diff options
author | Lennart Weller <lhw@ring0.de> | 2016-04-21 12:27:29 +0000 |
---|---|---|
committer | Lennart Weller <lhw@ring0.de> | 2016-04-21 12:27:29 +0000 |
commit | 30b94862648cdbf4f537337d2e2f01c369a9dee9 (patch) | |
tree | f0219dd8bd744fc09899bd0266402e05a4bff854 /src/proc_interrupts.c | |
parent | Imported Upstream version 1.0.0 (diff) | |
download | netdata-30b94862648cdbf4f537337d2e2f01c369a9dee9.tar.xz netdata-30b94862648cdbf4f537337d2e2f01c369a9dee9.zip |
Imported Upstream version 1.1.0upstream/1.1.0
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 25482dfa..6704ef1a 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 |