diff options
Diffstat (limited to 'libnetdata/procfile')
-rw-r--r-- | libnetdata/procfile/procfile.c | 61 |
1 files changed, 32 insertions, 29 deletions
diff --git a/libnetdata/procfile/procfile.c b/libnetdata/procfile/procfile.c index cdf0f972..1a7e47a5 100644 --- a/libnetdata/procfile/procfile.c +++ b/libnetdata/procfile/procfile.c @@ -48,11 +48,11 @@ char *procfile_filename(procfile *ff) { // An array of words static inline void procfile_words_add(procfile *ff, char *str) { - // debug(D_PROCFILE, PF_PREFIX ": adding word No %d: '%s'", fw->len, str); + // netdata_log_debug(D_PROCFILE, PF_PREFIX ": adding word No %d: '%s'", fw->len, str); pfwords *fw = ff->words; if(unlikely(fw->len == fw->size)) { - // debug(D_PROCFILE, PF_PREFIX ": expanding words"); + // netdata_log_debug(D_PROCFILE, PF_PREFIX ": expanding words"); size_t minimum = PFWORDS_INCREASE_STEP; size_t optimal = fw->size / 2; size_t wanted = (optimal > minimum)?optimal:minimum; @@ -66,7 +66,7 @@ static inline void procfile_words_add(procfile *ff, char *str) { NEVERNULL static inline pfwords *procfile_words_create(void) { - // debug(D_PROCFILE, PF_PREFIX ": initializing words"); + // netdata_log_debug(D_PROCFILE, PF_PREFIX ": initializing words"); size_t size = (procfile_adaptive_initial_allocation) ? procfile_max_words : PFWORDS_INCREASE_STEP; @@ -77,12 +77,12 @@ static inline pfwords *procfile_words_create(void) { } static inline void procfile_words_reset(pfwords *fw) { - // debug(D_PROCFILE, PF_PREFIX ": resetting words"); + // netdata_log_debug(D_PROCFILE, PF_PREFIX ": resetting words"); fw->len = 0; } static inline void procfile_words_free(pfwords *fw) { - // debug(D_PROCFILE, PF_PREFIX ": freeing words"); + // netdata_log_debug(D_PROCFILE, PF_PREFIX ": freeing words"); freez(fw); } @@ -93,11 +93,11 @@ static inline void procfile_words_free(pfwords *fw) { NEVERNULL static inline size_t *procfile_lines_add(procfile *ff) { - // debug(D_PROCFILE, PF_PREFIX ": adding line %d at word %d", fl->len, first_word); + // netdata_log_debug(D_PROCFILE, PF_PREFIX ": adding line %d at word %d", fl->len, first_word); pflines *fl = ff->lines; if(unlikely(fl->len == fl->size)) { - // debug(D_PROCFILE, PF_PREFIX ": expanding lines"); + // netdata_log_debug(D_PROCFILE, PF_PREFIX ": expanding lines"); size_t minimum = PFLINES_INCREASE_STEP; size_t optimal = fl->size / 2; size_t wanted = (optimal > minimum)?optimal:minimum; @@ -115,7 +115,7 @@ static inline size_t *procfile_lines_add(procfile *ff) { NEVERNULL static inline pflines *procfile_lines_create(void) { - // debug(D_PROCFILE, PF_PREFIX ": initializing lines"); + // netdata_log_debug(D_PROCFILE, PF_PREFIX ": initializing lines"); size_t size = (unlikely(procfile_adaptive_initial_allocation)) ? procfile_max_words : PFLINES_INCREASE_STEP; @@ -126,13 +126,13 @@ static inline pflines *procfile_lines_create(void) { } static inline void procfile_lines_reset(pflines *fl) { - // debug(D_PROCFILE, PF_PREFIX ": resetting lines"); + // netdata_log_debug(D_PROCFILE, PF_PREFIX ": resetting lines"); fl->len = 0; } static inline void procfile_lines_free(pflines *fl) { - // debug(D_PROCFILE, PF_PREFIX ": freeing lines"); + // netdata_log_debug(D_PROCFILE, PF_PREFIX ": freeing lines"); freez(fl); } @@ -144,7 +144,7 @@ static inline void procfile_lines_free(pflines *fl) { void procfile_close(procfile *ff) { if(unlikely(!ff)) return; - debug(D_PROCFILE, PF_PREFIX ": Closing file '%s'", procfile_filename(ff)); + netdata_log_debug(D_PROCFILE, PF_PREFIX ": Closing file '%s'", procfile_filename(ff)); freez(ff->filename); procfile_lines_free(ff->lines); @@ -156,7 +156,7 @@ void procfile_close(procfile *ff) { NOINLINE static void procfile_parser(procfile *ff) { - // debug(D_PROCFILE, PF_PREFIX ": Parsing file '%s'", ff->filename); + // netdata_log_debug(D_PROCFILE, PF_PREFIX ": Parsing file '%s'", ff->filename); char *s = ff->data // our current position , *e = &ff->data[ff->len] // the terminating null @@ -206,7 +206,7 @@ static void procfile_parser(procfile *ff) { (*line_words)++; t = ++s; - // debug(D_PROCFILE, PF_PREFIX ": ended line %d with %d words", l, ff->lines->lines[l].words); + // netdata_log_debug(D_PROCFILE, PF_PREFIX ": ended line %d with %d words", l, ff->lines->lines[l].words); line_words = procfile_lines_add(ff); } @@ -275,7 +275,7 @@ static void procfile_parser(procfile *ff) { } procfile *procfile_readall(procfile *ff) { - // debug(D_PROCFILE, PF_PREFIX ": Reading file '%s'.", ff->filename); + // netdata_log_debug(D_PROCFILE, PF_PREFIX ": Reading file '%s'.", ff->filename); ff->len = 0; // zero the used size ssize_t r = 1; // read at least once @@ -288,16 +288,17 @@ procfile *procfile_readall(procfile *ff) { size_t optimal = ff->size / 2; size_t wanted = (optimal > minimum)?optimal:minimum; - debug(D_PROCFILE, PF_PREFIX ": Expanding data buffer for file '%s' by %zu bytes.", procfile_filename(ff), wanted); + netdata_log_debug(D_PROCFILE, PF_PREFIX ": Expanding data buffer for file '%s' by %zu bytes.", procfile_filename(ff), wanted); ff = reallocz(ff, sizeof(procfile) + ff->size + wanted); ff->size += wanted; } - debug(D_PROCFILE, "Reading file '%s', from position %zd with length %zd", procfile_filename(ff), s, (ssize_t)(ff->size - s)); + netdata_log_debug(D_PROCFILE, "Reading file '%s', from position %zd with length %zd", procfile_filename(ff), s, (ssize_t)(ff->size - s)); r = read(ff->fd, &ff->data[s], ff->size - s); if(unlikely(r == -1)) { if(unlikely(!(ff->flags & PROCFILE_FLAG_NO_ERROR_ON_FILE_IO))) collector_error(PF_PREFIX ": Cannot read from file '%s' on fd %d", procfile_filename(ff), ff->fd); - else if(unlikely(ff->flags & PROCFILE_FLAG_ERROR_ON_ERROR_LOG)) error(PF_PREFIX ": Cannot read from file '%s' on fd %d", procfile_filename(ff), ff->fd); + else if(unlikely(ff->flags & PROCFILE_FLAG_ERROR_ON_ERROR_LOG)) + netdata_log_error(PF_PREFIX ": Cannot read from file '%s' on fd %d", procfile_filename(ff), ff->fd); procfile_close(ff); return NULL; } @@ -305,10 +306,11 @@ procfile *procfile_readall(procfile *ff) { ff->len += r; } - // debug(D_PROCFILE, "Rewinding file '%s'", ff->filename); + // netdata_log_debug(D_PROCFILE, "Rewinding file '%s'", ff->filename); if(unlikely(lseek(ff->fd, 0, SEEK_SET) == -1)) { if(unlikely(!(ff->flags & PROCFILE_FLAG_NO_ERROR_ON_FILE_IO))) collector_error(PF_PREFIX ": Cannot rewind on file '%s'.", procfile_filename(ff)); - else if(unlikely(ff->flags & PROCFILE_FLAG_ERROR_ON_ERROR_LOG)) error(PF_PREFIX ": Cannot rewind on file '%s'.", procfile_filename(ff)); + else if(unlikely(ff->flags & PROCFILE_FLAG_ERROR_ON_ERROR_LOG)) + netdata_log_error(PF_PREFIX ": Cannot rewind on file '%s'.", procfile_filename(ff)); procfile_close(ff); return NULL; } @@ -323,7 +325,7 @@ procfile *procfile_readall(procfile *ff) { if(unlikely(ff->words->len > procfile_max_words)) procfile_max_words = ff->words->len; } - // debug(D_PROCFILE, "File '%s' updated.", ff->filename); + // netdata_log_debug(D_PROCFILE, "File '%s' updated.", ff->filename); return ff; } @@ -401,16 +403,17 @@ void procfile_set_open_close(procfile *ff, const char *open, const char *close) } procfile *procfile_open(const char *filename, const char *separators, uint32_t flags) { - debug(D_PROCFILE, PF_PREFIX ": Opening file '%s'", filename); + netdata_log_debug(D_PROCFILE, PF_PREFIX ": Opening file '%s'", filename); int fd = open(filename, procfile_open_flags, 0666); if(unlikely(fd == -1)) { if(unlikely(!(flags & PROCFILE_FLAG_NO_ERROR_ON_FILE_IO))) collector_error(PF_PREFIX ": Cannot open file '%s'", filename); - else if(unlikely(flags & PROCFILE_FLAG_ERROR_ON_ERROR_LOG)) error(PF_PREFIX ": Cannot open file '%s'", filename); + else if(unlikely(flags & PROCFILE_FLAG_ERROR_ON_ERROR_LOG)) + netdata_log_error(PF_PREFIX ": Cannot open file '%s'", filename); return NULL; } - // info("PROCFILE: opened '%s' on fd %d", filename, fd); + // netdata_log_info("PROCFILE: opened '%s' on fd %d", filename, fd); size_t size = (unlikely(procfile_adaptive_initial_allocation)) ? procfile_max_allocation : PROCFILE_INCREMENT_BUFFER; procfile *ff = mallocz(sizeof(procfile) + size); @@ -427,7 +430,7 @@ procfile *procfile_open(const char *filename, const char *separators, uint32_t f procfile_set_separators(ff, separators); - debug(D_PROCFILE, "File '%s' opened.", filename); + netdata_log_debug(D_PROCFILE, "File '%s' opened.", filename); return ff; } @@ -435,7 +438,7 @@ procfile *procfile_reopen(procfile *ff, const char *filename, const char *separa if(unlikely(!ff)) return procfile_open(filename, separators, flags); if(likely(ff->fd != -1)) { - // info("PROCFILE: closing fd %d", ff->fd); + // netdata_log_info("PROCFILE: closing fd %d", ff->fd); close(ff->fd); } @@ -445,7 +448,7 @@ procfile *procfile_reopen(procfile *ff, const char *filename, const char *separa return NULL; } - // info("PROCFILE: opened '%s' on fd %d", filename, ff->fd); + // netdata_log_info("PROCFILE: opened '%s' on fd %d", filename, ff->fd); //strncpyz(ff->filename, filename, FILENAME_MAX); freez(ff->filename); @@ -466,17 +469,17 @@ void procfile_print(procfile *ff) { char *s; (void)s; - debug(D_PROCFILE, "File '%s' with %zu lines and %zu words", procfile_filename(ff), ff->lines->len, ff->words->len); + netdata_log_debug(D_PROCFILE, "File '%s' with %zu lines and %zu words", procfile_filename(ff), ff->lines->len, ff->words->len); for(l = 0; likely(l < lines) ;l++) { size_t words = procfile_linewords(ff, l); - debug(D_PROCFILE, " line %zu starts at word %zu and has %zu words", l, ff->lines->lines[l].first, ff->lines->lines[l].words); + netdata_log_debug(D_PROCFILE, " line %zu starts at word %zu and has %zu words", l, ff->lines->lines[l].first, ff->lines->lines[l].words); size_t w; for(w = 0; likely(w < words) ;w++) { s = procfile_lineword(ff, l, w); - debug(D_PROCFILE, " [%zu.%zu] '%s'", l, w, s); + netdata_log_debug(D_PROCFILE, " [%zu.%zu] '%s'", l, w, s); } } } |