@cryptotaxi247 / netdata-1 / commits / 39d3f1674

tracing: internal debugging checks are now enabled only when NETDATA_INTERNAL_CHECKS is set

Costa Tsaousis (ktsaou) committed Apr 7, 2016 at 12:50 UTC 39d3f16744cd354b4bd680fd48d5ffd7a51b6312
1 file changed +31 -11
src/apps_plugin.c
+31 -11
@@ -199,7 +199,7 @@ char *strdup_debug(const char *file, int line, const char *function, const char
199 #endif
200 #define strdup(ptr) strdup_debug(__FILE__, __LINE__, __FUNCTION__, (ptr))
201
202 -#endif /* ifdef NETDATA_INTERNAL_CHECKS */
202 +#endif /* NETDATA_INTERNAL_CHECKS */
203
204
205 // ----------------------------------------------------------------------------
@@ -268,10 +268,10 @@ unsigned long long get_hertz(void)
268
269 #ifdef HZ
270 myhz = HZ; /* <asm/param.h> */
271 -#else
271 +#else /* HZ */
272 /* If 32-bit or big-endian (not Alpha or ia64), assume HZ is 100. */
273 hz = (sizeof(long)==sizeof(int) || htons(999)==999) ? 100UL : 1024UL;
274 -#endif
274 +#endif /* HZ */
275
276 error("Unknown HZ value. Assuming %llu.", myhz);
277 return myhz;
@@ -574,7 +574,7 @@ struct pid_stat {
574 unsigned long long diff_cstime;
575 unsigned long long diff_cminflt;
576 unsigned long long diff_cmajflt;
577 -#endif
577 +#endif /* INCLUDE_CHILDS */
578
579 int *fds; // array of fds it uses
580 int fds_size; // the size of the fds array
@@ -822,7 +822,7 @@ int walk_down(pid_t pid, int level) {
822
823 return ret;
824 }
825 -#endif
825 +#endif /* INCLUDE_CHILDS */
826
827
828 // ----------------------------------------------------------------------------
@@ -834,7 +834,9 @@ int walk_down(pid_t pid, int level) {
834
835 struct file_descriptor {
836 avl avl;
837 +#ifdef NETDATA_INTERNAL_CHECKS
838 uint32_t magic;
839 +#endif /* NETDATA_INTERNAL_CHECKS */
840 uint32_t hash;
841 const char *name;
842 int type;
@@ -846,15 +848,21 @@ int all_files_len = 0;
848 int all_files_size = 0;
849
850 int file_descriptor_compare(void* a, void* b) {
851 +#ifdef NETDATA_INTERNAL_CHECKS
852 if(((struct file_descriptor *)a)->magic != 0x0BADCAFE || ((struct file_descriptor *)b)->magic != 0x0BADCAFE)
853 error("Corrupted index data detected. Please report this.");
854 +#endif /* NETDATA_INTERNAL_CHECKS */
855
856 if(((struct file_descriptor *)a)->hash < ((struct file_descriptor *)b)->hash)
857 return -1;
858 +
859 else if(((struct file_descriptor *)a)->hash > ((struct file_descriptor *)b)->hash)
860 return 1;
856 - else return strcmp(((struct file_descriptor *)a)->name, ((struct file_descriptor *)b)->name);
861 +
862 + else
863 + return strcmp(((struct file_descriptor *)a)->name, ((struct file_descriptor *)b)->name);
864 }
865 +
866 int file_descriptor_iterator(avl *a) { if(a) {}; return 0; }
867
868 avl_tree all_files_index = {
@@ -873,7 +881,9 @@ static struct file_descriptor *file_descriptor_find(const char *name, uint32_t h
881 tmp.name = name;
882 tmp.count = 0;
883 tmp.pos = 0;
884 +#ifdef NETDATA_INTERNAL_CHECKS
885 tmp.magic = 0x0BADCAFE;
886 +#endif /* NETDATA_INTERNAL_CHECKS */
887
888 avl_search(&all_files_index, (avl *)&tmp, file_descriptor_iterator, (avl **)&result);
889 return result;
@@ -895,10 +905,13 @@ static struct file_descriptor *file_descriptor_find(const char *name, uint32_t h
905 void file_descriptor_not_used(int id)
906 {
907 if(id > 0 && id < all_files_size) {
908 +
909 +#ifdef NETDATA_INTERNAL_CHECKS
910 if(all_files[id].magic != 0x0BADCAFE) {
911 error("Ignoring request to remove empty file id %d.", id);
912 return;
913 }
914 +#endif /* NETDATA_INTERNAL_CHECKS */
915
916 if(debug) fprintf(stderr, "apps.plugin: decreasing slot %d (count = %d).\n", id, all_files[id].count);
917
@@ -908,7 +921,9 @@ void file_descriptor_not_used(int id)
921 if(!all_files[id].count) {
922 if(debug) fprintf(stderr, "apps.plugin: >> slot %d is empty.\n", id);
923 file_descriptor_remove(&all_files[id]);
924 +#ifdef NETDATA_INTERNAL_CHECKS
925 all_files[id].magic = 0x00000000;
926 +#endif /* NETDATA_INTERNAL_CHECKS */
927 all_files_len--;
928 }
929 }
@@ -958,7 +973,9 @@ int file_descriptor_find_or_add(const char *name)
973 for(i = all_files_size; i < (all_files_size + FILE_DESCRIPTORS_INCREASE_STEP); i++) {
974 all_files[i].count = 0;
975 all_files[i].name = NULL;
976 +#ifdef NETDATA_INTERNAL_CHECKS
977 all_files[i].magic = 0x00000000;
978 +#endif /* NETDATA_INTERNAL_CHECKS */
979 all_files[i].pos = i;
980 }
981
@@ -977,8 +994,10 @@ int file_descriptor_find_or_add(const char *name)
994 if(!all_files[c].count) {
995 if(debug) fprintf(stderr, "apps.plugin: >> Examining slot %d.\n", c);
996
997 +#ifdef NETDATA_INTERNAL_CHECKS
998 if(all_files[c].magic == 0x0BADCAFE && all_files[c].name && file_descriptor_find(all_files[c].name, all_files[c].hash))
999 error("fd on position %d is not cleared properly. It still has %s in it.\n", c, all_files[c].name);
1000 +#endif /* NETDATA_INTERNAL_CHECKS */
1001
1002 if(debug) fprintf(stderr, "apps.plugin: >> %s fd position %d for %s (last name: %s)\n", all_files[c].name?"re-using":"using", c, name, all_files[c].name);
1003 if(all_files[c].name) free((void *)all_files[c].name);
@@ -1020,8 +1039,9 @@ int file_descriptor_find_or_add(const char *name)
1039 all_files[c].type = type;
1040 all_files[c].pos = c;
1041 all_files[c].count = 1;
1042 +#ifdef NETDATA_INTERNAL_CHECKS
1043 all_files[c].magic = 0x0BADCAFE;
1024 -
1044 +#endif /* NETDATA_INTERNAL_CHECKS */
1045 file_descriptor_add(&all_files[c]);
1046
1047 if(debug) fprintf(stderr, "apps.plugin: using fd position %d (name: %s)\n", c, all_files[c].name);
@@ -1342,7 +1362,7 @@ void update_statistics(void)
1362 p->diff_cstime = p->stime - p->cstime;
1363 p->diff_cminflt = p->minflt - p->cminflt;
1364 p->diff_cmajflt = p->majflt - p->cmajflt;
1345 -#endif
1365 +#endif /* INCLUDE_CHILDS */
1366 }
1367
1368 // give a target to all merged child processes
@@ -1413,7 +1433,7 @@ void update_statistics(void)
1433 if(diff_minflt) error("Cannot fix up minflt %llu", diff_minflt);
1434 if(diff_majflt) error("Cannot fix up majflt %llu", diff_majflt);
1435 }
1416 -#endif
1436 +#endif /* INCLUDE_CHILDS */
1437
1438 // zero all the targets
1439 targets = 0;
@@ -1456,7 +1476,7 @@ void update_statistics(void)
1476
1477 #ifdef INCLUDE_CHILDS
1478 if(debug) walk_down(0, 1);
1459 -#endif
1479 +#endif /* INCLUDE_CHILDS */
1480
1481 // concentrate everything on the targets
1482 for(p = root_of_pids; p ; p = p->next) {
@@ -1532,7 +1552,7 @@ void update_statistics(void)
1552 p->old_majflt = p->majflt;
1553 p->old_cminflt = p->cminflt;
1554 p->old_cmajflt = p->cmajflt;
1535 -#endif
1555 +#endif /* INCLUDE_CHILDS */
1556 }
1557 else {
1558 // since the process has exited, the user