X-Git-Url: https://git.octo.it/?a=blobdiff_plain;ds=sidebyside;f=src%2Fcontextswitch.c;h=3bd6d9f53cc849421760fa211dfab9caddb106a7;hb=e1bfa71aca1f37c2f293dc9adb44065c6e7a9ad9;hp=f571d39c39201c174d0cfea1ba68054a6565ad0d;hpb=5faee1b80e2718c7c12801439af1a6a6729c0b8d;p=collectd.git diff --git a/src/contextswitch.c b/src/contextswitch.c index f571d39c..3bd6d9f5 100644 --- a/src/contextswitch.c +++ b/src/contextswitch.c @@ -22,6 +22,7 @@ **/ #include "collectd.h" + #include "common.h" #include "plugin.h" @@ -37,18 +38,20 @@ /* 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)); @@ -59,29 +62,31 @@ static void cs_submit (derive_t context_switches) static int cs_read (void) { - int status = -2; #if HAVE_SYSCTLBYNAME - int value; + int value = 0; size_t value_len = sizeof (value); + int status; - if (sysctlbyname ("vm.stats.sys.v_swtch", (void *) &value, &value_len, - NULL, 0) == 0) + status = sysctlbyname ("vm.stats.sys.v_swtch", + &value, &value_len, + /* new pointer = */ NULL, /* new length = */ 0); + if (status != 0) { - cs_submit(value); - status = 0; - } - else - { - ERROR("contextswitch plugin: sysctlbyname failed"); + ERROR("contextswitch plugin: sysctlbyname " + "(vm.stats.sys.v_swtch) failed"); + return (-1); } + cs_submit (value); /* #endif HAVE_SYSCTLBYNAME */ + #elif KERNEL_LINUX FILE *fh; char buffer[64]; int numfields; char *fields[3]; derive_t result = 0; + int status = -2; fh = fopen ("/proc/stat", "r"); if (fh == NULL) { @@ -119,7 +124,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; }