This commit is contained in:
aristocratos 2021-05-20 15:04:06 +02:00
parent 9a901a4fba
commit 881b90f4f3

View file

@ -210,12 +210,13 @@ namespace Proc {
if (fs::exists((string)d.path() + "/stat")) { if (fs::exists((string)d.path() + "/stat")) {
pread.clear(); instr.clear(); pstat.clear(); pread.clear(); instr.clear(); pstat.clear();
ifstream pread((string)d.path() + "/stat"); ifstream pread((string)d.path() + "/stat");
if (pread.good() && getline(pread, instr)) { if (pread.good() && getline(pread, instr)) {
pstat = ssplit(instr.substr(instr.rfind(')') + 1), " ", 38); //? Skip pid and comm field and find comm fields closing ')' from right to avoid names with whitespace or parenthesis
pstat = ssplit(instr.substr(instr.rfind(')') + 1), " ", 37, true);
} }
pread.close(); pread.close();
if (pstat.size() < 22) continue; if (pstat.size() < 20) continue;
//? Process state //? Process state
state = pstat[0][0]; state = pstat[0][0];
@ -239,7 +240,7 @@ namespace Proc {
} }
//? CPU number last executed on //? CPU number last executed on
if (pstat.size() > 39) cpu_n = stoi(pstat[36]); if (pstat.size() > 36) cpu_n = stoi(pstat[36]);
//? Process cpu usage since last update, 100'000 because (100 percent * 1000 milliseconds) for correct conversion //? Process cpu usage since last update, 100'000 because (100 percent * 1000 milliseconds) for correct conversion
@ -248,7 +249,7 @@ namespace Proc {
//? Process cumulative cpu usage since process start //? Process cumulative cpu usage since process start
cpu_s = static_cast<double>((cpu_t / clk_tck) / (uptime - (cache[pid].cpu_s / clk_tck))); cpu_s = static_cast<double>((cpu_t / clk_tck) / (uptime - (cache[pid].cpu_s / clk_tck)));
//? Add latest cpu times to cache //? Update cache with latest cpu times
cache[pid].cpu_t = cpu_t; cache[pid].cpu_t = cpu_t;
} }