From ff55421f5232228e0f800c4c574634478c2c5f4a Mon Sep 17 00:00:00 2001 From: Michael Carlberg Date: Tue, 20 Dec 2016 15:24:41 +0100 Subject: [PATCH] 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 --- src/modules/cpu.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/modules/cpu.cpp b/src/modules/cpu.cpp index f74a511b..fdb91442 100644 --- a/src/modules/cpu.cpp +++ b/src/modules/cpu.cpp @@ -54,10 +54,15 @@ namespace modules { return false; } + vector percentage_cores; for (size_t i = 0; i < cores_n; i++) { auto load = get_load(i); m_total += load; m_load.emplace_back(load); + + if (m_label) { + percentage_cores.emplace_back(to_string(static_cast(load + 0.5f)) + "%"); + } } m_total = m_total / static_cast(cores_n); @@ -65,6 +70,12 @@ namespace modules { if (m_label) { m_label->reset_tokens(); m_label->replace_token("%percentage%", to_string(static_cast(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;