try sysctl first to get cpu info

This commit is contained in:
Doug MacEachern 2005-02-15 01:56:22 +00:00
parent 63c5b91496
commit 1a0c381c58
1 changed files with 9 additions and 2 deletions

View File

@ -359,9 +359,16 @@ int sigar_cpu_get(sigar_t *sigar, sigar_cpu_t *cpu)
#else #else
int status; int status;
long cp_time[CPUSTATES]; long cp_time[CPUSTATES];
size_t size = sizeof(cp_time);
status = kread(sigar, &cp_time, sizeof(cp_time), /* try sysctl first, does not require /dev/kmem perms */
sigar->koffsets[KOFFSET_CPUINFO]); if (sysctlbyname("kern.cp_time", &cp_time, &size, NULL, 0) == -1) {
status = kread(sigar, &cp_time, sizeof(cp_time),
sigar->koffsets[KOFFSET_CPUINFO]);
}
else {
status = SIGAR_OK;
}
if (status != SIGAR_OK) { if (status != SIGAR_OK) {
return status; return status;