diff options
Diffstat (limited to 'CPUMeter.c')
-rw-r--r-- | CPUMeter.c | 36 |
1 files changed, 5 insertions, 31 deletions
@@ -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); |