X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fcontextswitch.c;h=834fbd74cd9182c7931c6a2ce898cb98650c01cc;hb=11ca18db12e489c40aa0ac41672872cfae4b1f0b;hp=c207318f9d62425fbfb18e7e86727bce62b65bcb;hpb=26fbc23e518dcc74502ae3b2495112adc3840879;p=collectd.git diff --git a/src/contextswitch.c b/src/contextswitch.c index c207318f..834fbd74 100644 --- a/src/contextswitch.c +++ b/src/contextswitch.c @@ -22,6 +22,7 @@ **/ #include "collectd.h" + #include "common.h" #include "plugin.h" @@ -37,20 +38,21 @@ /* no global variables */ /* #endif KERNEL_LINUX */ +#elif HAVE_PERFSTAT +# include +# include +/* #endif HAVE_PERFSTAT */ + #else # error "No applicable input method." #endif static void cs_submit (derive_t context_switches) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].derive = (derive_t) context_switches; - - vl.values = values; + vl.values = &(value_t) { .derive = context_switches }; vl.values_len = 1; - sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "contextswitch", sizeof (vl.plugin)); sstrncpy (vl.type, "contextswitch", sizeof (vl.type)); @@ -121,7 +123,24 @@ static int cs_read (void) if (status == -2) ERROR ("contextswitch plugin: Unable to find context switch value."); -#endif /* KERNEL_LINUX */ +/* #endif KERNEL_LINUX */ + +#elif HAVE_PERFSTAT + int status = 0; + perfstat_cpu_total_t perfcputotal; + + status = perfstat_cpu_total(NULL, &perfcputotal, sizeof(perfstat_cpu_total_t), 1); + if (status < 0) + { + char errbuf[1024]; + ERROR ("contextswitch plugin: perfstat_cpu_total: %s", + sstrerror (errno, errbuf, sizeof (errbuf))); + return (-1); + } + + cs_submit(perfcputotal.pswitch); + status = 0; +#endif /* defined(HAVE_PERFSTAT) */ return status; }