@cryptotaxi247 / netdata-1 / commits / 46b93c425

minor optimization on proc loops

Costa Tsaousis (ktsaou) committed Jan 14, 2017 at 20:18 UTC 46b93c425ee738e1eaa69571695ef13171666a96
1 file changed +21 -13
src/plugin_proc.c
+21 -13
@@ -72,10 +72,12 @@ void *proc_main(void *ptr) {
72 // check the enabled status for each module
73 int i;
74 for(i = 0 ; proc_modules[i].name ;i++) {
75 - proc_modules[i].enabled = config_get_boolean("plugin:proc", proc_modules[i].name, 1);
76 - proc_modules[i].last_run_usec = 0ULL;
77 - proc_modules[i].duration = 0ULL;
78 - proc_modules[i].rd = NULL;
75 + struct proc_module *pm = &proc_modules[i];
76 +
77 + pm->enabled = config_get_boolean("plugin:proc", pm->name, 1);
78 + pm->last_run_usec = 0ULL;
79 + pm->duration = 0ULL;
80 + pm->rd = NULL;
81 }
82
83 usec_t step = rrd_update_every * USEC_PER_SEC;
@@ -93,15 +95,16 @@ void *proc_main(void *ptr) {
95 // BEGIN -- the job to be done
96
97 for(i = 0 ; proc_modules[i].name ;i++) {
96 - if(unlikely(!proc_modules[i].enabled)) continue;
98 + struct proc_module *pm = &proc_modules[i];
99 + if(unlikely(!pm->enabled)) continue;
100
98 - debug(D_PROCNETDEV_LOOP, "PROC calling %s.", proc_modules[i].name);
101 + debug(D_PROCNETDEV_LOOP, "PROC calling %s.", pm->name);
102
100 - proc_modules[i].enabled = !proc_modules[i].func(rrd_update_every, (proc_modules[i].last_run_usec > 0)?now - proc_modules[i].last_run_usec:0ULL);
101 - proc_modules[i].last_run_usec = now;
103 + pm->enabled = !pm->func(rrd_update_every, (pm->last_run_usec > 0)?now - pm->last_run_usec:0ULL);
104 + pm->last_run_usec = now;
105
106 now = now_monotonic_usec();
104 - proc_modules[i].duration = now - proc_modules[i].last_run_usec;
107 + pm->duration = now - pm->last_run_usec;
108
109 if(unlikely(netdata_exit)) break;
110 }
@@ -112,6 +115,7 @@ void *proc_main(void *ptr) {
115
116 if(vdo_cpu_netdata) {
117 static RRDSET *st = NULL;
118 +
119 if(unlikely(!st)) {
120 st = rrdset_find_bytype("netdata", "plugin_proc_modules");
121
@@ -119,16 +123,20 @@ void *proc_main(void *ptr) {
123 st = rrdset_create("netdata", "plugin_proc_modules", NULL, "proc", NULL, "NetData Proc Plugin Modules Durations", "milliseconds/run", 132001, rrd_update_every, RRDSET_TYPE_STACKED);
124
125 for(i = 0 ; proc_modules[i].name ;i++) {
122 - if(unlikely(!proc_modules[i].enabled)) continue;
123 - proc_modules[i].rd = rrddim_add(st, proc_modules[i].dim, NULL, 1, 1000, RRDDIM_ABSOLUTE);
126 + struct proc_module *pm = &proc_modules[i];
127 + if(unlikely(!pm->enabled)) continue;
128 +
129 + pm->rd = rrddim_add(st, pm->dim, NULL, 1, 1000, RRDDIM_ABSOLUTE);
130 }
131 }
132 }
133 else rrdset_next(st);
134
135 for(i = 0 ; proc_modules[i].name ;i++) {
130 - if(unlikely(!proc_modules[i].enabled)) continue;
131 - rrddim_set_by_pointer(st, proc_modules[i].rd, proc_modules[i].duration);
136 + struct proc_module *pm = &proc_modules[i];
137 + if(unlikely(!pm->enabled)) continue;
138 +
139 + rrddim_set_by_pointer(st, pm->rd, pm->duration);
140 }
141 rrdset_done(st);
142