@cryptotaxi247 / netdata-1 / commits / cfc82626a

interrupts array moved from stack to memory allocation #66

Costa Tsaousis (ktsaou) committed Apr 3, 2016 at 12:08 UTC cfc82626ab5bf7cb7bf7c329c6e01be9863199a2
2 files changed +38 -2
src/proc_interrupts.c
+19 -1
@@ -25,10 +25,28 @@ struct interrupt {
25 unsigned long long total;
26 };
27
28 +static struct interrupt *alloc_interrupts(int lines) {
29 + static struct interrupt *irrs = NULL;
30 + static int alloced = 0;
31 +
32 + if(lines < alloced) return irrs;
33 + else {
34 + irrs = (struct interrupt *)realloc(irrs, lines * sizeof(struct interrupt));
35 + if(!irrs)
36 + fatal("Cannot allocate memory for %d interrupts", lines);
37 +
38 + alloced = lines;
39 + }
40 +
41 + return irrs;
42 +}
43 +
44 int do_proc_interrupts(int update_every, unsigned long long dt) {
45 static procfile *ff = NULL;
46 static int cpus = -1, do_per_core = -1;
47
48 + struct interrupt *irrs = NULL;
49 +
50 if(dt) {};
51
52 if(do_per_core == -1) do_per_core = config_get_boolean("plugin:proc:/proc/interrupts", "interrupts per core", 1);
@@ -68,7 +86,7 @@ int do_proc_interrupts(int update_every, unsigned long long dt) {
86 }
87
88 // allocate the size we need;
71 - struct interrupt irrs[lines];
89 + irrs = alloc_interrupts(lines);
90 irrs[0].used = 0;
91
92 // loop through all lines
src/proc_softirqs.c
+19 -1
@@ -25,10 +25,28 @@ struct interrupt {
25 unsigned long long total;
26 };
27
28 +static struct interrupt *alloc_interrupts(int lines) {
29 + static struct interrupt *irrs = NULL;
30 + static int alloced = 0;
31 +
32 + if(lines < alloced) return irrs;
33 + else {
34 + irrs = (struct interrupt *)realloc(irrs, lines * sizeof(struct interrupt));
35 + if(!irrs)
36 + fatal("Cannot allocate memory for %d interrupts", lines);
37 +
38 + alloced = lines;
39 + }
40 +
41 + return irrs;
42 +}
43 +
44 int do_proc_softirqs(int update_every, unsigned long long dt) {
45 static procfile *ff = NULL;
46 static int cpus = -1, do_per_core = -1;
47
48 + struct interrupt *irrs = NULL;
49 +
50 if(dt) {};
51
52 if(do_per_core == -1) do_per_core = config_get_boolean("plugin:proc:/proc/softirqs", "interrupts per core", 1);
@@ -68,7 +86,7 @@ int do_proc_softirqs(int update_every, unsigned long long dt) {
86 }
87
88 // allocate the size we need;
71 - struct interrupt irrs[lines];
89 + irrs = alloc_interrupts(lines);
90 irrs[0].used = 0;
91
92 // loop through all lines