Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved cpu idle ticks calculation #1008

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/freebsd/btop_collect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,13 @@ namespace Cpu {

//? Calculate cpu total for each core
if (i > Shared::coreCount) break;
const long long calc_totals = max(0ll, totals - core_old_totals.at(i));
const long long calc_idles = max(0ll, idles - core_old_idles.at(i));
long long calc_totals = max(0ll, totals - core_old_totals.at(i));
long long calc_idles = max(0ll, idles - core_old_idles.at(i));
if (calc_totals == 0) {
//? No changes for this core, simulate 1 idle
calc_totals = 1;
calc_idles = 1;
}
core_old_totals.at(i) = totals;
core_old_idles.at(i) = idles;

Expand All @@ -453,8 +458,13 @@ namespace Cpu {

}

const long long calc_totals = max(1ll, global_totals - cpu_old.at("totals"));
const long long calc_idles = max(1ll, global_idles - cpu_old.at("idles"));
long long calc_totals = max(0ll, global_totals - cpu_old.at("totals"));
long long calc_idles = max(0ll, global_idles - cpu_old.at("idles"));
if (calc_totals == 0) {
//? No changes, simulate 1 idle
calc_totals = 1;
calc_idles = 1;
}

//? Populate cpu.cpu_percent with all fields from syscall
for (int ii = 0; const auto &val : times_summed) {
Expand Down
18 changes: 14 additions & 4 deletions src/linux/btop_collect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -951,8 +951,13 @@ namespace Cpu {

//? Calculate values for totals from first line of stat
if (i == 0) {
const long long calc_totals = max(1ll, totals - cpu_old.at("totals"));
const long long calc_idles = max(1ll, idles - cpu_old.at("idles"));
long long calc_totals = max(0ll, totals - cpu_old.at("totals"));
long long calc_idles = max(0ll, idles - cpu_old.at("idles"));
if (calc_totals == 0) {
//? No changes in stat, simulate 1 idle
calc_totals = 1;
calc_idles = 1;
}
cpu_old.at("totals") = totals;
cpu_old.at("idles") = idles;

Expand Down Expand Up @@ -982,8 +987,13 @@ namespace Cpu {
core_old_idles.push_back(0);
cpu.core_percent.emplace_back();
}
const long long calc_totals = max(0ll, totals - core_old_totals.at(i-1));
const long long calc_idles = max(0ll, idles - core_old_idles.at(i-1));
long long calc_totals = max(0ll, totals - core_old_totals.at(i-1));
long long calc_idles = max(0ll, idles - core_old_idles.at(i-1));
if (calc_totals == 0) {
//? No changes in stat for this core, simulate 1 idle
calc_totals = 1;
calc_idles = 1;
}
core_old_totals.at(i-1) = totals;
core_old_idles.at(i-1) = idles;

Expand Down
18 changes: 14 additions & 4 deletions src/netbsd/btop_collect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -601,8 +601,13 @@ namespace Cpu {

//? Calculate cpu total for each core
if (i > Shared::coreCount) break;
const long long calc_totals = max(0ll, totals - core_old_totals.at(i));
const long long calc_idles = max(0ll, idles - core_old_idles.at(i));
long long calc_totals = max(0ll, totals - core_old_totals.at(i));
long long calc_idles = max(0ll, idles - core_old_idles.at(i));
if (calc_totals == 0) {
//? No changes for this core, simulate 1 idle
calc_totals = 1;
calc_idles = 1;
}
core_old_totals.at(i) = totals;
core_old_idles.at(i) = idles;

Expand All @@ -618,8 +623,13 @@ namespace Cpu {

}

const long long calc_totals = max(1ll, global_totals - cpu_old.at("totals"));
const long long calc_idles = max(1ll, global_idles - cpu_old.at("idles"));
long long calc_totals = max(0ll, global_totals - cpu_old.at("totals"));
long long calc_idles = max(0ll, global_idles - cpu_old.at("idles"));
if (calc_totals == 0) {
//? No changes, simulate 1 idle
calc_totals = 1;
calc_idles = 1;
}

//? Populate cpu.cpu_percent with all fields from syscall
for (int ii = 0; const auto &val : times_summed) {
Expand Down
18 changes: 14 additions & 4 deletions src/openbsd/btop_collect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,13 @@ namespace Cpu {

//? Calculate cpu total for each core
if (i > Shared::coreCount) break;
const long long calc_totals = max(0ll, totals - core_old_totals.at(i));
const long long calc_idles = max(0ll, idles - core_old_idles.at(i));
long long calc_totals = max(0ll, totals - core_old_totals.at(i));
long long calc_idles = max(0ll, idles - core_old_idles.at(i));
if (calc_totals == 0) {
//? No changes for this core, simulate 1 idle
calc_totals = 1;
calc_idles = 1;
}
core_old_totals.at(i) = totals;
core_old_idles.at(i) = idles;

Expand All @@ -469,8 +474,13 @@ namespace Cpu {

}

const long long calc_totals = max(1ll, global_totals - cpu_old.at("totals"));
const long long calc_idles = max(1ll, global_idles - cpu_old.at("idles"));
long long calc_totals = max(0ll, global_totals - cpu_old.at("totals"));
long long calc_idles = max(0ll, global_idles - cpu_old.at("idles"));
if (calc_totals == 0) {
//? No changes, simulate 1 idle
calc_totals = 1;
calc_idles = 1;
}

//? Populate cpu.cpu_percent with all fields from syscall
for (int ii = 0; const auto &val : times_summed) {
Expand Down
18 changes: 14 additions & 4 deletions src/osx/btop_collect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,8 +494,13 @@ namespace Cpu {

//? Calculate cpu total for each core
if (i > Shared::coreCount) break;
const long long calc_totals = max(0ll, totals - core_old_totals.at(i));
const long long calc_idles = max(0ll, idles - core_old_idles.at(i));
long long calc_totals = max(0ll, totals - core_old_totals.at(i));
long long calc_idles = max(0ll, idles - core_old_idles.at(i));
if (calc_totals == 0) {
//? No changes for this core, simulate 1 idle
calc_totals = 1;
calc_idles = 1;
}
core_old_totals.at(i) = totals;
core_old_idles.at(i) = idles;

Expand All @@ -510,8 +515,13 @@ namespace Cpu {
}
}

const long long calc_totals = max(1ll, global_totals - cpu_old.at("totals"));
const long long calc_idles = max(1ll, global_idles - cpu_old.at("idles"));
long long calc_totals = max(0ll, global_totals - cpu_old.at("totals"));
long long calc_idles = max(0ll, global_idles - cpu_old.at("idles"));
if (calc_totals == 0) {
//? No changes, simulate 1 idle
calc_totals = 1;
calc_idles = 1;
}

//? Populate cpu.cpu_percent with all fields from syscall
for (int ii = 0; const auto &val : times_summed) {
Expand Down
Loading