From 11d66ee78dc30d821d4e9de8d937e72aeadaa631 Mon Sep 17 00:00:00 2001 From: Roel Postelmans Date: Fri, 14 Sep 2018 20:42:04 +0200 Subject: [PATCH] feat(mem): Add ramp and bar for swap (#1325) Now all the tokens in the memory module also have ramp and bar counterparts. These can be used exactly the same as `bar-used` and `ramp-used`, they are named ``, ``, ``, and `` --- include/modules/memory.hpp | 8 ++++++++ src/modules/memory.cpp | 24 +++++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/include/modules/memory.hpp b/include/modules/memory.hpp index 91f9f532..5f06d0ab 100644 --- a/include/modules/memory.hpp +++ b/include/modules/memory.hpp @@ -21,6 +21,10 @@ namespace modules { static constexpr const char* TAG_BAR_FREE{""}; static constexpr const char* TAG_RAMP_USED{""}; static constexpr const char* TAG_RAMP_FREE{""}; + static constexpr const char* TAG_BAR_SWAP_USED{""}; + static constexpr const char* TAG_BAR_SWAP_FREE{""}; + static constexpr const char* TAG_RAMP_SWAP_USED{""}; + static constexpr const char* TAG_RAMP_SWAP_FREE{""}; label_t m_label; progressbar_t m_bar_memused; @@ -29,8 +33,12 @@ namespace modules { int m_perc_memfree{0}; ramp_t m_ramp_memused; ramp_t m_ramp_memfree; + progressbar_t m_bar_swapused; + progressbar_t m_bar_swapfree; int m_perc_swap_used{0}; int m_perc_swap_free{0}; + ramp_t m_ramp_swapused; + ramp_t m_ramp_swapfree; }; } diff --git a/src/modules/memory.cpp b/src/modules/memory.cpp index 500821e2..d214c2bb 100644 --- a/src/modules/memory.cpp +++ b/src/modules/memory.cpp @@ -18,7 +18,8 @@ namespace modules { memory_module::memory_module(const bar_settings& bar, string name_) : timer_module(bar, move(name_)) { m_interval = m_conf.get(name(), "interval", 1s); - m_formatter->add(DEFAULT_FORMAT, TAG_LABEL, {TAG_LABEL, TAG_BAR_USED, TAG_BAR_FREE, TAG_RAMP_USED, TAG_RAMP_FREE}); + m_formatter->add(DEFAULT_FORMAT, TAG_LABEL, {TAG_LABEL, TAG_BAR_USED, TAG_BAR_FREE, TAG_RAMP_USED, TAG_RAMP_FREE, + TAG_BAR_SWAP_USED, TAG_BAR_SWAP_FREE, TAG_RAMP_SWAP_USED, TAG_RAMP_SWAP_FREE}); if (m_formatter->has(TAG_BAR_USED)) { m_bar_memused = load_progressbar(m_bar, m_conf, name(), TAG_BAR_USED); @@ -32,6 +33,19 @@ namespace modules { if(m_formatter->has(TAG_RAMP_FREE)) { m_ramp_memfree = load_ramp(m_conf, name(), TAG_RAMP_FREE); } + if (m_formatter->has(TAG_BAR_SWAP_USED)) { + m_bar_swapused = load_progressbar(m_bar, m_conf, name(), TAG_BAR_SWAP_USED); + } + if (m_formatter->has(TAG_BAR_SWAP_FREE)) { + m_bar_swapfree = load_progressbar(m_bar, m_conf, name(), TAG_BAR_SWAP_FREE); + } + if(m_formatter->has(TAG_RAMP_SWAP_USED)) { + m_ramp_swapused = load_ramp(m_conf, name(), TAG_RAMP_SWAP_USED); + } + if(m_formatter->has(TAG_RAMP_SWAP_FREE)) { + m_ramp_swapfree = load_ramp(m_conf, name(), TAG_RAMP_SWAP_FREE); + } + if (m_formatter->has(TAG_LABEL)) { m_label = load_optional_label(m_conf, name(), TAG_LABEL, "%percentage_used%%"); } @@ -116,6 +130,14 @@ namespace modules { builder->node(m_ramp_memfree->get_by_percentage(m_perc_memfree)); } else if (tag == TAG_RAMP_USED) { builder->node(m_ramp_memused->get_by_percentage(m_perc_memused)); + } else if (tag == TAG_BAR_SWAP_USED) { + builder->node(m_bar_swapused->output(m_perc_swap_used)); + } else if (tag == TAG_BAR_SWAP_FREE) { + builder->node(m_bar_swapfree->output(m_perc_swap_free)); + } else if (tag == TAG_RAMP_SWAP_FREE) { + builder->node(m_ramp_swapfree->get_by_percentage(m_perc_swap_free)); + } else if (tag == TAG_RAMP_SWAP_USED) { + builder->node(m_ramp_swapused->get_by_percentage(m_perc_swap_used)); } else { return false; }