OpenBSD sigar_cpu_get impl

This commit is contained in:
Doug MacEachern 2008-02-18 00:17:27 +00:00
parent 06059b41fe
commit 4ef57c1ae0
1 changed files with 8 additions and 3 deletions

View File

@ -611,16 +611,23 @@ int sigar_cpu_get(sigar_t *sigar, sigar_cpu_t *cpu)
cpu->wait = 0; /*N/A*/ cpu->wait = 0; /*N/A*/
cpu->total = cpu->user + cpu->nice + cpu->sys + cpu->idle; cpu->total = cpu->user + cpu->nice + cpu->sys + cpu->idle;
#elif defined(__FreeBSD__) #elif defined(__FreeBSD__) || (__OpenBSD__)
int status; int status;
unsigned long cp_time[CPUSTATES]; unsigned long cp_time[CPUSTATES];
size_t size = sizeof(cp_time); size_t size = sizeof(cp_time);
# ifdef __OpenBSD__
int mib[] = { CTL_KERN, KERN_CPTIME };
if (sysctl(mib, NMIB(mib), &cp_time, &size, NULL, 0) == -1) {
status = errno;
}
# else
/* try sysctl first, does not require /dev/kmem perms */ /* try sysctl first, does not require /dev/kmem perms */
if (sysctlbyname("kern.cp_time", &cp_time, &size, NULL, 0) == -1) { if (sysctlbyname("kern.cp_time", &cp_time, &size, NULL, 0) == -1) {
status = kread(sigar, &cp_time, sizeof(cp_time), status = kread(sigar, &cp_time, sizeof(cp_time),
sigar->koffsets[KOFFSET_CPUINFO]); sigar->koffsets[KOFFSET_CPUINFO]);
} }
# endif
else { else {
status = SIGAR_OK; status = SIGAR_OK;
} }
@ -635,8 +642,6 @@ int sigar_cpu_get(sigar_t *sigar, sigar_cpu_t *cpu)
cpu->idle = SIGAR_TICK2MSEC(cp_time[CP_IDLE]); cpu->idle = SIGAR_TICK2MSEC(cp_time[CP_IDLE]);
cpu->wait = 0; /*N/A*/ cpu->wait = 0; /*N/A*/
cpu->total = cpu->user + cpu->nice + cpu->sys + cpu->idle; cpu->total = cpu->user + cpu->nice + cpu->sys + cpu->idle;
#else
/*XXX OpenBSD*/
#endif #endif
return SIGAR_OK; return SIGAR_OK;