mirror of
https://github.com/aristocratos/btop.git
synced 2024-09-29 22:51:35 +02:00
Fixed: Use /proc/pid/statm if RSS memory from /proc/pid/stat is faulty
This commit is contained in:
parent
8288d7c311
commit
6d11c8b4db
@ -70,6 +70,7 @@ namespace Shared {
|
|||||||
void init();
|
void init();
|
||||||
|
|
||||||
extern long coreCount, page_size, clk_tck;
|
extern long coreCount, page_size, clk_tck;
|
||||||
|
extern int totalMem_len;
|
||||||
extern uint64_t totalMem;
|
extern uint64_t totalMem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,6 +80,7 @@ namespace Shared {
|
|||||||
fs::path procPath, passwd_path;
|
fs::path procPath, passwd_path;
|
||||||
uint64_t totalMem;
|
uint64_t totalMem;
|
||||||
long pageSize, clkTck, coreCount;
|
long pageSize, clkTck, coreCount;
|
||||||
|
int totalMem_len;
|
||||||
|
|
||||||
void init() {
|
void init() {
|
||||||
|
|
||||||
@ -114,6 +115,7 @@ namespace Shared {
|
|||||||
if (meminfo.good()) {
|
if (meminfo.good()) {
|
||||||
meminfo.ignore(SSmax, ':');
|
meminfo.ignore(SSmax, ':');
|
||||||
meminfo >> totalMem;
|
meminfo >> totalMem;
|
||||||
|
totalMem_len = to_string(totalMem).size();
|
||||||
totalMem <<= 10;
|
totalMem <<= 10;
|
||||||
}
|
}
|
||||||
if (not meminfo.good() or totalMem == 0)
|
if (not meminfo.good() or totalMem == 0)
|
||||||
@ -1451,6 +1453,9 @@ namespace Proc {
|
|||||||
next_x = 24;
|
next_x = 24;
|
||||||
continue;
|
continue;
|
||||||
case 24: //? RSS memory (can be inaccurate, but parsing smaps increases total cpu usage by ~20x)
|
case 24: //? RSS memory (can be inaccurate, but parsing smaps increases total cpu usage by ~20x)
|
||||||
|
if (cmp_greater(short_str.size(), Shared::totalMem_len))
|
||||||
|
new_proc.mem = Shared::totalMem;
|
||||||
|
else
|
||||||
new_proc.mem = stoull(short_str) * Shared::pageSize;
|
new_proc.mem = stoull(short_str) * Shared::pageSize;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -1464,6 +1469,16 @@ namespace Proc {
|
|||||||
|
|
||||||
if (x-offset < 24) continue;
|
if (x-offset < 24) continue;
|
||||||
|
|
||||||
|
//? Get RSS memory from /proc/[pid]/statm if value from /proc/[pid]/stat looks wrong
|
||||||
|
if (new_proc.mem >= Shared::totalMem) {
|
||||||
|
pread.open(d.path() / "statm");
|
||||||
|
if (not pread.good()) continue;
|
||||||
|
pread.ignore(SSmax, ' ');
|
||||||
|
pread >> new_proc.mem;
|
||||||
|
new_proc.mem *= Shared::pageSize;
|
||||||
|
pread.close();
|
||||||
|
}
|
||||||
|
|
||||||
//? Process cpu usage since last update
|
//? Process cpu usage since last update
|
||||||
new_proc.cpu_p = clamp(round(cmult * 1000 * (cpu_t - new_proc.cpu_t) / max((uint64_t)1, cputimes - old_cputimes)) / 10.0, 0.0, 100.0 * Shared::coreCount);
|
new_proc.cpu_p = clamp(round(cmult * 1000 * (cpu_t - new_proc.cpu_t) / max((uint64_t)1, cputimes - old_cputimes)) / 10.0, 0.0, 100.0 * Shared::coreCount);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user