X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Firq.c;h=cb444a47309c1bad1701e7389acd9eec5a037f8f;hb=e14e8b7f5c5bf9d0fe5cc632c6383f304d4ac2ad;hp=96bf7f06189b883acadaba8cf72cb55349db1eca;hpb=efa4700ad47969749b0fca622294fd006b2d7cb8;p=collectd.git diff --git a/src/irq.c b/src/irq.c index 96bf7f06..cb444a47 100644 --- a/src/irq.c +++ b/src/irq.c @@ -22,9 +22,9 @@ **/ #include "collectd.h" + #include "common.h" #include "plugin.h" -#include "configfile.h" #include "utils_ignorelist.h" #if !KERNEL_LINUX @@ -72,15 +72,12 @@ static int irq_config (const char *key, const char *value) static void irq_submit (const char *irq_name, derive_t value) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; if (ignorelist_match (ignorelist, irq_name) != 0) return; - values[0].derive = value; - - vl.values = values; + vl.values = &(value_t) { .derive = value }; vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "irq", sizeof (vl.plugin)); @@ -94,7 +91,16 @@ static int irq_read (void) { FILE *fh; char buffer[1024]; - + int cpu_count; + char *fields[256]; + + /* + * Example content: + * CPU0 CPU1 CPU2 CPU3 + * 0: 2574 1 3 2 IO-APIC-edge timer + * 1: 102553 158669 218062 70587 IO-APIC-edge i8042 + * 8: 0 0 0 1 IO-APIC-edge rtc0 + */ fh = fopen ("/proc/interrupts", "r"); if (fh == NULL) { @@ -104,20 +110,39 @@ static int irq_read (void) return (-1); } + /* Get CPU count from the first line */ + if(fgets (buffer, sizeof (buffer), fh) != NULL) { + cpu_count = strsplit (buffer, fields, + STATIC_ARRAY_SIZE (fields)); + } else { + ERROR ("irq plugin: unable to get CPU count from first line " + "of /proc/interrupts"); + fclose (fh); + return (-1); + } + while (fgets (buffer, sizeof (buffer), fh) != NULL) { char *irq_name; size_t irq_name_len; derive_t irq_value; int i; - - char *fields[64]; int fields_num; + int irq_values_to_parse; - fields_num = strsplit (buffer, fields, 64); + fields_num = strsplit (buffer, fields, + STATIC_ARRAY_SIZE (fields)); if (fields_num < 2) continue; + /* Parse this many numeric fields, skip the rest + * (+1 because first there is a name of irq in each line) */ + if (fields_num >= cpu_count + 1) + irq_values_to_parse = cpu_count; + else + irq_values_to_parse = fields_num - 1; + + /* First field is irq name and colon */ irq_name = fields[0]; irq_name_len = strlen (irq_name); if (irq_name_len < 2) @@ -128,11 +153,15 @@ static int irq_read (void) if (irq_name[irq_name_len - 1] != ':') continue; + /* Is it the the ARM fast interrupt (FIQ)? */ + if (irq_name_len == 4 && (strncmp(irq_name, "FIQ:", 4) == 0)) + continue; + irq_name[irq_name_len - 1] = 0; irq_name_len--; irq_value = 0; - for (i = 1; i < fields_num; i++) + for (i = 1; i <= irq_values_to_parse; i++) { /* Per-CPU value */ value_t v;