diff --git a/src/contextswitch.c b/src/contextswitch.c
index 56d8bf09ee490f79bf148eaff6d67947ad98d1f2..344f76e76f0c29242ac20821d8efb25f83f12871 100644 (file)
--- a/src/contextswitch.c
+++ b/src/contextswitch.c
/**
* collectd - src/contextswitch.c
* Copyright (C) 2009 Patrik Weiskircher
+ * Copyright (C) 2010 Kimo Rosenbaum
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
*
* Authors:
* Patrik Weiskircher <weiskircher at inqnet.at>
+ * Kimo Rosenbaum <http://github.com/kimor79>
**/
#include "collectd.h"
/* no global variables */
/* #endif KERNEL_LINUX */
+#elif HAVE_PERFSTAT
+# include <sys/protosw.h>
+# include <libperfstat.h>
+/* #endif HAVE_PERFSTAT */
+
#else
# error "No applicable input method."
#endif
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) {
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;
}