X-Git-Url: https://arthur.barton.de/gitweb/?a=blobdiff_plain;f=src%2Fplugin_idlejitter.c;h=2ed78160c93bed78b8d8aea3b63fe08b6734c686;hb=8a77a42998d10e3599728e722f6fb2fbe190627c;hp=f18ebb310388fc50a09a79091e1b677097d41e58;hpb=6a9c3d217fc1a249fd12286d76387ef3a9f63163;p=netdata.git diff --git a/src/plugin_idlejitter.c b/src/plugin_idlejitter.c old mode 100755 new mode 100644 index f18ebb31..2ed78160 --- a/src/plugin_idlejitter.c +++ b/src/plugin_idlejitter.c @@ -1,62 +1,59 @@ -#include -#include -#include -#include -#include - -#include "global_statistics.h" #include "common.h" -#include "config.h" -#include "log.h" -#include "rrd.h" -#include "plugin_idlejitter.h" #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("IDLEJITTER thread created with task id %d", gettid()); + + if(pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL) != 0) + error("Cannot set pthread cancel type to DEFERRED."); + + if(pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) != 0) + error("Cannot set pthread cancel state to ENABLE."); - if(pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL) != 0) - error("Cannot set pthread cancel type to DEFERRED."); + int sleep_ms = (int) config_get_number("plugin:idlejitter", "loop time in ms", CPU_IDLEJITTER_SLEEP_TIME_MS); + if(sleep_ms <= 0) { + config_set_number("plugin:idlejitter", "loop time in ms", CPU_IDLEJITTER_SLEEP_TIME_MS); + sleep_ms = CPU_IDLEJITTER_SLEEP_TIME_MS; + } - if(pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) != 0) - error("Cannot set pthread cancel state to ENABLE."); + RRDSET *st = rrdset_find_localhost("system.idlejitter"); + if(!st) { + 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); + } - int sleep_ms = config_get_number("plugin:idlejitter", "loop time in ms", CPU_IDLEJITTER_SLEEP_TIME_MS); - if(sleep_ms <= 0) { - config_set_number("plugin:idlejitter", "loop time in ms", CPU_IDLEJITTER_SLEEP_TIME_MS); - sleep_ms = CPU_IDLEJITTER_SLEEP_TIME_MS; - } + struct timeval before, after; + unsigned long long counter; + for(counter = 0; 1 ;counter++) { + usec_t usec = 0, susec = 0; - RRDSET *st = rrdset_find("system.idlejitter"); - if(!st) { - st = rrdset_create("system", "idlejitter", NULL, "cpu", "CPU Idle Jitter", "microseconds lost/s", 9999, rrd_update_every, RRDSET_TYPE_LINE); - rrddim_add(st, "jitter", NULL, 1, 1, RRDDIM_ABSOLUTE); - } + if(netdata_exit) break; - struct timeval before, after; - unsigned long long counter; - for(counter = 0; 1 ;counter++) { - unsigned long long usec = 0, susec = 0; + while(susec < (localhost->rrd_update_every * USEC_PER_SEC)) { - while(susec < (rrd_update_every * 1000000ULL)) { + now_monotonic_timeval(&before); + sleep_usec(sleep_ms * 1000); + now_monotonic_timeval(&after); - gettimeofday(&before, NULL); - usleep(sleep_ms * 1000); - gettimeofday(&after, NULL); + // calculate the time it took for a full loop + usec = dt_usec(&after, &before); + susec += usec; + } + usec -= (sleep_ms * 1000); - // calculate the time it took for a full loop - usec = usecdiff(&after, &before); - susec += usec; - } - usec -= (sleep_ms * 1000); + if(counter) rrdset_next(st); + rrddim_set(st, "jitter", usec); + rrdset_done(st); + } - if(counter) rrdset_next_usec(st, susec); - rrddim_set(st, "jitter", usec); - rrdset_done(st); - } + info("IDLEJITTER thread exiting"); - return NULL; + static_thread->enabled = 0; + pthread_exit(NULL); + return NULL; }