double Platform_setCPUValues(Meter* mtr, int cpu) { if (cpu == 0) { return Platform_setCPUAverageValues(mtr); } DarwinProcessList *dpl = (DarwinProcessList *)mtr->pl; processor_cpu_load_info_t prev = &dpl->prev_load[cpu-1]; processor_cpu_load_info_t curr = &dpl->curr_load[cpu-1]; double total = 0; /* Take the sums */ for(size_t i = 0; i < CPU_STATE_MAX; ++i) { total += (double)curr->cpu_ticks[i] - (double)prev->cpu_ticks[i]; } mtr->values[CPU_METER_NICE] = ((double)curr->cpu_ticks[CPU_STATE_NICE] - (double)prev->cpu_ticks[CPU_STATE_NICE])* 100.0 / total; mtr->values[CPU_METER_NORMAL] = ((double)curr->cpu_ticks[CPU_STATE_USER] - (double)prev->cpu_ticks[CPU_STATE_USER])* 100.0 / total; mtr->values[CPU_METER_KERNEL] = ((double)curr->cpu_ticks[CPU_STATE_SYSTEM] - (double)prev->cpu_ticks[CPU_STATE_SYSTEM])* 100.0 / total; Meter_setItems(mtr, 3); /* Convert to percent and return */ total = mtr->values[CPU_METER_NICE] + mtr->values[CPU_METER_NORMAL] + mtr->values[CPU_METER_KERNEL]; return CLAMP(total, 0.0, 100.0); }
double Platform_setCPUValues(Meter* mtr, int cpu) { /* All just from CPUMeter.c */ static const int CPU_METER_NICE = 0; static const int CPU_METER_NORMAL = 1; static const int CPU_METER_KERNEL = 2; DarwinProcessList *dpl = (DarwinProcessList *)mtr->pl; processor_cpu_load_info_t prev = &dpl->prev_load[cpu-1]; processor_cpu_load_info_t curr = &dpl->curr_load[cpu-1]; double total = 0; /* Take the sums */ for(size_t i = 0; i < CPU_STATE_MAX; ++i) { total += (double)curr->cpu_ticks[i] - (double)prev->cpu_ticks[i]; } mtr->values[CPU_METER_NICE] = ((double)curr->cpu_ticks[CPU_STATE_NICE] - (double)prev->cpu_ticks[CPU_STATE_NICE])* 100.0 / total; mtr->values[CPU_METER_NORMAL] = ((double)curr->cpu_ticks[CPU_STATE_USER] - (double)prev->cpu_ticks[CPU_STATE_USER])* 100.0 / total; mtr->values[CPU_METER_KERNEL] = ((double)curr->cpu_ticks[CPU_STATE_SYSTEM] - (double)prev->cpu_ticks[CPU_STATE_SYSTEM])* 100.0 / total; Meter_setItems(mtr, 3); /* Convert to percent and return */ total = mtr->values[CPU_METER_NICE] + mtr->values[CPU_METER_NORMAL] + mtr->values[CPU_METER_KERNEL]; return MIN(100.0, MAX(0.0, total)); }