From 30b94862648cdbf4f537337d2e2f01c369a9dee9 Mon Sep 17 00:00:00 2001 From: Lennart Weller Date: Thu, 21 Apr 2016 14:27:29 +0200 Subject: Imported Upstream version 1.1.0 --- src/proc_softirqs.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) mode change 100755 => 100644 src/proc_softirqs.c (limited to 'src/proc_softirqs.c') diff --git a/src/proc_softirqs.c b/src/proc_softirqs.c old mode 100755 new mode 100644 index 9373baaec..c3a75f600 --- a/src/proc_softirqs.c +++ b/src/proc_softirqs.c @@ -25,10 +25,28 @@ struct interrupt { unsigned long long total; }; +static struct interrupt *alloc_interrupts(int lines) { + static struct interrupt *irrs = NULL; + static int alloced = 0; + + if(lines < alloced) return irrs; + else { + irrs = (struct interrupt *)realloc(irrs, lines * sizeof(struct interrupt)); + if(!irrs) + fatal("Cannot allocate memory for %d interrupts", lines); + + alloced = lines; + } + + return irrs; +} + int do_proc_softirqs(int update_every, unsigned long long dt) { static procfile *ff = NULL; static int cpus = -1, do_per_core = -1; + struct interrupt *irrs = NULL; + if(dt) {}; if(do_per_core == -1) do_per_core = config_get_boolean("plugin:proc:/proc/softirqs", "interrupts per core", 1); @@ -46,6 +64,11 @@ int do_proc_softirqs(int update_every, unsigned long long dt) { uint32_t lines = procfile_lines(ff), l; uint32_t words = procfile_linewords(ff, 0), w; + if(!lines) { + error("Cannot read /proc/softirqs, zero lines reported."); + return 1; + } + // find how many CPUs are there if(cpus == -1) { cpus = 0; @@ -63,7 +86,7 @@ int do_proc_softirqs(int update_every, unsigned long long dt) { } // allocate the size we need; - struct interrupt irrs[lines]; + irrs = alloc_interrupts(lines); irrs[0].used = 0; // loop through all lines -- cgit v1.2.3