1
0
Fork 0
mirror of https://github.com/polybar/polybar.git synced 2024-11-25 13:55:47 -05:00

feat(cpu): Load percentage per core

Display load percentage for individual cpu cores
or a concatenated string for all cores.

Example:

  label = %percentage-core1% %percentage-core4%
  label = %percentage-cores%

Refs #256
This commit is contained in:
Michael Carlberg 2016-12-20 15:24:41 +01:00
parent c14c46b998
commit ff55421f52

View file

@ -54,10 +54,15 @@ namespace modules {
return false; return false;
} }
vector<string> percentage_cores;
for (size_t i = 0; i < cores_n; i++) { for (size_t i = 0; i < cores_n; i++) {
auto load = get_load(i); auto load = get_load(i);
m_total += load; m_total += load;
m_load.emplace_back(load); m_load.emplace_back(load);
if (m_label) {
percentage_cores.emplace_back(to_string(static_cast<int>(load + 0.5f)) + "%");
}
} }
m_total = m_total / static_cast<float>(cores_n); m_total = m_total / static_cast<float>(cores_n);
@ -65,6 +70,12 @@ namespace modules {
if (m_label) { if (m_label) {
m_label->reset_tokens(); m_label->reset_tokens();
m_label->replace_token("%percentage%", to_string(static_cast<int>(m_total + 0.5f)) + "%"); m_label->replace_token("%percentage%", to_string(static_cast<int>(m_total + 0.5f)) + "%");
m_label->replace_token("%percentage-cores%", string_util::join(percentage_cores, " "));
size_t i{0};
for (auto&& p : percentage_cores) {
m_label->replace_token("%percentage-core" + to_string(++i) + "%", p);
}
} }
return true; return true;