]> arthur.barton.de Git - netdata.git/commitdiff
interrupts array moved from stack to memory allocation #66
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Sun, 3 Apr 2016 09:08:52 +0000 (12:08 +0300)
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Sun, 3 Apr 2016 09:08:52 +0000 (12:08 +0300)
src/proc_interrupts.c
src/proc_softirqs.c

index 8ebbd1c2caffc8d90ffb2b3921c60557b4b55b0c..6704ef1a59ac966d52b742fb8b6e35d9fd907ce5 100755 (executable)
@@ -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);
@@ -68,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
index a601c7e350afd389bbd594e1ee8958017c6e6046..c3a75f600abe0893f3b6393b2265c0b1fbf29ee5 100755 (executable)
@@ -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);
@@ -68,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