3 #define CPU_IDLEJITTER_SLEEP_TIME_MS 20
5 void *cpuidlejitter_main(void *ptr) {
6 struct netdata_static_thread *static_thread = (struct netdata_static_thread *)ptr;
8 info("IDLEJITTER thread created with task id %d", gettid());
10 if(pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL) != 0)
11 error("Cannot set pthread cancel type to DEFERRED.");
13 if(pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) != 0)
14 error("Cannot set pthread cancel state to ENABLE.");
16 int sleep_ms = (int) config_get_number("plugin:idlejitter", "loop time in ms", CPU_IDLEJITTER_SLEEP_TIME_MS);
18 config_set_number("plugin:idlejitter", "loop time in ms", CPU_IDLEJITTER_SLEEP_TIME_MS);
19 sleep_ms = CPU_IDLEJITTER_SLEEP_TIME_MS;
22 RRDSET *st = rrdset_find_localhost("system.idlejitter");
24 st = rrdset_create_localhost("system", "idlejitter", NULL, "processes", NULL, "CPU Idle Jitter"
25 , "microseconds lost/s", 9999, localhost->rrd_update_every, RRDSET_TYPE_LINE);
26 rrddim_add(st, "jitter", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
29 struct timeval before, after;
30 unsigned long long counter;
31 for(counter = 0; 1 ;counter++) {
32 usec_t usec = 0, susec = 0;
34 if(netdata_exit) break;
36 while(susec < (localhost->rrd_update_every * USEC_PER_SEC)) {
38 now_monotonic_timeval(&before);
39 sleep_usec(sleep_ms * 1000);
40 now_monotonic_timeval(&after);
42 // calculate the time it took for a full loop
43 usec = dt_usec(&after, &before);
46 usec -= (sleep_ms * 1000);
48 if(counter) rrdset_next(st);
49 rrddim_set(st, "jitter", usec);
53 info("IDLEJITTER thread exiting");
55 static_thread->enabled = 0;