mirror of https://github.com/xzeldon/htop.git
Make CPU meter optionally account guest time in its percentages
This commit is contained in:
parent
af285d1d3b
commit
8ace29c267
51
CPUMeter.c
51
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:");
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -150,6 +150,7 @@ typedef struct ProcessList_ {
|
|||
bool detailedCPUTime;
|
||||
bool countCPUsFromZero;
|
||||
bool updateProcessNames;
|
||||
bool accountGuestInCPUMeter;
|
||||
const char **treeStr;
|
||||
|
||||
} ProcessList;
|
||||
|
|
|
@ -130,6 +130,7 @@ typedef struct ProcessList_ {
|
|||
bool detailedCPUTime;
|
||||
bool countCPUsFromZero;
|
||||
bool updateProcessNames;
|
||||
bool accountGuestInCPUMeter;
|
||||
const char **treeStr;
|
||||
|
||||
} ProcessList;
|
||||
|
|
|
@ -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=");
|
||||
|
|
4
htop.c
4
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("/");
|
||||
|
|
Loading…
Reference in New Issue