Skip to content

Commit b101fb3

Browse files
authored
fix: linux process cpu usage under-reported when vm guests active (#1609)
The Linux /proc/stat fields "guest" and "guest_nice" are already included in "user" and "nice". In Proc::collect do like Cpu::collect does and don't double count them. The double-counting caused the CPU usage denominator to be too large when VM guests were active, causing the reported CPU usage percentages of all processes to be too small. Closes: #1608
1 parent 6462ebc commit b101fb3

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/linux/btop_collect.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2989,12 +2989,13 @@ namespace Proc {
29892989
pread.close();
29902990
}
29912991

2992-
//? Get cpu total times from /proc/stat
2992+
//? Get cpu total times from /proc/stat up to the guest field
29932993
cputimes = 0;
29942994
pread.open(Shared::procPath / "stat");
29952995
if (pread.good()) {
29962996
pread.ignore(SSmax, ' ');
2997-
for (uint64_t times; pread >> times; cputimes += times);
2997+
int i = 0;
2998+
for (uint64_t times; i < 8 and pread >> times; cputimes += times, i++);
29982999
}
29993000
else throw std::runtime_error("Failure to read /proc/stat");
30003001
pread.close();

0 commit comments

Comments
 (0)