From 9699648b2a5f86a338564b303c8ec960e98842f7 Mon Sep 17 00:00:00 2001 From: David Isaksson Date: Fri, 3 Sep 2021 18:26:58 +0200 Subject: [PATCH] SystemMonitor: Make memory statistics dynamically formatted by size Previously all memory values on the performance was formatted as KiB, but with such formatting it can be quite hard to read large numbers (as mentioned by Andreas on todays office hours livestream :^)). This patch makes use of the human readable formatting utilies and displays them in an easier to read format. --- .../SystemMonitor/MemoryStatsWidget.cpp | 22 ++++++++++++------- Userland/Applications/SystemMonitor/main.cpp | 12 +++++----- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/Userland/Applications/SystemMonitor/MemoryStatsWidget.cpp b/Userland/Applications/SystemMonitor/MemoryStatsWidget.cpp index 3e435553e3..1c0a23705f 100644 --- a/Userland/Applications/SystemMonitor/MemoryStatsWidget.cpp +++ b/Userland/Applications/SystemMonitor/MemoryStatsWidget.cpp @@ -7,6 +7,7 @@ #include "MemoryStatsWidget.h" #include "GraphWidget.h" #include +#include #include #include #include @@ -61,9 +62,14 @@ MemoryStatsWidget::~MemoryStatsWidget() { } -static inline u64 page_count_to_kb(u64 kb) +static inline u64 page_count_to_bytes(u64 count) { - return (kb * 4096) / 1024; + return count * 4096; +} + +static inline u64 page_count_to_kb(u64 count) +{ + return page_count_to_bytes(count) / 1024; } static inline u64 bytes_to_kb(u64 bytes) @@ -102,14 +108,14 @@ void MemoryStatsWidget::refresh() size_t physical_pages_in_use = user_physical_allocated + super_physical_alloc; size_t total_userphysical_and_swappable_pages = user_physical_allocated + user_physical_committed + user_physical_uncommitted; - m_kmalloc_space_label->set_text(String::formatted("{}K/{}K", bytes_to_kb(kmalloc_allocated), bytes_to_kb(kmalloc_bytes_total))); - m_user_physical_pages_label->set_text(String::formatted("{}K/{}K", page_count_to_kb(physical_pages_in_use), page_count_to_kb(physical_pages_total))); - m_user_physical_pages_committed_label->set_text(String::formatted("{}K", page_count_to_kb(user_physical_committed))); - m_supervisor_physical_pages_label->set_text(String::formatted("{}K/{}K", page_count_to_kb(super_physical_alloc), page_count_to_kb(supervisor_pages_total))); + m_kmalloc_space_label->set_text(String::formatted("{}/{}", human_readable_size(kmalloc_allocated), human_readable_size(kmalloc_bytes_total))); + m_user_physical_pages_label->set_text(String::formatted("{}/{}", human_readable_size(page_count_to_bytes(physical_pages_in_use)), human_readable_size(page_count_to_bytes(physical_pages_total)))); + m_user_physical_pages_committed_label->set_text(String::formatted("{}", human_readable_size(page_count_to_bytes(user_physical_committed)))); + m_supervisor_physical_pages_label->set_text(String::formatted("{}/{}", human_readable_size(page_count_to_bytes(super_physical_alloc)), human_readable_size(page_count_to_bytes(supervisor_pages_total)))); m_kmalloc_count_label->set_text(String::formatted("{}", kmalloc_call_count)); m_kfree_count_label->set_text(String::formatted("{}", kfree_call_count)); m_kmalloc_difference_label->set_text(String::formatted("{:+}", kmalloc_call_count - kfree_call_count)); - m_graph.set_max(page_count_to_kb(total_userphysical_and_swappable_pages) + bytes_to_kb(kmalloc_bytes_total)); - m_graph.add_value({ (int)page_count_to_kb(user_physical_committed), (int)page_count_to_kb(user_physical_allocated), (int)bytes_to_kb(kmalloc_bytes_total) }); + m_graph.set_max(page_count_to_bytes(total_userphysical_and_swappable_pages) + kmalloc_bytes_total); + m_graph.add_value({ (int)page_count_to_bytes(user_physical_committed), (int)page_count_to_bytes(user_physical_allocated), (int)kmalloc_bytes_total }); } diff --git a/Userland/Applications/SystemMonitor/main.cpp b/Userland/Applications/SystemMonitor/main.cpp index a38151b5c2..554c28be03 100644 --- a/Userland/Applications/SystemMonitor/main.cpp +++ b/Userland/Applications/SystemMonitor/main.cpp @@ -710,20 +710,20 @@ NonnullRefPtr build_performance_tab() memory_graph.set_stack_values(true); memory_graph.set_value_format(0, { .graph_color_role = ColorRole::SyntaxComment, - .text_formatter = [](int value) { - return String::formatted("Committed: {} KiB", value); + .text_formatter = [](int bytes) { + return String::formatted("Committed: {}", human_readable_size(bytes)); }, }); memory_graph.set_value_format(1, { .graph_color_role = ColorRole::SyntaxPreprocessorStatement, - .text_formatter = [](int value) { - return String::formatted("Allocated: {} KiB", value); + .text_formatter = [](int bytes) { + return String::formatted("Allocated: {}", human_readable_size(bytes)); }, }); memory_graph.set_value_format(2, { .graph_color_role = ColorRole::SyntaxPreprocessorValue, - .text_formatter = [](int value) { - return String::formatted("Kernel heap: {} KiB", value); + .text_formatter = [](int bytes) { + return String::formatted("Kernel heap: {}", human_readable_size(bytes)); }, });