@cryptotaxi247 / netdata-1 / commits / 99aa0a93e

added debug

Costa Tsaousis (ktsaou) committed Mar 19, 2015 at 10:53 UTC 99aa0a93e96c25b1294d2e640b7ed874661d4cdd
2 files changed +43 -29
src/procfile.c
+28 -28
@@ -26,14 +26,14 @@
26 #define PFWORDS_INCREASE_STEP 200
27
28 pfwords *pfwords_add(pfwords *fw, char *str) {
29 - debug(D_PROCFILE, PF_PREFIX ": adding word No %d: '%s'\n", fw->len, str);
29 + debug(D_PROCFILE, PF_PREFIX ": adding word No %d: '%s'", fw->len, str);
30
31 if(fw->len == fw->size) {
32 - debug(D_PROCFILE, PF_PREFIX ": expanding words\n");
32 + debug(D_PROCFILE, PF_PREFIX ": expanding words");
33
34 pfwords *new = realloc(fw, sizeof(pfwords) + (fw->size + PFWORDS_INCREASE_STEP) * sizeof(char *));
35 if(!new) {
36 - error(PF_PREFIX ": failed to expand words\n");
36 + error(PF_PREFIX ": failed to expand words");
37 free(fw);
38 return NULL;
39 }
@@ -47,7 +47,7 @@ pfwords *pfwords_add(pfwords *fw, char *str) {
47 }
48
49 pfwords *pfwords_new(void) {
50 - debug(D_PROCFILE, PF_PREFIX ": initializing words\n");
50 + debug(D_PROCFILE, PF_PREFIX ": initializing words");
51
52 pfwords *new = malloc(sizeof(pfwords) + PFWORDS_INCREASE_STEP * sizeof(char *));
53 if(!new) return NULL;
@@ -58,12 +58,12 @@ pfwords *pfwords_new(void) {
58 }
59
60 void pfwords_reset(pfwords *fw) {
61 - debug(D_PROCFILE, PF_PREFIX ": reseting words\n");
61 + debug(D_PROCFILE, PF_PREFIX ": reseting words");
62 fw->len = 0;
63 }
64
65 void pfwords_free(pfwords *fw) {
66 - debug(D_PROCFILE, PF_PREFIX ": freeing words\n");
66 + debug(D_PROCFILE, PF_PREFIX ": freeing words");
67
68 free(fw);
69 }
@@ -75,14 +75,14 @@ void pfwords_free(pfwords *fw) {
75 #define PFLINES_INCREASE_STEP 10
76
77 pflines *pflines_add(pflines *fl, uint32_t first_word) {
78 - debug(D_PROCFILE, PF_PREFIX ": adding line %d at word %d\n", fl->len, first_word);
78 + debug(D_PROCFILE, PF_PREFIX ": adding line %d at word %d", fl->len, first_word);
79
80 if(fl->len == fl->size) {
81 - debug(D_PROCFILE, PF_PREFIX ": expanding lines\n");
81 + debug(D_PROCFILE, PF_PREFIX ": expanding lines");
82
83 pflines *new = realloc(fl, sizeof(pflines) + (fl->size + PFLINES_INCREASE_STEP) * sizeof(ffline));
84 if(!new) {
85 - error(PF_PREFIX ": failed to expand lines\n");
85 + error(PF_PREFIX ": failed to expand lines");
86 free(fl);
87 return NULL;
88 }
@@ -97,7 +97,7 @@ pflines *pflines_add(pflines *fl, uint32_t first_word) {
97 }
98
99 pflines *pflines_new(void) {
100 - debug(D_PROCFILE, PF_PREFIX ": initializing lines\n");
100 + debug(D_PROCFILE, PF_PREFIX ": initializing lines");
101
102 pflines *new = malloc(sizeof(pflines) + PFLINES_INCREASE_STEP * sizeof(ffline));
103 if(!new) return NULL;
@@ -108,13 +108,13 @@ pflines *pflines_new(void) {
108 }
109
110 void pflines_reset(pflines *fl) {
111 - debug(D_PROCFILE, PF_PREFIX ": reseting lines\n");
111 + debug(D_PROCFILE, PF_PREFIX ": reseting lines");
112
113 fl->len = 0;
114 }
115
116 void pflines_free(pflines *fl) {
117 - debug(D_PROCFILE, PF_PREFIX ": freeing lines\n");
117 + debug(D_PROCFILE, PF_PREFIX ": freeing lines");
118
119 free(fl);
120 }
@@ -131,7 +131,7 @@ void pflines_free(pflines *fl) {
131 #define PF_CHAR_IS_WORD 2
132
133 void procfile_close(procfile *ff) {
134 - debug(D_PROCFILE, PF_PREFIX ": Closing file '%s'. Reason: %s\n", ff->filename, strerror(errno));
134 + debug(D_PROCFILE, PF_PREFIX ": Closing file '%s'. Reason: %s", ff->filename, strerror(errno));
135
136 if(ff->lines) pflines_free(ff->lines);
137 if(ff->words) pfwords_free(ff->words);
@@ -141,7 +141,7 @@ void procfile_close(procfile *ff) {
141 }
142
143 procfile *procfile_parser(procfile *ff) {
144 - debug(D_PROCFILE, PF_PREFIX ": Parsing file '%s'\n", ff->filename);
144 + debug(D_PROCFILE, PF_PREFIX ": Parsing file '%s'", ff->filename);
145
146 char *s = ff->data, *e = ff->data, *t = ff->data;
147 uint32_t l = 0, w = 0;
@@ -181,7 +181,7 @@ procfile *procfile_parser(procfile *ff) {
181 ff->lines->lines[l].words++;
182 w++;
183
184 - debug(D_PROCFILE, PF_PREFIX ": ended line %d with %d words\n", l, ff->lines->lines[l].words);
184 + debug(D_PROCFILE, PF_PREFIX ": ended line %d with %d words", l, ff->lines->lines[l].words);
185
186 ff->lines = pflines_add(ff->lines, w);
187 if(!ff->lines) goto cleanup;
@@ -214,24 +214,24 @@ procfile *procfile_parser(procfile *ff) {
214 return ff;
215
216 cleanup:
217 - error(PF_PREFIX ": Failed to parse file '%s'. Reason: %s\n", ff->filename, strerror(errno));
217 + error(PF_PREFIX ": Failed to parse file '%s'. Reason: %s", ff->filename, strerror(errno));
218 procfile_close(ff);
219 return NULL;
220 }
221
222 procfile *procfile_readall(procfile *ff) {
223 - debug(D_PROCFILE, PF_PREFIX ": Reading file '%s'.\n", ff->filename);
223 + debug(D_PROCFILE, PF_PREFIX ": Reading file '%s'.", ff->filename);
224
225 ssize_t s = 0, r = ff->size, x = ff->size;
226 ff->len = 0;
227
228 while(r == x) {
229 if(s) {
230 - debug(D_PROCFILE, PF_PREFIX ": Expanding data buffer for file '%s'.\n", ff->filename);
230 + debug(D_PROCFILE, PF_PREFIX ": Expanding data buffer for file '%s'.", ff->filename);
231
232 procfile *new = realloc(ff, sizeof(procfile) + ff->size + PROCFILE_INCREMENT_BUFFER);
233 if(!new) {
234 - error(PF_PREFIX ": Cannot allocate memory for file '%s'. Reason: %s\n", ff->filename, strerror(errno));
234 + error(PF_PREFIX ": Cannot allocate memory for file '%s'. Reason: %s", ff->filename, strerror(errno));
235 procfile_close(ff);
236 return NULL;
237 }
@@ -243,7 +243,7 @@ procfile *procfile_readall(procfile *ff) {
243 debug(D_PROCFILE, "Reading file '%s', from position %ld with length %ld", ff->filename, s, ff->size - s);
244 r = read(ff->fd, &ff->data[s], ff->size - s);
245 if(r == -1) {
246 - error(PF_PREFIX ": Cannot read from file '%s'. Reason: %s\n", ff->filename, strerror(errno));
246 + error(PF_PREFIX ": Cannot read from file '%s'. Reason: %s", ff->filename, strerror(errno));
247 procfile_close(ff);
248 return NULL;
249 }
@@ -254,7 +254,7 @@ procfile *procfile_readall(procfile *ff) {
254
255 debug(D_PROCFILE, "Rewinding file '%s'", ff->filename);
256 if(lseek(ff->fd, 0, SEEK_SET) == -1) {
257 - error(PF_PREFIX ": Cannot rewind on file '%s'.\n", ff->filename);
257 + error(PF_PREFIX ": Cannot rewind on file '%s'.", ff->filename);
258 procfile_close(ff);
259 return NULL;
260 }
@@ -269,17 +269,17 @@ procfile *procfile_readall(procfile *ff) {
269 }
270
271 procfile *procfile_open(const char *filename, const char *separators) {
272 - debug(D_PROCFILE, PF_PREFIX ": Opening file '%s'\n", filename);
272 + debug(D_PROCFILE, PF_PREFIX ": Opening file '%s'", filename);
273
274 int fd = open(filename, O_RDONLY, 0666);
275 if(fd == -1) {
276 - error(PF_PREFIX ": Cannot open file '%s'. Reason: %s\n", filename, strerror(errno));
276 + error(PF_PREFIX ": Cannot open file '%s'. Reason: %s", filename, strerror(errno));
277 return NULL;
278 }
279
280 procfile *ff = malloc(sizeof(procfile) + PROCFILE_INITIAL_BUFFER);
281 if(!ff) {
282 - error(PF_PREFIX ": Cannot allocate memory for file '%s'. Reason: %s\n", ff->filename, strerror(errno));
282 + error(PF_PREFIX ": Cannot allocate memory for file '%s'. Reason: %s", ff->filename, strerror(errno));
283 close(fd);
284 return NULL;
285 }
@@ -295,7 +295,7 @@ procfile *procfile_open(const char *filename, const char *separators) {
295 ff->words = pfwords_new();
296
297 if(!ff->lines || !ff->words) {
298 - error(PF_PREFIX ": Cannot initialize parser for file '%s'. Reason: %s\n", ff->filename, strerror(errno));
298 + error(PF_PREFIX ": Cannot initialize parser for file '%s'. Reason: %s", ff->filename, strerror(errno));
299 procfile_close(ff);
300 return NULL;
301 }
@@ -324,16 +324,16 @@ void procfile_print(procfile *ff) {
324 uint32_t words, w;
325 char *s;
326
327 - debug(D_PROCFILE, "File '%s' with %d lines and %d words\n", ff->filename, ff->lines->len, ff->words->len);
327 + debug(D_PROCFILE, "File '%s' with %d lines and %d words", ff->filename, ff->lines->len, ff->words->len);
328
329 for(l = 0; l < lines ;l++) {
330 words = procfile_linewords(ff, l);
331
332 - debug(D_PROCFILE, " line %d starts at word %d and has %d words\n", l, ff->lines->lines[l].first, ff->lines->lines[l].words);
332 + debug(D_PROCFILE, " line %d starts at word %d and has %d words", l, ff->lines->lines[l].first, ff->lines->lines[l].words);
333
334 for(w = 0; w < words ;w++) {
335 s = procfile_lineword(ff, l, w);
336 - debug(D_PROCFILE, " [%d.%d] '%s'\n", l, w, s);
336 + debug(D_PROCFILE, " [%d.%d] '%s'", l, w, s);
337 }
338 }
339 }
src/rrd.c
+15 -1
@@ -504,6 +504,8 @@ void rrd_stats_save_all(void)
504
505 RRD_STATS *rrd_stats_find(const char *id)
506 {
507 + debug(D_RRD_STATS, "rrd_stats_find() for chart %s", id);
508 +
509 unsigned long hash = simple_hash(id);
510
511 pthread_rwlock_rdlock(&root_rwlock);
@@ -519,6 +521,8 @@ RRD_STATS *rrd_stats_find(const char *id)
521
522 RRD_STATS *rrd_stats_find_bytype(const char *type, const char *id)
523 {
524 + debug(D_RRD_STATS, "rrd_stats_find_bytype() for chart %s.%s", type, id);
525 +
526 char buf[RRD_STATS_NAME_MAX + 1];
527
528 strncpy(buf, type, RRD_STATS_NAME_MAX - 1);
@@ -533,6 +537,8 @@ RRD_STATS *rrd_stats_find_bytype(const char *type, const char *id)
537
538 RRD_STATS *rrd_stats_find_byname(const char *name)
539 {
540 + debug(D_RRD_STATS, "rrd_stats_find_byname() for chart %s", name);
541 +
542 char b[CONFIG_MAX_VALUE + 1];
543
544 rrd_stats_strncpy_name(b, name, CONFIG_MAX_VALUE);
@@ -550,6 +556,8 @@ RRD_STATS *rrd_stats_find_byname(const char *name)
556
557 RRD_DIMENSION *rrd_stats_dimension_find(RRD_STATS *st, const char *id)
558 {
559 + debug(D_RRD_STATS, "rrd_stats_dimension_find() for chart %s, dimension %s", st->name, id);
560 +
561 unsigned long hash = simple_hash(id);
562
563 RRD_DIMENSION *rd = st->dimensions;
@@ -564,6 +572,8 @@ RRD_DIMENSION *rrd_stats_dimension_find(RRD_STATS *st, const char *id)
572
573 int rrd_stats_dimension_hide(RRD_STATS *st, const char *id)
574 {
575 + debug(D_RRD_STATS, "rrd_stats_dimension_hide() for chart %s, dimension %s", st->name, id);
576 +
577 RRD_DIMENSION *rd = rrd_stats_dimension_find(st, id);
578 if(!rd) {
579 error("Cannot find dimension with id '%s' on stats '%s' (%s).", id, st->name, st->id);
@@ -576,7 +586,7 @@ int rrd_stats_dimension_hide(RRD_STATS *st, const char *id)
586
587 void rrd_stats_dimension_set_by_pointer(RRD_STATS *st, RRD_DIMENSION *rd, collected_number value)
588 {
579 - if(st) {;}
589 + debug(D_RRD_STATS, "rrd_stats_dimension_set() for chart %s, dimension %s, value " COLLECTED_NUMBER_FORMAT, st->name, rd->name, value);
590
591 gettimeofday(&rd->last_collected_time, NULL);
592 rd->collected_value = value;
@@ -596,6 +606,8 @@ int rrd_stats_dimension_set(RRD_STATS *st, const char *id, collected_number valu
606
607 void rrd_stats_next_usec(RRD_STATS *st, unsigned long long microseconds)
608 {
609 + debug(D_RRD_STATS, "rrd_stats_next() for chart %s with microseconds %llu", st->name, microseconds);
610 +
611 if(st->debug) debug(D_RRD_STATS, "%s: NEXT: %llu microseconds", st->name, microseconds);
612 if(microseconds > st->entries * st->update_every * 1000000ULL) {
613 info("History of chart %s too old. Reseting chart.", st->name);
@@ -625,6 +637,8 @@ void rrd_stats_next_plugins(RRD_STATS *st)
637
638 unsigned long long rrd_stats_done(RRD_STATS *st)
639 {
640 + debug(D_RRD_STATS, "rrd_stats_done() for chart %s", st->name);
641 +
642 RRD_DIMENSION *rd, *last;
643 int oldstate;
644