diff options
author | Xavier Roche <xroche@users.noreply.github.com> | 2014-05-10 19:08:05 +0000 |
---|---|---|
committer | Xavier Roche <xroche@users.noreply.github.com> | 2014-05-10 19:08:05 +0000 |
commit | 917d6bd3c44476d032f40b61b6e49ce2ea76494e (patch) | |
tree | 419ba75e9d21462bed0324ad877a068f38de96bf | |
parent | a085b2b2fa78158c9c60debb9c2f8d813ea528ae (diff) |
Better logging for hashtables
-rw-r--r-- | src/htsback.c | 4 | ||||
-rw-r--r-- | src/htsback.h | 2 | ||||
-rw-r--r-- | src/htscore.c | 8 | ||||
-rw-r--r-- | src/htshash.c | 12 | ||||
-rw-r--r-- | src/htshash.h | 2 | ||||
-rw-r--r-- | src/htslib.c | 61 | ||||
-rw-r--r-- | src/htslib.h | 3 | ||||
-rw-r--r-- | src/htsserver.c | 3 | ||||
-rw-r--r-- | src/htstools.c | 1 | ||||
-rw-r--r-- | src/httrack-library.h | 2 | ||||
-rw-r--r-- | src/proxy/store.c | 6 |
11 files changed, 92 insertions, 12 deletions
diff --git a/src/htsback.c b/src/htsback.c index 2f6df7b..d5d7c10 100644 --- a/src/htsback.c +++ b/src/htsback.c @@ -67,13 +67,15 @@ static int slot_can_be_cached_on_disk(const lien_back * back); static int slot_can_be_cleaned(const lien_back * back); static int slot_can_be_finalized(httrackp * opt, const lien_back * back); -struct_back *back_new(int back_max) { +struct_back *back_new(httrackp *opt, int back_max) { int i; struct_back *sback = calloct(1, sizeof(struct_back)); sback->count = back_max; sback->lnk = (lien_back *) calloct((back_max + 1), sizeof(lien_back)); sback->ready = inthash_new(0); + hts_set_hash_handler(sback->ready, opt); + inthash_set_name(sback->ready, "back_new"); sback->ready_size_bytes = 0; inthash_value_is_malloc(sback->ready, 1); // init diff --git a/src/htsback.h b/src/htsback.h index 2203dd5..1da5450 100644 --- a/src/htsback.h +++ b/src/htsback.h @@ -68,7 +68,7 @@ typedef struct htsblk htsblk; #ifdef HTS_INTERNAL_BYTECODE // create/destroy -struct_back *back_new(int back_max); +struct_back *back_new(httrackp *opt, int back_max); void back_free(struct_back ** sback); // backing diff --git a/src/htscore.c b/src/htscore.c index bd2580b..94ed251 100644 --- a/src/htscore.c +++ b/src/htscore.c @@ -401,6 +401,10 @@ int httpmirror(char *url1, httrackp * opt) { XH_extuninit; return 0; } + hts_set_hash_handler(cache_hashtable, opt); + hts_set_hash_handler(cache_tests, opt); + inthash_set_name(cache_hashtable, "cache_hashtable"); + inthash_set_name(cache_tests, "cache_tests"); inthash_value_is_malloc(cache_tests, 1); /* malloc */ cache.hashtable = (void *) cache_hashtable; /* copy backcache hash */ cache.cached_tests = (void *) cache_tests; /* copy of cache_tests */ @@ -445,7 +449,7 @@ int httpmirror(char *url1, httrackp * opt) { lien_tot = 0; // initialiser hachage - hash_init(&hash, opt->urlhack); + hash_init(opt, &hash, opt->urlhack); // note: we need a cast because of the const hash.liens = (const lien_url **) liens; @@ -683,7 +687,7 @@ int httpmirror(char *url1, httrackp * opt) { // On prévoit large: les fichiers HTML ne prennent que peu de place en mémoire, et les // fichiers non html sont sauvés en direct sur disque. // --> 1024 entrées + 32 entrées par socket en supplément - sback = back_new(opt->maxsoc * 32 + 1024); + sback = back_new(opt, opt->maxsoc * 32 + 1024); if (sback == NULL) { hts_log_print(opt, LOG_PANIC, "Not enough memory, can not allocate %d bytes", diff --git a/src/htshash.c b/src/htshash.c index 15af190..7bdf782 100644 --- a/src/htshash.c +++ b/src/htshash.c @@ -34,11 +34,11 @@ Please visit our Website: http://www.httrack.com /* Internal engine bytecode */ #define HTS_INTERNAL_BYTECODE +#include "htsopt.h" #include "htshash.h" /* specific definitions */ #include "htsbase.h" -#include "htsopt.h" #include "htsglobal.h" #include "htsmd5.h" #include "htscore.h" @@ -171,12 +171,20 @@ static int key_former_adrfil_equals(void *arg, const char *a, const char *b) { return key_adrfil_equals_generic(arg, a, b, 1); } -void hash_init(hash_struct * hash, int normalized) { +void hash_init(httrackp *opt, hash_struct * hash, int normalized) { hash->sav = inthash_new(0); hash->adrfil = inthash_new(0); hash->former_adrfil = inthash_new(0); hash->normalized = normalized; + hts_set_hash_handler(hash->sav, opt); + hts_set_hash_handler(hash->adrfil, opt); + hts_set_hash_handler(hash->former_adrfil, opt); + + inthash_set_name(hash->sav, "hash->sav"); + inthash_set_name(hash->adrfil, "hash->adrfil"); + inthash_set_name(hash->former_adrfil, "hash->former_adrfil"); + /* Case-insensitive comparison ; keys are direct char* filenames */ inthash_value_set_key_handler(hash->sav, key_duphandler, diff --git a/src/htshash.h b/src/htshash.h index f8150c6..4810513 100644 --- a/src/htshash.h +++ b/src/htshash.h @@ -51,7 +51,7 @@ typedef enum hash_struct_type { } hash_struct_type; // tables de hachage -void hash_init(hash_struct *hash, int normalized); +void hash_init(httrackp *opt, hash_struct *hash, int normalized); void hash_free(hash_struct *hash); int hash_read(const hash_struct * hash, const char *nom1, const char *nom2, hash_struct_type type); diff --git a/src/htslib.c b/src/htslib.c index 9248cf9..d1936cc 100644 --- a/src/htslib.c +++ b/src/htslib.c @@ -5116,8 +5116,33 @@ static void default_inthash_asserthandler(void *arg, const char* exp, const char abortf_(exp, file, line); } +static int get_loglevel_from_inthash(inthash_loglevel level) { + switch(level) { + case inthash_log_critical: + return LOG_PANIC; + break; + case inthash_log_warning: + return LOG_WARNING; + break; + case inthash_log_info: + return LOG_INFO; + break; + case inthash_log_debug: + return LOG_DEBUG; + break; + case inthash_log_trace: + return LOG_TRACE; + break; + default: + return LOG_ERROR; + break; + } +} + +/* log to default console */ static void default_inthash_loghandler(void *arg, inthash_loglevel level, const char* format, va_list args) { + if (level <= inthash_log_warning) { fprintf(stderr, "** warning: "); } @@ -5125,6 +5150,27 @@ static void default_inthash_loghandler(void *arg, inthash_loglevel level, fprintf(stderr, "\n"); } +/* log to project log */ +static void htsopt_inthash_loghandler(void *arg, inthash_loglevel level, + const char* format, va_list args) { + httrackp *const opt = (httrackp*) arg; + if (opt != NULL && opt->log != NULL) { + hts_log_vprint(opt, get_loglevel_from_inthash(level), + format, args); + } else { + default_inthash_loghandler(NULL, level, format, args); + } +} + +/* attach hashtable logger to project log */ +void hts_set_hash_handler(inthash hashtable, httrackp *opt) { + /* Init hashtable default assertion handler. */ + inthash_set_assert_handler(hashtable, + htsopt_inthash_loghandler, + default_inthash_asserthandler, + opt); +} + static int hts_init_ok = 0; HTSEXT_API int hts_init(void) { const char *dbg_env; @@ -5232,10 +5278,9 @@ HTSEXT_API int hts_log(httrackp * opt, const char *prefix, const char *msg) { return 1; /* Error */ } -HTSEXT_API void hts_log_print(httrackp * opt, int type, const char *format, ...) { +HTSEXT_API void hts_log_vprint(httrackp * opt, int type, const char *format, va_list args) { assertf(format != NULL); if (opt != NULL && opt->log != NULL) { - va_list args; const int save_errno = errno; const char *s_type = "unknown"; const int level = type & 0xff; @@ -5267,9 +5312,7 @@ HTSEXT_API void hts_log_print(httrackp * opt, int type, const char *format, ...) break; } fspc(opt, opt->log, s_type); - va_start(args, format); (void) vfprintf(opt->log, format, args); - va_end(args); if ((type & LOG_ERRNO) != 0) { fprintf(opt->log, ": %s", strerror(save_errno)); } @@ -5281,6 +5324,16 @@ HTSEXT_API void hts_log_print(httrackp * opt, int type, const char *format, ...) } } +HTSEXT_API void hts_log_print(httrackp * opt, int type, const char *format, ...) { + assertf(format != NULL); + if (opt != NULL && opt->log != NULL) { + va_list args; + va_start(args, format); + hts_log_vprint(opt, type, format, args); + va_end(args); + } +} + HTSEXT_API void set_wrappers(httrackp * opt) { // LEGACY } diff --git a/src/htslib.h b/src/htslib.h index 8a6c206..2b75dc4 100644 --- a/src/htslib.h +++ b/src/htslib.h @@ -234,6 +234,9 @@ struct t_dnscache { // initialize an htsblk structure void hts_init_htsblk(htsblk * r); +// attach specific project log to hachtable logger +void hts_set_hash_handler(inthash hashtable, httrackp *opt); + // version HTSEXT_API const char* hts_version(void); diff --git a/src/htsserver.c b/src/htsserver.c index 1388110..65329f3 100644 --- a/src/htsserver.c +++ b/src/htsserver.c @@ -1443,6 +1443,7 @@ int smallserver(T_SOC soc, char *url, char *method, char *data, char *path) { int htslang_init(void) { if (NewLangList == NULL) { NewLangList = inthash_new(0); + inthash_set_name(NewLangList, "NewLangList"); if (NewLangList == NULL) { abortLog("Error in lang.h: not enough memory"); } else { @@ -1487,6 +1488,8 @@ static int htslang_load(char *limit_to, char *path) { LANG_DELETE(); NewLangStr = inthash_new(0); NewLangStrKeys = inthash_new(0); + inthash_set_name(NewLangStr, "NewLangStr"); + inthash_set_name(NewLangStrKeys, "NewLangStrKeys"); if ((NewLangStr == NULL) || (NewLangStrKeys == NULL)) { abortLog("Error in lang.h: not enough memory"); } else { diff --git a/src/htstools.c b/src/htstools.c index 78fb827..de81d57 100644 --- a/src/htstools.c +++ b/src/htstools.c @@ -980,6 +980,7 @@ HTSEXT_API char *hts_getcategories(char *path, int type) { if (type == 1) { hashCateg = inthash_new(0); + inthash_set_name(hashCateg, "hashCateg"); StringCat(categ, "Test category 1"); StringCat(categ, "\r\nTest category 2"); } diff --git a/src/httrack-library.h b/src/httrack-library.h index 21ff79c..8c63fb4 100644 --- a/src/httrack-library.h +++ b/src/httrack-library.h @@ -116,6 +116,8 @@ HTSEXT_API int plug_wrapper(httrackp * opt, const char *moduleName, HTSEXT_API int hts_log(httrackp * opt, const char *prefix, const char *msg); HTSEXT_API void hts_log_print(httrackp * opt, int type, const char *format, ...) HTS_PRINTF_FUN(3, 4); +HTSEXT_API void hts_log_vprint(httrackp * opt, int type, const char *format, + va_list args); /* Infos */ HTSEXT_API const char *hts_get_version_info(httrackp * opt); diff --git a/src/proxy/store.c b/src/proxy/store.c index 9d756b7..daa9952 100644 --- a/src/proxy/store.c +++ b/src/proxy/store.c @@ -238,6 +238,7 @@ PT_Indexes PT_New(void) { PT_Indexes index = (PT_Indexes) calloc(sizeof(_PT_Indexes), 1); index->cil = inthash_new(0); + inthash_set_name(index->cil, "index->cil"); index->index_size = 0; index->index = NULL; return index; @@ -432,8 +433,10 @@ char **PT_Enumerate(PT_Indexes indexes, const char *url, int subtree) { inthash_chain *chain; inthash hdupes = NULL; - if (!subtree) + if (!subtree) { hdupes = inthash_new(0); + inthash_set_name(hdupes, "hdupes"); + } StringClear(list); StringClear(listindexes); StringClear(subitem); @@ -551,6 +554,7 @@ PT_Index PT_LoadCache(const char *filename) { index->slots.common.timestamp = (time_t) time(NULL); index->slots.common.startUrl[0] = '\0'; index->slots.common.hash = inthash_new(0); + inthash_set_name(index->slots.common.hash, "index->slots.common.hash"); if (!_IndexFuncts[type].PT_LoadCache(index, filename)) { proxytrack_print_log(DEBUG, "reading httrack cache (format #%d) %s : error", |