diff options
author | Lennart Weller <lhw@ring0.de> | 2016-09-05 08:27:21 +0000 |
---|---|---|
committer | Lennart Weller <lhw@ring0.de> | 2016-09-05 08:27:21 +0000 |
commit | 1746898cefcb17f58b5cf27b4dad3d28236f1152 (patch) | |
tree | 9207f191cf39bbd077a1e1c73d6e82123e2fc710 /src/plugin_idlejitter.c | |
parent | Imported Upstream version 1.2.0+dfsg (diff) | |
download | netdata-1746898cefcb17f58b5cf27b4dad3d28236f1152.tar.xz netdata-1746898cefcb17f58b5cf27b4dad3d28236f1152.zip |
Imported Upstream version 1.3.0+dfsgupstream/1.3.0+dfsg
Diffstat (limited to 'src/plugin_idlejitter.c')
-rw-r--r-- | src/plugin_idlejitter.c | 84 |
1 files changed, 35 insertions, 49 deletions
diff --git a/src/plugin_idlejitter.c b/src/plugin_idlejitter.c index 56c22a16..30c6d870 100644 --- a/src/plugin_idlejitter.c +++ b/src/plugin_idlejitter.c @@ -1,68 +1,54 @@ -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#include <pthread.h> -#include <sys/time.h> -#include <sys/resource.h> -#include <strings.h> -#include <unistd.h> - -#include "global_statistics.h" #include "common.h" -#include "appconfig.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) { ; } + if(ptr) { ; } - info("CPU Idle Jitter thread created with task id %d", gettid()); + info("CPU Idle Jitter 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_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_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) != 0) + error("Cannot set pthread cancel state to ENABLE."); - 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; - } + 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; + } - RRDSET *st = rrdset_find("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); - } + RRDSET *st = rrdset_find("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); + } - struct timeval before, after; - unsigned long long counter; - for(counter = 0; 1 ;counter++) { - unsigned long long usec = 0, susec = 0; + struct timeval before, after; + unsigned long long counter; + for(counter = 0; 1 ;counter++) { + unsigned long long usec = 0, susec = 0; - while(susec < (rrd_update_every * 1000000ULL)) { + while(susec < (rrd_update_every * 1000000ULL)) { - gettimeofday(&before, NULL); - usleep(sleep_ms * 1000); - gettimeofday(&after, NULL); + gettimeofday(&before, NULL); + usleep(sleep_ms * 1000); + gettimeofday(&after, NULL); - // calculate the time it took for a full loop - usec = usecdiff(&after, &before); - susec += usec; - } - usec -= (sleep_ms * 1000); + // calculate the time it took for a full loop + usec = usec_dt(&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(st); + rrddim_set(st, "jitter", usec); + rrdset_done(st); + } - pthread_exit(NULL); - return NULL; + pthread_exit(NULL); + return NULL; } |