Skip to content

Commit b7eb686

Browse files
committed
Use CPU_METER_STEAL for 'virtualized' CPU time in non-detailed mode
Linux and PCP platform code used to write the 'virtualized' (steal+guest) CPU time into the CPU_METER_IRQ item when the "detailed CPU time" option is off, which would result in a wrong color painted for virtual CPU time in bar mode. Write the 'virtualized' CPU time to CPU_METER_STEAL instead, which is more appropriate for the job. Also update the "virtualized" CPU meter item in the help screen: (1) The color is now CPU_STEAL for consistency. (2) In monochrome mode, two dummy items are displayed before the "virtualized" word so that the bar meter symbol mapping is correct. Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
1 parent 7fb4d52 commit b7eb686

3 files changed

Lines changed: 12 additions & 5 deletions

File tree

Action.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,8 +781,11 @@ static Htop_Reaction actionHelp(State* st) {
781781
addbartext(CRT_colors[CPU_GUEST], "/", "guest");
782782
addbartext(CRT_colors[CPU_IOWAIT], "/", "io-wait");
783783
addbartext(CRT_colors[BAR_SHADOW], " ", "used%");
784+
} else if (CRT_colorScheme == COLORSCHEME_MONOCHROME) {
785+
addbartext(CRT_colors[CPU_STEAL], "/-/-/", "virtualized");
786+
addbartext(CRT_colors[BAR_SHADOW], " ", "used%");
784787
} else {
785-
addbartext(CRT_colors[CPU_GUEST], "/", "virtualized");
788+
addbartext(CRT_colors[CPU_STEAL], "/", "virtualized");
786789
addbartext(CRT_colors[BAR_SHADOW], " ", "used%");
787790
}
788791
addattrstr(CRT_colors[BAR_BORDER], "]");

linux/Platform.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,11 @@ double Platform_setCPUValues(Meter* this, unsigned int cpu) {
373373
v[CPU_METER_KERNEL] = cpuData->systemAllPeriod / total * 100.0;
374374
this->curItems = 3;
375375

376-
v[CPU_METER_IRQ] = (cpuData->stealPeriod + cpuData->guestPeriod) / total * 100.0;
376+
v[CPU_METER_IRQ] = 0.0; // Accounted in 'kernel'
377+
v[CPU_METER_SOFTIRQ] = 0.0; // Accounted in 'kernel'
378+
v[CPU_METER_STEAL] = (cpuData->stealPeriod + cpuData->guestPeriod) / total * 100.0;
377379
if (settings->accountGuestInCPUMeter) {
378-
this->curItems = 4;
380+
this->curItems = 6;
379381
}
380382
}
381383

pcp/Platform.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,10 +562,12 @@ static double Platform_setOneCPUValues(Meter* this, const Settings* settings, pm
562562
v[CPU_METER_KERNEL] = values[CPU_SYSTEM_ALL_PERIOD].ull / total * 100.0;
563563
this->curItems = 3;
564564

565+
v[CPU_METER_IRQ] = 0.0;
566+
v[CPU_METER_SOFTIRQ] = 0.0;
565567
value = values[CPU_STEAL_PERIOD].ull + values[CPU_GUEST_PERIOD].ull;
566-
v[CPU_METER_IRQ] = value / total * 100.0;
568+
v[CPU_METER_STEAL] = value / total * 100.0;
567569
if (settings->accountGuestInCPUMeter) {
568-
this->curItems = 4;
570+
this->curItems = 6;
569571
}
570572
}
571573

0 commit comments

Comments
 (0)