mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 01:20:25 +00:00
SystemMonitor: Register MemoryStatsWidget
This also requires that the associated graph widget may be null.
This commit is contained in:
parent
abf2ed4c52
commit
abfddd01d4
Notes:
sideshowbarker
2024-07-17 20:33:50 +09:00
Author: https://github.com/kleinesfilmroellchen Commit: https://github.com/SerenityOS/serenity/commit/abfddd01d4 Pull-request: https://github.com/SerenityOS/serenity/pull/13125
3 changed files with 31 additions and 8 deletions
|
@ -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 });
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -10,8 +10,8 @@
|
|||
#include <LibGUI/Widget.h>
|
||||
|
||||
namespace SystemMonitor {
|
||||
|
||||
class GraphWidget;
|
||||
}
|
||||
|
||||
class MemoryStatsWidget final : public GUI::Widget {
|
||||
C_OBJECT(MemoryStatsWidget)
|
||||
|
@ -20,12 +20,15 @@ public:
|
|||
|
||||
virtual ~MemoryStatsWidget() override = default;
|
||||
|
||||
void set_graph_widget(GraphWidget& graph);
|
||||
|
||||
void refresh();
|
||||
|
||||
private:
|
||||
MemoryStatsWidget(SystemMonitor::GraphWidget& graph);
|
||||
MemoryStatsWidget(GraphWidget* graph);
|
||||
MemoryStatsWidget();
|
||||
|
||||
SystemMonitor::GraphWidget& m_graph;
|
||||
GraphWidget* m_graph;
|
||||
RefPtr<GUI::Label> m_user_physical_pages_label;
|
||||
RefPtr<GUI::Label> m_user_physical_pages_committed_label;
|
||||
RefPtr<GUI::Label> m_supervisor_physical_pages_label;
|
||||
|
@ -34,3 +37,5 @@ private:
|
|||
RefPtr<GUI::Label> m_kfree_count_label;
|
||||
RefPtr<GUI::Label> m_kmalloc_difference_label;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -212,7 +212,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
auto& refresh_timer = window->add<Core::Timer>(
|
||||
frequency * 1000, [&] {
|
||||
process_model->update();
|
||||
if (auto* memory_stats_widget = MemoryStatsWidget::the())
|
||||
if (auto* memory_stats_widget = SystemMonitor::MemoryStatsWidget::the())
|
||||
memory_stats_widget->refresh();
|
||||
});
|
||||
|
||||
|
@ -746,6 +746,6 @@ NonnullRefPtr<GUI::Widget> build_performance_tab()
|
|||
},
|
||||
});
|
||||
|
||||
graphs_container->add<MemoryStatsWidget>(memory_graph);
|
||||
graphs_container->add<SystemMonitor::MemoryStatsWidget>(&memory_graph);
|
||||
return graphs_container;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue