From b5785ebec1ab3c33a84413ae2e7839f66184e144 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Sat, 31 Dec 2005 19:51:04 +0000 Subject: [PATCH] fix cpu_list for multi cpus on darwin --- src/os/darwin/darwin_sigar.c | 38 ++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/os/darwin/darwin_sigar.c b/src/os/darwin/darwin_sigar.c index c7f0b999..ceddf994 100644 --- a/src/os/darwin/darwin_sigar.c +++ b/src/os/darwin/darwin_sigar.c @@ -495,6 +495,43 @@ int sigar_cpu_get(sigar_t *sigar, sigar_cpu_t *cpu) int sigar_cpu_list_get(sigar_t *sigar, sigar_cpu_list_t *cpulist) { +#ifdef DARWIN + kern_return_t status; + mach_msg_type_number_t count; + processor_cpu_load_info_data_t *cpuload; + natural_t i, ncpu; + + status = host_processor_info(mach_host_self(), + PROCESSOR_CPU_LOAD_INFO, + &ncpu, + (processor_info_array_t*)&cpuload, + &count); + + if (status != KERN_SUCCESS) { + return errno; + } + + sigar_cpu_list_create(cpulist); + + for (i=0; idata[cpulist->number++]; + + cpu->user = cpuload[i].cpu_ticks[CPU_STATE_USER]; + cpu->sys = cpuload[i].cpu_ticks[CPU_STATE_SYSTEM]; + cpu->idle = cpuload[i].cpu_ticks[CPU_STATE_IDLE]; + cpu->nice = cpuload[i].cpu_ticks[CPU_STATE_NICE]; + cpu->wait = 0; /*N/A*/ + cpu->total = cpu->user + cpu->nice + cpu->sys + cpu->idle; + } + + vm_deallocate(mach_task_self(), (vm_address_t)cpuload, count); + + return SIGAR_OK; +#else sigar_cpu_t *cpu; sigar_cpu_list_create(cpulist); @@ -503,6 +540,7 @@ int sigar_cpu_list_get(sigar_t *sigar, sigar_cpu_list_t *cpulist) cpu = &cpulist->data[cpulist->number++]; return sigar_cpu_get(sigar, cpu); +#endif } int sigar_uptime_get(sigar_t *sigar,