summaryrefslogtreecommitdiffstats
path: root/src/proc_softirqs.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/proc_softirqs.c')
-rw-r--r--[-rwxr-xr-x]src/proc_softirqs.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/src/proc_softirqs.c b/src/proc_softirqs.c
index 9373baaec..c3a75f600 100755..100644
--- 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