1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:17:44 +00:00

SystemMonitor: Register MemoryStatsWidget

This also requires that the associated graph widget may be null.
This commit is contained in:
kleines Filmröllchen 2022-03-19 00:19:56 +01:00 committed by Andreas Kling
parent abf2ed4c52
commit abfddd01d4
3 changed files with 31 additions and 8 deletions

View file

@ -17,6 +17,10 @@
#include <LibGfx/StylePainter.h>
#include <stdlib.h>
REGISTER_WIDGET(SystemMonitor, MemoryStatsWidget)
namespace SystemMonitor {
static MemoryStatsWidget* s_the;
MemoryStatsWidget* MemoryStatsWidget::the()
@ -24,7 +28,12 @@ MemoryStatsWidget* MemoryStatsWidget::the()
return s_the;
}
MemoryStatsWidget::MemoryStatsWidget(SystemMonitor::GraphWidget& graph)
MemoryStatsWidget::MemoryStatsWidget()
: MemoryStatsWidget(nullptr)
{
}
MemoryStatsWidget::MemoryStatsWidget(GraphWidget* graph)
: m_graph(graph)
{
VERIFY(!s_the);
@ -59,6 +68,11 @@ MemoryStatsWidget::MemoryStatsWidget(SystemMonitor::GraphWidget& graph)
refresh();
}
void MemoryStatsWidget::set_graph_widget(GraphWidget& graph)
{
m_graph = &graph;
}
static inline u64 page_count_to_bytes(size_t count)
{
return count * 4096;
@ -101,6 +115,10 @@ void MemoryStatsWidget::refresh()
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_bytes(total_userphysical_and_swappable_pages) + kmalloc_bytes_total);
m_graph.add_value({ page_count_to_bytes(user_physical_committed), page_count_to_bytes(user_physical_allocated), kmalloc_bytes_total });
if (m_graph) {
m_graph->set_max(page_count_to_bytes(total_userphysical_and_swappable_pages) + kmalloc_bytes_total);
m_graph->add_value({ page_count_to_bytes(user_physical_committed), page_count_to_bytes(user_physical_allocated), kmalloc_bytes_total });
}
}
}