summaryrefslogtreecommitdiffstats
path: root/darwin
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2015-10-23 13:46:21 -0200
committerHisham Muhammad <hisham@gobolinux.org>2015-10-23 13:46:21 -0200
commit71190654bc926fb137e829fb8e2f9efa1e4344ab (patch)
tree3c7570e7ed4517a129c5d6ff67955964bdb7907c /darwin
parent9c146393a3a8b4470d015066b796cc2807a44142 (diff)
Calculate CPU averages on Darwin (See #295).
Diffstat (limited to 'darwin')
-rw-r--r--darwin/DarwinProcess.c10
-rw-r--r--darwin/Platform.c25
2 files changed, 26 insertions, 9 deletions
diff --git a/darwin/DarwinProcess.c b/darwin/DarwinProcess.c
index 0b4ec3fe..83e9d828 100644
--- a/darwin/DarwinProcess.c
+++ b/darwin/DarwinProcess.c
@@ -220,11 +220,11 @@ char *DarwinProcess_getCmdLine(struct kinfo_proc* k, int show_args ) {
/* Convert previous '\0'. */
*np = ' ';
}
- /* Note location of current '\0'. */
- np = cp;
- }
- }
- }
+ /* Note location of current '\0'. */
+ np = cp;
+ }
+ }
+ }
#endif
/*
diff --git a/darwin/Platform.c b/darwin/Platform.c
index f56d27f3..f8108e78 100644
--- a/darwin/Platform.c
+++ b/darwin/Platform.c
@@ -21,6 +21,7 @@ in the source distribution for its full text.
/*{
#include "Action.h"
+#include "CPUMeter.h"
#include "BatteryMeter.h"
#include "DarwinProcess.h"
}*/
@@ -163,11 +164,27 @@ ProcessPidColumn Process_pidColumns[] = {
{ .id = 0, .label = NULL },
};
+static double Platform_setCPUAverageValues(Meter* mtr) {
+ DarwinProcessList *dpl = (DarwinProcessList *)mtr->pl;
+ int cpus = dpl->super.cpuCount;
+ double sumNice, sumNormal, sumKernel, sumPercent;
+ for (int i = 1; i <= cpus; i++) {
+ sumPercent += Platform_setCPUValues(mtr, i);
+ sumNice += mtr->values[CPU_METER_NICE];
+ sumNormal += mtr->values[CPU_METER_NORMAL];
+ sumKernel += mtr->values[CPU_METER_KERNEL];
+ }
+ mtr->values[CPU_METER_NICE] = sumNice / cpus;
+ mtr->values[CPU_METER_NORMAL] = sumNormal / cpus;
+ mtr->values[CPU_METER_KERNEL] = sumKernel / cpus;
+ return sumPercent / cpus;
+}
+
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;
+
+ if (cpu == 0) {
+ return Platform_setCPUAverageValues(mtr);
+ }
DarwinProcessList *dpl = (DarwinProcessList *)mtr->pl;
processor_cpu_load_info_t prev = &dpl->prev_load[cpu-1];

© 2014-2024 Faster IT GmbH | imprint | privacy policy