aboutsummaryrefslogtreecommitdiffstats
path: root/plugin_proc_stat.c
diff options
context:
space:
mode:
authorvolker <volker@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>2010-01-05 22:29:16 +0000
committervolker <volker@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>2010-01-05 22:29:16 +0000
commit55e86007a4860af150cf3a8613e49294183c6b8e (patch)
tree955f08719382ba4ff56823e467b8d5f72594a237 /plugin_proc_stat.c
parentda4098a3eb744d224600627237ae251fd71a9807 (diff)
downloadlcd4linux-55e86007a4860af150cf3a8613e49294183c6b8e.tar.gz
plugins work on MacOS X: proc_stat, cpuinfo
git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@1077 3ae390bd-cb1e-0410-b409-cd5a39f66f1f
Diffstat (limited to 'plugin_proc_stat.c')
-rw-r--r--plugin_proc_stat.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/plugin_proc_stat.c b/plugin_proc_stat.c
index d6a926f..a8c91ce 100644
--- a/plugin_proc_stat.c
+++ b/plugin_proc_stat.c
@@ -41,6 +41,11 @@
#include <ctype.h>
#include <errno.h>
+#ifdef __MAC_OS_X_VERSION_10_3
+#include <mach/mach_host.h>
+#include <mach/host_info.h>
+#endif
+
#include "debug.h"
#include "plugin.h"
#include "qprintf.h"
@@ -84,6 +89,10 @@ static int parse_proc_stat(void)
if (age > 0 && age <= 10)
return 0;
+#if 0
+
+ /* Linux Kernel, /proc-filesystem */
+
if (stream == NULL)
stream = fopen("/proc/stat", "r");
if (stream == NULL) {
@@ -214,6 +223,35 @@ static int parse_proc_stat(void)
hash_put1(buffer, beg);
}
}
+
+#else
+
+ /* MACH Kernel, MacOS X */
+
+ kern_return_t err;
+ mach_msg_type_number_t count;
+ host_info_t r_load;
+ host_cpu_load_info_data_t cpu_load;
+ char s_val[8];
+
+ r_load = &cpu_load;
+ count = HOST_CPU_LOAD_INFO_COUNT;
+ err = host_statistics(mach_host_self(), HOST_CPU_LOAD_INFO, r_load, &count);
+ if (KERN_SUCCESS != err) {
+ error("Error getting cpu load");
+ return -1;
+ }
+ snprintf(s_val, sizeof(s_val), "%d", cpu_load.cpu_ticks[CPU_STATE_USER]);
+ hash_put2("cpu", "user", s_val);
+ snprintf(s_val, sizeof(s_val), "%d", cpu_load.cpu_ticks[CPU_STATE_NICE]);
+ hash_put2("cpu", "nice", s_val);
+ snprintf(s_val, sizeof(s_val), "%d", cpu_load.cpu_ticks[CPU_STATE_SYSTEM]);
+ hash_put2("cpu", "system", s_val);
+ snprintf(s_val, sizeof(s_val), "%d", cpu_load.cpu_ticks[CPU_STATE_IDLE]);
+ hash_put2("cpu", "idle", s_val);
+
+#endif
+
return 0;
}