X-Git-Url: https://arthur.barton.de/gitweb/?a=blobdiff_plain;f=src%2Fplugin_idlejitter.c;h=2ed78160c93bed78b8d8aea3b63fe08b6734c686;hb=909e26f825bc1f6f907231761412c885331fec7e;hp=a9b340ab00897637b7f047f1c3e3c832b55f4059;hpb=0acd15dd4aae24a0366fafce03679c51feed779d;p=netdata.git diff --git a/src/plugin_idlejitter.c b/src/plugin_idlejitter.c index a9b340ab..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,25 +19,28 @@ 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; unsigned long long counter; for(counter = 0; 1 ;counter++) { - unsigned long long usec = 0, susec = 0; + usec_t usec = 0, susec = 0; - while(susec < (rrd_update_every * 1000000ULL)) { + if(netdata_exit) break; - gettimeofday(&before, NULL); + while(susec < (localhost->rrd_update_every * USEC_PER_SEC)) { + + now_monotonic_timeval(&before); sleep_usec(sleep_ms * 1000); - gettimeofday(&after, NULL); + now_monotonic_timeval(&after); // calculate the time it took for a full loop - usec = usec_dt(&after, &before); + usec = dt_usec(&after, &before); susec += usec; } usec -= (sleep_ms * 1000); @@ -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; }