get cpu mhz for darwin

This commit is contained in:
Doug MacEachern 2005-12-02 01:03:03 +00:00
parent 1921b62a7b
commit c7061cc660
1 changed files with 8 additions and 4 deletions

View File

@ -1350,12 +1350,16 @@ int sigar_cpu_info_list_get(sigar_t *sigar,
char model[128], vendor[128], *ptr; char model[128], vendor[128], *ptr;
size = sizeof(mhz); size = sizeof(mhz);
if (!sysctlbyname(CTL_HW_FREQ, &mhz, &size, NULL, 0)) { if (sysctlbyname(CTL_HW_FREQ, &mhz, &size, NULL, 0) < 0) {
mhz /= 1000000; int mib[] = { CTL_HW, HW_CPU_FREQ };
} size = sizeof(mhz);
else { if (sysctl(mib, NMIB(mib), &mhz, &size, NULL, 0) < 0) {
mhz = SIGAR_FIELD_NOTIMPL; mhz = SIGAR_FIELD_NOTIMPL;
} }
}
if (mhz != SIGAR_FIELD_NOTIMPL) {
mhz /= 1000000;
}
size = sizeof(model); size = sizeof(model);
if (sysctlbyname("hw.model", &model, &size, NULL, 0) == -1) { if (sysctlbyname("hw.model", &model, &size, NULL, 0) == -1) {