work-around for faster dimensions to eliminate extreme case NULL dereference
Costa Tsaousis (ktsaou) committed
Jan 15, 2017 at 06:56 UTC
bebef2b15b13bcb63bdabe414f2dfd808be14cb0
2 files changed
+45
-48
src/plugin_proc_diskspace.c
+9
-12
@@ -186,6 +186,7 @@ void *proc_diskspace_main(void *ptr) {
186
check_for_new_mountpoints_every = update_every;
187
188
RRDSET *stcpu_thread = NULL, *st_duration = NULL;
189
+ RRDDIM *rd_user = NULL, *rd_system = NULL, *rd_duration = NULL;
190
struct rusage thread;
191
192
usec_t last = 0, dt = 0;
@@ -236,38 +237,34 @@ void *proc_diskspace_main(void *ptr) {
237
238
if(!stcpu_thread) {
239
stcpu_thread = rrdset_find("netdata.plugin_diskspace");
239
- if(!stcpu_thread) {
240
- stcpu_thread = rrdset_create("netdata", "plugin_diskspace", NULL, "diskspace", NULL
240
+ if(!stcpu_thread) stcpu_thread = rrdset_create("netdata", "plugin_diskspace", NULL, "diskspace", NULL
241
, "NetData Disk Space Plugin CPU usage", "milliseconds/s", 132020
242
, update_every, RRDSET_TYPE_STACKED);
243
244
- rrddim_add(stcpu_thread, "user", NULL, 1, 1000, RRDDIM_INCREMENTAL);
245
- rrddim_add(stcpu_thread, "system", NULL, 1, 1000, RRDDIM_INCREMENTAL);
246
- }
244
+ rd_user = rrddim_add(stcpu_thread, "user", NULL, 1, 1000, RRDDIM_INCREMENTAL);
245
+ rd_system = rrddim_add(stcpu_thread, "system", NULL, 1, 1000, RRDDIM_INCREMENTAL);
246
}
247
else
248
rrdset_next(stcpu_thread);
249
251
- rrddim_set(stcpu_thread, "user", thread.ru_utime.tv_sec * 1000000ULL + thread.ru_utime.tv_usec);
252
- rrddim_set(stcpu_thread, "system", thread.ru_stime.tv_sec * 1000000ULL + thread.ru_stime.tv_usec);
250
+ rrddim_set_by_pointer(stcpu_thread, rd_user, thread.ru_utime.tv_sec * 1000000ULL + thread.ru_utime.tv_usec);
251
+ rrddim_set_by_pointer(stcpu_thread, rd_system, thread.ru_stime.tv_sec * 1000000ULL + thread.ru_stime.tv_usec);
252
rrdset_done(stcpu_thread);
253
254
// ----------------------------------------------------------------
255
256
if(!st_duration) {
257
st_duration = rrdset_find("netdata.plugin_diskspace_dt");
259
- if(!st_duration) {
260
- st_duration = rrdset_create("netdata", "plugin_diskspace_dt", NULL, "diskspace", NULL
258
+ if(!st_duration) st_duration = rrdset_create("netdata", "plugin_diskspace_dt", NULL, "diskspace", NULL
259
, "NetData Disk Space Plugin Duration", "milliseconds/run", 132021
260
, update_every, RRDSET_TYPE_AREA);
261
264
- rrddim_add(st_duration, "duration", NULL, 1, 1000, RRDDIM_ABSOLUTE);
265
- }
262
+ rd_duration = rrddim_add(st_duration, "duration", NULL, 1, 1000, RRDDIM_ABSOLUTE);
263
}
264
else
265
rrdset_next(st_duration);
266
270
- rrddim_set(st_duration, "duration", dt);
267
+ rrddim_set_by_pointer(st_duration, rd_duration, dt);
268
rrdset_done(st_duration);
269
270
// ----------------------------------------------------------------
src/proc_net_dev.c
+36
-36
@@ -205,11 +205,11 @@ int do_proc_net_dev(int update_every, usec_t dt) {
205
if(unlikely(!d->st_bandwidth)) {
206
d->st_bandwidth = rrdset_find_bytype("net", d->name);
207
208
- if(!d->st_bandwidth) {
208
+ if(!d->st_bandwidth)
209
d->st_bandwidth = rrdset_create("net", d->name, NULL, d->name, "net.net", "Bandwidth", "kilobits/s", 7000, update_every, RRDSET_TYPE_AREA);
210
- d->rd_rbytes = rrddim_add(d->st_bandwidth, "received", NULL, 8, 1024, RRDDIM_INCREMENTAL);
211
- d->rd_tbytes = rrddim_add(d->st_bandwidth, "sent", NULL, -8, 1024, RRDDIM_INCREMENTAL);
212
- }
210
+
211
+ d->rd_rbytes = rrddim_add(d->st_bandwidth, "received", NULL, 8, 1024, RRDDIM_INCREMENTAL);
212
+ d->rd_tbytes = rrddim_add(d->st_bandwidth, "sent", NULL, -8, 1024, RRDDIM_INCREMENTAL);
213
}
214
else rrdset_next(d->st_bandwidth);
215
@@ -227,14 +227,14 @@ int do_proc_net_dev(int update_every, usec_t dt) {
227
if(unlikely(!d->st_packets)) {
228
d->st_packets = rrdset_find_bytype("net_packets", d->name);
229
230
- if(!d->st_packets) {
230
+ if(!d->st_packets)
231
d->st_packets = rrdset_create("net_packets", d->name, NULL, d->name, "net.packets", "Packets", "packets/s", 7001, update_every, RRDSET_TYPE_LINE);
232
- d->st_packets->isdetail = 1;
232
234
- d->rd_rpackets = rrddim_add(d->st_packets, "received", NULL, 1, 1, RRDDIM_INCREMENTAL);
235
- d->rd_tpackets = rrddim_add(d->st_packets, "sent", NULL, -1, 1, RRDDIM_INCREMENTAL);
236
- d->rd_rmulticast = rrddim_add(d->st_packets, "multicast", NULL, 1, 1, RRDDIM_INCREMENTAL);
237
- }
233
+ d->st_packets->isdetail = 1;
234
+
235
+ d->rd_rpackets = rrddim_add(d->st_packets, "received", NULL, 1, 1, RRDDIM_INCREMENTAL);
236
+ d->rd_tpackets = rrddim_add(d->st_packets, "sent", NULL, -1, 1, RRDDIM_INCREMENTAL);
237
+ d->rd_rmulticast = rrddim_add(d->st_packets, "multicast", NULL, 1, 1, RRDDIM_INCREMENTAL);
238
}
239
else rrdset_next(d->st_packets);
240
@@ -253,13 +253,13 @@ int do_proc_net_dev(int update_every, usec_t dt) {
253
if(unlikely(!d->st_errors)) {
254
d->st_errors = rrdset_find_bytype("net_errors", d->name);
255
256
- if(!d->st_errors) {
256
+ if(!d->st_errors)
257
d->st_errors = rrdset_create("net_errors", d->name, NULL, d->name, "net.errors", "Interface Errors", "errors/s", 7002, update_every, RRDSET_TYPE_LINE);
258
- d->st_errors->isdetail = 1;
258
260
- d->rd_rerrors = rrddim_add(d->st_errors, "inbound", NULL, 1, 1, RRDDIM_INCREMENTAL);
261
- d->rd_terrors = rrddim_add(d->st_errors, "outbound", NULL, -1, 1, RRDDIM_INCREMENTAL);
262
- }
259
+ d->st_errors->isdetail = 1;
260
+
261
+ d->rd_rerrors = rrddim_add(d->st_errors, "inbound", NULL, 1, 1, RRDDIM_INCREMENTAL);
262
+ d->rd_terrors = rrddim_add(d->st_errors, "outbound", NULL, -1, 1, RRDDIM_INCREMENTAL);
263
}
264
else rrdset_next(d->st_errors);
265
@@ -277,13 +277,13 @@ int do_proc_net_dev(int update_every, usec_t dt) {
277
if(unlikely(!d->st_drops)) {
278
d->st_drops = rrdset_find_bytype("net_drops", d->name);
279
280
- if(!d->st_drops) {
280
+ if(!d->st_drops)
281
d->st_drops = rrdset_create("net_drops", d->name, NULL, d->name, "net.drops", "Interface Drops", "drops/s", 7003, update_every, RRDSET_TYPE_LINE);
282
- d->st_drops->isdetail = 1;
282
284
- d->rd_rdrops = rrddim_add(d->st_drops, "inbound", NULL, 1, 1, RRDDIM_INCREMENTAL);
285
- d->rd_tdrops = rrddim_add(d->st_drops, "outbound", NULL, -1, 1, RRDDIM_INCREMENTAL);
286
- }
283
+ d->st_drops->isdetail = 1;
284
+
285
+ d->rd_rdrops = rrddim_add(d->st_drops, "inbound", NULL, 1, 1, RRDDIM_INCREMENTAL);
286
+ d->rd_tdrops = rrddim_add(d->st_drops, "outbound", NULL, -1, 1, RRDDIM_INCREMENTAL);
287
}
288
else rrdset_next(d->st_drops);
289
@@ -301,13 +301,13 @@ int do_proc_net_dev(int update_every, usec_t dt) {
301
if(unlikely(!d->st_fifo)) {
302
d->st_fifo = rrdset_find_bytype("net_fifo", d->name);
303
304
- if(!d->st_fifo) {
304
+ if(!d->st_fifo)
305
d->st_fifo = rrdset_create("net_fifo", d->name, NULL, d->name, "net.fifo", "Interface FIFO Buffer Errors", "errors", 7004, update_every, RRDSET_TYPE_LINE);
306
- d->st_fifo->isdetail = 1;
306
308
- d->rd_rfifo = rrddim_add(d->st_fifo, "receive", NULL, 1, 1, RRDDIM_INCREMENTAL);
309
- d->rd_tfifo = rrddim_add(d->st_fifo, "transmit", NULL, -1, 1, RRDDIM_INCREMENTAL);
310
- }
307
+ d->st_fifo->isdetail = 1;
308
+
309
+ d->rd_rfifo = rrddim_add(d->st_fifo, "receive", NULL, 1, 1, RRDDIM_INCREMENTAL);
310
+ d->rd_tfifo = rrddim_add(d->st_fifo, "transmit", NULL, -1, 1, RRDDIM_INCREMENTAL);
311
}
312
else rrdset_next(d->st_fifo);
313
@@ -324,13 +324,13 @@ int do_proc_net_dev(int update_every, usec_t dt) {
324
if(d->do_compressed == CONFIG_ONDEMAND_YES) {
325
if(unlikely(!d->st_compressed)) {
326
d->st_compressed = rrdset_find_bytype("net_compressed", d->name);
327
- if(!d->st_compressed) {
327
+ if(!d->st_compressed)
328
d->st_compressed = rrdset_create("net_compressed", d->name, NULL, d->name, "net.compressed", "Compressed Packets", "packets/s", 7005, update_every, RRDSET_TYPE_LINE);
329
- d->st_compressed->isdetail = 1;
329
331
- d->rd_rcompressed = rrddim_add(d->st_compressed, "received", NULL, 1, 1, RRDDIM_INCREMENTAL);
332
- d->rd_tcompressed = rrddim_add(d->st_compressed, "sent", NULL, -1, 1, RRDDIM_INCREMENTAL);
333
- }
330
+ d->st_compressed->isdetail = 1;
331
+
332
+ d->rd_rcompressed = rrddim_add(d->st_compressed, "received", NULL, 1, 1, RRDDIM_INCREMENTAL);
333
+ d->rd_tcompressed = rrddim_add(d->st_compressed, "sent", NULL, -1, 1, RRDDIM_INCREMENTAL);
334
}
335
else rrdset_next(d->st_compressed);
336
@@ -347,14 +347,14 @@ int do_proc_net_dev(int update_every, usec_t dt) {
347
if(d->do_events == CONFIG_ONDEMAND_YES) {
348
if(unlikely(!d->st_events)) {
349
d->st_events = rrdset_find_bytype("net_events", d->name);
350
- if(!d->st_events) {
350
+ if(!d->st_events)
351
d->st_events = rrdset_create("net_events", d->name, NULL, d->name, "net.events", "Network Interface Events", "events/s", 7006, update_every, RRDSET_TYPE_LINE);
352
- d->st_events->isdetail = 1;
352
354
- d->rd_rframe = rrddim_add(d->st_events, "frames", NULL, 1, 1, RRDDIM_INCREMENTAL);
355
- d->rd_tcollisions = rrddim_add(d->st_events, "collisions", NULL, -1, 1, RRDDIM_INCREMENTAL);
356
- d->rd_tcarrier = rrddim_add(d->st_events, "carrier", NULL, -1, 1, RRDDIM_INCREMENTAL);
357
- }
353
+ d->st_events->isdetail = 1;
354
+
355
+ d->rd_rframe = rrddim_add(d->st_events, "frames", NULL, 1, 1, RRDDIM_INCREMENTAL);
356
+ d->rd_tcollisions = rrddim_add(d->st_events, "collisions", NULL, -1, 1, RRDDIM_INCREMENTAL);
357
+ d->rd_tcarrier = rrddim_add(d->st_events, "carrier", NULL, -1, 1, RRDDIM_INCREMENTAL);
358
}
359
else rrdset_next(d->st_events);
360