7 #include <mach/mach_error.h>
8 #include <mach/mach_host.h>
9 #include <mach/mach_init.h>
10 #include <mach/mach_types.h>
11 #include <mach/message.h>
26 static_assert(std::numeric_limits<FwSizeType>::max() >= std::numeric_limits<natural_t>::max(),
27 "FwSizeType cannot hold natural_t values");
28 natural_t cpu_count_natural;
29 mach_msg_type_number_t processor_msg_count;
30 kern_return_t stat = host_processor_info(mach_host_self(), PROCESSOR_CPU_LOAD_INFO, &cpu_count_natural,
31 reinterpret_cast<processor_info_array_t*
>(&cpu_load_info), &processor_msg_count);
32 cpu_count = cpu_count_natural;
48 processor_cpu_load_info_t cpu_load_info;
53 if (cpu_count <= cpu_index) {
54 status = KERN_FAILURE;
55 }
else if (KERN_SUCCESS == status) {
56 processor_cpu_load_info per_cpu_info = cpu_load_info[cpu_index];
60 for (
FwSizeType i = 0; i < CPU_STATE_MAX; i++) {
61 total += per_cpu_info.cpu_ticks[i];
63 used = total - per_cpu_info.cpu_ticks[CPU_STATE_IDLE];
69 processor_cpu_load_info_t cpu_load_info;
79 if (KERN_SUCCESS == status) {
88 return &this->m_handle;
PlatformSizeType FwSizeType
Cpu variable handle parent.
CpuHandle * getHandle() override
returns the raw console handle
Status _getCount(FwSizeType &cpu_count) override
Request the count of the CPUs detected by the system.
Status _getTicks(Os::Cpu::Ticks &ticks, FwSizeType cpu_index) override
Get the CPU tick information for a given CPU.
kern_return_t cpu_by_index(FwSizeType cpu_index, FwSizeType &used, FwSizeType &total)
Query for a single CPU's ticks information.
kern_return_t cpu_data_helper(processor_cpu_load_info_t &cpu_load_info, FwSizeType &cpu_count)
helper around raw CPU capture API
Status
Generic OK/ERROR status.
@ OP_OK
Operation succeeded.
Generic used/total struct.
FwSizeType total
Total amount.
FwSizeType used
Used amount.