3 #define CPU_IDLEJITTER_SLEEP_TIME_MS 20
5 void *cpuidlejitter_main(void *ptr)
9 info("CPU Idle Jitter thread created with task id %d", gettid());
11 if(pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL) != 0)
12 error("Cannot set pthread cancel type to DEFERRED.");
14 if(pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) != 0)
15 error("Cannot set pthread cancel state to ENABLE.");
17 int sleep_ms = (int) config_get_number("plugin:idlejitter", "loop time in ms", CPU_IDLEJITTER_SLEEP_TIME_MS);
19 config_set_number("plugin:idlejitter", "loop time in ms", CPU_IDLEJITTER_SLEEP_TIME_MS);
20 sleep_ms = CPU_IDLEJITTER_SLEEP_TIME_MS;
23 RRDSET *st = rrdset_find("system.idlejitter");
25 st = rrdset_create("system", "idlejitter", NULL, "processes", NULL, "CPU Idle Jitter", "microseconds lost/s", 9999, rrd_update_every, RRDSET_TYPE_LINE);
26 rrddim_add(st, "jitter", NULL, 1, 1, RRDDIM_ABSOLUTE);
29 struct timeval before, after;
30 unsigned long long counter;
31 for(counter = 0; 1 ;counter++) {
32 unsigned long long usec = 0, susec = 0;
34 while(susec < (rrd_update_every * 1000000ULL)) {
36 gettimeofday(&before, NULL);
37 usleep(sleep_ms * 1000);
38 gettimeofday(&after, NULL);
40 // calculate the time it took for a full loop
41 usec = usec_dt(&after, &before);
44 usec -= (sleep_ms * 1000);
46 if(counter) rrdset_next(st);
47 rrddim_set(st, "jitter", usec);