diff options
Diffstat (limited to 'src/proc_interrupts.c')
-rw-r--r--[-rwxr-xr-x] | src/proc_interrupts.c | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/proc_interrupts.c b/src/proc_interrupts.c index 25482dfa7..6704ef1a5 100755..100644 --- a/src/proc_interrupts.c +++ b/src/proc_interrupts.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_interrupts(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/interrupts", "interrupts per core", 1); @@ -46,6 +64,11 @@ int do_proc_interrupts(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/interrupts, zero lines reported."); + return 1; + } + // find how many CPUs are there if(cpus == -1) { cpus = 0; @@ -63,7 +86,7 @@ int do_proc_interrupts(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 |