X-Git-Url: https://arthur.barton.de/gitweb/?a=blobdiff_plain;f=src%2Fplugin_idlejitter.c;h=2ed78160c93bed78b8d8aea3b63fe08b6734c686;hb=b428238a72b11dc13bbe87257a53ae97f536d513;hp=77fab3fa8b605f3dc371a74079830ad09a3cda3c;hpb=0e6bc626cb01f374f7e6b89cecb471bd2da003ad;p=netdata.git diff --git a/src/plugin_idlejitter.c b/src/plugin_idlejitter.c index 77fab3fa..2ed78160 100644 --- a/src/plugin_idlejitter.c +++ b/src/plugin_idlejitter.c @@ -2,11 +2,10 @@ #define CPU_IDLEJITTER_SLEEP_TIME_MS 20 -void *cpuidlejitter_main(void *ptr) -{ - if(ptr) { ; } +void *cpuidlejitter_main(void *ptr) { + struct netdata_static_thread *static_thread = (struct netdata_static_thread *)ptr; - info("CPU Idle Jitter thread created with task id %d", gettid()); + info("IDLEJITTER thread created with task id %d", gettid()); if(pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL) != 0) error("Cannot set pthread cancel type to DEFERRED."); @@ -20,10 +19,11 @@ void *cpuidlejitter_main(void *ptr) sleep_ms = CPU_IDLEJITTER_SLEEP_TIME_MS; } - RRDSET *st = rrdset_find("system.idlejitter"); + RRDSET *st = rrdset_find_localhost("system.idlejitter"); if(!st) { - st = rrdset_create("system", "idlejitter", NULL, "processes", NULL, "CPU Idle Jitter", "microseconds lost/s", 9999, rrd_update_every, RRDSET_TYPE_LINE); - rrddim_add(st, "jitter", NULL, 1, 1, RRDDIM_ABSOLUTE); + st = rrdset_create_localhost("system", "idlejitter", NULL, "processes", NULL, "CPU Idle Jitter" + , "microseconds lost/s", 9999, localhost->rrd_update_every, RRDSET_TYPE_LINE); + rrddim_add(st, "jitter", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); } struct timeval before, after; @@ -31,11 +31,13 @@ void *cpuidlejitter_main(void *ptr) for(counter = 0; 1 ;counter++) { usec_t usec = 0, susec = 0; - while(susec < (rrd_update_every * USEC_PER_SEC)) { + if(netdata_exit) break; - now_realtime_timeval(&before); + while(susec < (localhost->rrd_update_every * USEC_PER_SEC)) { + + now_monotonic_timeval(&before); sleep_usec(sleep_ms * 1000); - now_realtime_timeval(&after); + now_monotonic_timeval(&after); // calculate the time it took for a full loop usec = dt_usec(&after, &before); @@ -48,6 +50,9 @@ void *cpuidlejitter_main(void *ptr) rrdset_done(st); } + info("IDLEJITTER thread exiting"); + + static_thread->enabled = 0; pthread_exit(NULL); return NULL; }