Merge branch 'main' into fixed-merge-conflict

This commit is contained in:
Στέφανος 2022-10-03 10:41:40 +03:00 committed by GitHub
commit 73afc487fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -106,7 +106,7 @@ namespace Shared {
if (passwd_path.empty())
Logger::warning("Could not read /etc/passwd, will show UID instead of username.");
coreCount = sysconf(_SC_NPROCESSORS_ONLN);
coreCount = sysconf(_SC_NPROCESSORS_CONF);
if (coreCount < 1) {
coreCount = 1;
Logger::warning("Could not determine number of cores, defaulting to 1.");
@ -674,9 +674,29 @@ namespace Cpu {
cread.close();
//? Get cpu total times for all cores from /proc/stat
string cpu_name;
cread.open(Shared::procPath / "stat");
for (int i = 0; cread.good() and cread.peek() == 'c'; i++) {
cread.ignore(SSmax, ' ');
int i = 0;
for (; i <= Shared::coreCount; i++) {
//? Make sure to add zero value for missing core values if at end of file
if ((not cread.good() or cread.peek() != 'c') and i < Shared::coreCount) {
if (i == 0) throw std::runtime_error("Failed to parse /proc/stat");
else cpu.core_percent.at(i-1).push_back(0);
}
else {
if (i == 0) cread.ignore(SSmax, ' ');
else {
cread >> cpu_name;
int cpuNum = std::stoi(cpu_name.substr(3));
if (cpuNum > Shared::coreCount - 1) throw std::runtime_error("Mismatch betweeen /proc/stat core count and previously detected core count");
//? Add zero value for core if core number is missing from /proc/stat
while (i - 1 < cpuNum) {
cpu.core_percent.at(i-1).push_back(0);
if (cpu.core_percent.at(i-1).size() > 40) cpu.core_percent.at(i-1).pop_front();
i++;
}
}
//? Expected on kernel 2.6.3> : 0=user, 1=nice, 2=system, 3=idle, 4=iowait, 5=irq, 6=softirq, 7=steal, 8=guest, 9=guest_nice
vector<long long> times;
@ -717,6 +737,7 @@ namespace Cpu {
if (++ii == 10) break;
}
continue;
}
//? Calculate cpu total for each core
else {
@ -727,12 +748,14 @@ namespace Cpu {
core_old_idles.at(i-1) = idles;
cpu.core_percent.at(i-1).push_back(clamp((long long)round((double)(calc_totals - calc_idles) * 100 / calc_totals), 0ll, 100ll));
}
}
//? Reduce size if there are more values than needed for graph
if (cpu.core_percent.at(i-1).size() > 40) cpu.core_percent.at(i-1).pop_front();
}
}
}
if (i < Shared::coreCount + 1) throw std::runtime_error("Failed to parse /proc/stat");
}
catch (const std::exception& e) {
Logger::debug("get_cpuHz() : " + string{e.what()});