summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2013-12-18 02:58:34 +0000
committerHisham Muhammad <hisham@gobolinux.org>2013-12-18 02:58:34 +0000
commit8ace29c267bad42bc898152541f7732834b291c2 (patch)
tree342b1e4fb1cb08e5d6838953147be2b180383ae3
parentaf285d1d3bb182c3f09c70110f4305cb19437245 (diff)
Make CPU meter optionally account guest time in its percentages
-rw-r--r--CPUMeter.c51
-rw-r--r--DisplayOptionsPanel.c1
-rw-r--r--ProcessList.c1
-rw-r--r--ProcessList.h1
-rw-r--r--Settings.c3
-rw-r--r--htop.c4
6 files changed, 37 insertions, 24 deletions
diff --git a/CPUMeter.c b/CPUMeter.c
index 4ce47849..64286f2f 100644
--- a/CPUMeter.c
+++ b/CPUMeter.c
@@ -20,7 +20,7 @@ in the source distribution for its full text.
}*/
int CPUMeter_attributes[] = {
- CPU_NICE, CPU_NORMAL, CPU_KERNEL, CPU_IRQ, CPU_SOFTIRQ, CPU_IOWAIT, CPU_STEAL, CPU_GUEST
+ CPU_NICE, CPU_NORMAL, CPU_KERNEL, CPU_IRQ, CPU_SOFTIRQ, CPU_STEAL, CPU_GUEST, CPU_IOWAIT
};
#ifndef MIN
@@ -51,24 +51,29 @@ static void CPUMeter_setValues(Meter* this, char* buffer, int size) {
CPUData* cpuData = &(pl->cpus[cpu]);
double total = (double) ( cpuData->totalPeriod == 0 ? 1 : cpuData->totalPeriod);
double percent;
- this->values[0] = cpuData->nicePeriod / total * 100.0;
- this->values[1] = cpuData->userPeriod / total * 100.0;
+ double* v = this->values;
+ v[0] = cpuData->nicePeriod / total * 100.0;
+ v[1] = cpuData->userPeriod / total * 100.0;
if (pl->detailedCPUTime) {
- this->values[2] = cpuData->systemPeriod / total * 100.0;
- this->values[3] = cpuData->irqPeriod / total * 100.0;
- this->values[4] = cpuData->softIrqPeriod / total * 100.0;
- this->values[5] = cpuData->ioWaitPeriod / total * 100.0;
- this->values[6] = cpuData->stealPeriod / total * 100.0;
- this->values[7] = cpuData->guestPeriod / total * 100.0;
+ 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);
- percent = MIN(100.0, MAX(0.0, (this->values[0]+this->values[1]+this->values[2]+
- this->values[3]+this->values[4])));
+ 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 {
- this->values[2] = cpuData->systemAllPeriod / total * 100.0;
- this->values[3] = (cpuData->stealPeriod + cpuData->guestPeriod) / total * 100.0;
+ v[2] = cpuData->systemAllPeriod / total * 100.0;
+ v[3] = (cpuData->stealPeriod + cpuData->guestPeriod) / total * 100.0;
Meter_setItems(this, 4);
- percent = MIN(100.0, MAX(0.0, (this->values[0]+this->values[1]+this->values[2]+this->values[3])));
+ percent = v[0]+v[1]+v[2]+v[3];
}
+ percent = MIN(100.0, MAX(0.0, percent));
if (isnan(percent)) percent = 0.0;
snprintf(buffer, size, "%5.1f%%", percent);
}
@@ -97,17 +102,19 @@ static void CPUMeter_display(Object* cast, RichString* out) {
sprintf(buffer, "%5.1f%% ", this->values[4]);
RichString_append(out, CRT_colors[METER_TEXT], "si:");
RichString_append(out, CRT_colors[CPU_SOFTIRQ], buffer);
- sprintf(buffer, "%5.1f%% ", this->values[5]);
- RichString_append(out, CRT_colors[METER_TEXT], "wa:");
- RichString_append(out, CRT_colors[CPU_IOWAIT], buffer);
- sprintf(buffer, "%5.1f%% ", this->values[6]);
- RichString_append(out, CRT_colors[METER_TEXT], "st:");
- RichString_append(out, CRT_colors[CPU_STEAL], buffer);
- if (this->values[7]) {
- sprintf(buffer, "%5.1f%% ", this->values[7]);
+ if (this->values[5]) {
+ sprintf(buffer, "%5.1f%% ", this->values[5]);
+ RichString_append(out, CRT_colors[METER_TEXT], "st:");
+ RichString_append(out, CRT_colors[CPU_STEAL], buffer);
+ }
+ if (this->values[6]) {
+ sprintf(buffer, "%5.1f%% ", this->values[6]);
RichString_append(out, CRT_colors[METER_TEXT], "gu:");
RichString_append(out, CRT_colors[CPU_GUEST], buffer);
}
+ sprintf(buffer, "%5.1f%% ", this->values[7]);
+ RichString_append(out, CRT_colors[METER_TEXT], "wa:");
+ RichString_append(out, CRT_colors[CPU_IOWAIT], buffer);
} else {
sprintf(buffer, "%5.1f%% ", this->values[2]);
RichString_append(out, CRT_colors[METER_TEXT], "sys:");
diff --git a/DisplayOptionsPanel.c b/DisplayOptionsPanel.c
index 2c01b5ef..61533132 100644
--- a/DisplayOptionsPanel.c
+++ b/DisplayOptionsPanel.c
@@ -90,5 +90,6 @@ DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager*
Panel_add(super, (Object*) CheckItem_new(strdup("Detailed CPU time (System/IO-Wait/Hard-IRQ/Soft-IRQ/Steal/Guest)"), &(settings->pl->detailedCPUTime), false));
Panel_add(super, (Object*) CheckItem_new(strdup("Count CPUs from 0 instead of 1"), &(settings->pl->countCPUsFromZero), false));
Panel_add(super, (Object*) CheckItem_new(strdup("Update process names on every refresh"), &(settings->pl->updateProcessNames), false));
+ Panel_add(super, (Object*) CheckItem_new(strdup("Add guest time in CPU meter percentage"), &(settings->pl->accountGuestInCPUMeter), false));
return this;
}
diff --git a/ProcessList.c b/ProcessList.c
index 88ccae44..a0aed392 100644
--- a/ProcessList.c
+++ b/ProcessList.c
@@ -150,6 +150,7 @@ typedef struct ProcessList_ {
bool detailedCPUTime;
bool countCPUsFromZero;
bool updateProcessNames;
+ bool accountGuestInCPUMeter;
const char **treeStr;
} ProcessList;
diff --git a/ProcessList.h b/ProcessList.h
index af202c87..cabd68d6 100644
--- a/ProcessList.h
+++ b/ProcessList.h
@@ -130,6 +130,7 @@ typedef struct ProcessList_ {
bool detailedCPUTime;
bool countCPUsFromZero;
bool updateProcessNames;
+ bool accountGuestInCPUMeter;
const char **treeStr;
} ProcessList;
diff --git a/Settings.c b/Settings.c
index 46b3a971..0a85d584 100644
--- a/Settings.c
+++ b/Settings.c
@@ -128,6 +128,8 @@ static bool Settings_read(Settings* this, char* fileName, int cpuCount) {
this->pl->countCPUsFromZero = atoi(option[1]);
} else if (String_eq(option[0], "update_process_names")) {
this->pl->updateProcessNames = atoi(option[1]);
+ } else if (String_eq(option[0], "account_guest_in_cpu_meter")) {
+ this->pl->accountGuestInCPUMeter = atoi(option[1]);
} else if (String_eq(option[0], "delay")) {
this->delay = atoi(option[1]);
} else if (String_eq(option[0], "color_scheme")) {
@@ -188,6 +190,7 @@ bool Settings_write(Settings* this) {
fprintf(fd, "detailed_cpu_time=%d\n", (int) this->pl->detailedCPUTime);
fprintf(fd, "cpu_count_from_zero=%d\n", (int) this->pl->countCPUsFromZero);
fprintf(fd, "update_process_names=%d\n", (int) this->pl->updateProcessNames);
+ fprintf(fd, "account_guest_in_cpu_meter=%d\n", (int) this->pl->accountGuestInCPUMeter);
fprintf(fd, "color_scheme=%d\n", (int) this->colorScheme);
fprintf(fd, "delay=%d\n", (int) this->delay);
fprintf(fd, "left_meters=");
diff --git a/htop.c b/htop.c
index de9df527..7471dcd4 100644
--- a/htop.c
+++ b/htop.c
@@ -86,9 +86,9 @@ static void showHelp(ProcessList* pl) {
addattrstr(CRT_colors[CPU_KERNEL], "kernel"); addstr("/");
addattrstr(CRT_colors[CPU_IRQ], "irq"); addstr("/");
addattrstr(CRT_colors[CPU_SOFTIRQ], "soft-irq"); addstr("/");
- addattrstr(CRT_colors[CPU_IOWAIT], "io-wait"); addstr("/");
addattrstr(CRT_colors[CPU_STEAL], "steal"); addstr("/");
- addattrstr(CRT_colors[CPU_GUEST], "guest");
+ addattrstr(CRT_colors[CPU_GUEST], "guest"); addstr("/");
+ addattrstr(CRT_colors[CPU_IOWAIT], "io-wait");
addattrstr(CRT_colors[BAR_SHADOW], " used%");
} else {
addattrstr(CRT_colors[CPU_NICE], "low-priority"); addstr("/");

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