summaryrefslogtreecommitdiffstats
path: root/CPUMeter.c
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2015-01-21 23:27:31 -0200
committerHisham Muhammad <hisham@gobolinux.org>2015-01-21 23:27:31 -0200
commit3383d8e5561dfc6fb2b65e0a194df94ccb5e08af (patch)
treedafba704561386b31b6b8af6dafb5b9a2ba7453c /CPUMeter.c
parent36b78328843d0dae0d0fadbd0e814a8a1546327c (diff)
Sorry about the mega-patch.
This is a work-in-progress, code is currently broken. (Some actions, and notably, the header, are missing.)
Diffstat (limited to 'CPUMeter.c')
-rw-r--r--CPUMeter.c36
1 files changed, 5 insertions, 31 deletions
diff --git a/CPUMeter.c b/CPUMeter.c
index 95b397f6..511af8e9 100644
--- a/CPUMeter.c
+++ b/CPUMeter.c
@@ -8,7 +8,8 @@ in the source distribution for its full text.
#include "CPUMeter.h"
#include "CRT.h"
-#include "ProcessList.h"
+#include "Settings.h"
+#include "Platform.h"
#include <assert.h>
#include <stdlib.h>
@@ -34,7 +35,7 @@ static void CPUMeter_init(Meter* this) {
int cpu = this->param;
if (this->pl->cpuCount > 1) {
char caption[10];
- sprintf(caption, "%-3d", ProcessList_cpuId(this->pl, cpu - 1));
+ sprintf(caption, "%-3d", Settings_cpuId(this->pl->settings, cpu - 1));
Meter_setCaption(this, caption);
}
if (this->param == 0)
@@ -42,39 +43,12 @@ static void CPUMeter_init(Meter* this) {
}
static void CPUMeter_setValues(Meter* this, char* buffer, int size) {
- ProcessList* pl = this->pl;
int cpu = this->param;
if (cpu > this->pl->cpuCount) {
snprintf(buffer, size, "absent");
return;
}
- CPUData* cpuData = &(pl->cpus[cpu]);
- double total = (double) ( cpuData->totalPeriod == 0 ? 1 : cpuData->totalPeriod);
- double percent;
- double* v = this->values;
- v[0] = cpuData->nicePeriod / total * 100.0;
- v[1] = cpuData->userPeriod / total * 100.0;
- if (pl->detailedCPUTime) {
- v[2] = cpuData->systemPeriod / total * 100.0;
- v[3] = cpuData->irqPeriod / total * 100.0;
- v[4] = cpuData->softIrqPeriod / total * 100.0;
- v[5] = cpuData->stealPeriod / total * 100.0;
- v[6] = cpuData->guestPeriod / total * 100.0;
- v[7] = cpuData->ioWaitPeriod / total * 100.0;
- Meter_setItems(this, 8);
- if (pl->accountGuestInCPUMeter) {
- percent = v[0]+v[1]+v[2]+v[3]+v[4]+v[5]+v[6];
- } else {
- percent = v[0]+v[1]+v[2]+v[3]+v[4];
- }
- } else {
- v[2] = cpuData->systemAllPeriod / total * 100.0;
- v[3] = (cpuData->stealPeriod + cpuData->guestPeriod) / total * 100.0;
- Meter_setItems(this, 4);
- percent = v[0]+v[1]+v[2]+v[3];
- }
- percent = MIN(100.0, MAX(0.0, percent));
- if (isnan(percent)) percent = 0.0;
+ double percent = Platform_setCPUValues(this, cpu);
snprintf(buffer, size, "%5.1f%%", percent);
}
@@ -89,7 +63,7 @@ static void CPUMeter_display(Object* cast, RichString* out) {
sprintf(buffer, "%5.1f%% ", this->values[1]);
RichString_append(out, CRT_colors[METER_TEXT], ":");
RichString_append(out, CRT_colors[CPU_NORMAL], buffer);
- if (this->pl->detailedCPUTime) {
+ if (this->pl->settings->detailedCPUTime) {
sprintf(buffer, "%5.1f%% ", this->values[2]);
RichString_append(out, CRT_colors[METER_TEXT], "sy:");
RichString_append(out, CRT_colors[CPU_KERNEL], buffer);

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