mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:27:43 +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
3 changed files with 31 additions and 8 deletions
|
@ -17,6 +17,10 @@
|
||||||
#include <LibGfx/StylePainter.h>
|
#include <LibGfx/StylePainter.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
REGISTER_WIDGET(SystemMonitor, MemoryStatsWidget)
|
||||||
|
|
||||||
|
namespace SystemMonitor {
|
||||||
|
|
||||||
static MemoryStatsWidget* s_the;
|
static MemoryStatsWidget* s_the;
|
||||||
|
|
||||||
MemoryStatsWidget* MemoryStatsWidget::the()
|
MemoryStatsWidget* MemoryStatsWidget::the()
|
||||||
|
@ -24,7 +28,12 @@ MemoryStatsWidget* MemoryStatsWidget::the()
|
||||||
return s_the;
|
return s_the;
|
||||||
}
|
}
|
||||||
|
|
||||||
MemoryStatsWidget::MemoryStatsWidget(SystemMonitor::GraphWidget& graph)
|
MemoryStatsWidget::MemoryStatsWidget()
|
||||||
|
: MemoryStatsWidget(nullptr)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
MemoryStatsWidget::MemoryStatsWidget(GraphWidget* graph)
|
||||||
: m_graph(graph)
|
: m_graph(graph)
|
||||||
{
|
{
|
||||||
VERIFY(!s_the);
|
VERIFY(!s_the);
|
||||||
|
@ -59,6 +68,11 @@ MemoryStatsWidget::MemoryStatsWidget(SystemMonitor::GraphWidget& graph)
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MemoryStatsWidget::set_graph_widget(GraphWidget& graph)
|
||||||
|
{
|
||||||
|
m_graph = &graph;
|
||||||
|
}
|
||||||
|
|
||||||
static inline u64 page_count_to_bytes(size_t count)
|
static inline u64 page_count_to_bytes(size_t count)
|
||||||
{
|
{
|
||||||
return count * 4096;
|
return count * 4096;
|
||||||
|
@ -101,6 +115,10 @@ void MemoryStatsWidget::refresh()
|
||||||
m_kfree_count_label->set_text(String::formatted("{}", kfree_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_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);
|
if (m_graph) {
|
||||||
m_graph.add_value({ page_count_to_bytes(user_physical_committed), page_count_to_bytes(user_physical_allocated), kmalloc_bytes_total });
|
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>
|
#include <LibGUI/Widget.h>
|
||||||
|
|
||||||
namespace SystemMonitor {
|
namespace SystemMonitor {
|
||||||
|
|
||||||
class GraphWidget;
|
class GraphWidget;
|
||||||
}
|
|
||||||
|
|
||||||
class MemoryStatsWidget final : public GUI::Widget {
|
class MemoryStatsWidget final : public GUI::Widget {
|
||||||
C_OBJECT(MemoryStatsWidget)
|
C_OBJECT(MemoryStatsWidget)
|
||||||
|
@ -20,12 +20,15 @@ public:
|
||||||
|
|
||||||
virtual ~MemoryStatsWidget() override = default;
|
virtual ~MemoryStatsWidget() override = default;
|
||||||
|
|
||||||
|
void set_graph_widget(GraphWidget& graph);
|
||||||
|
|
||||||
void refresh();
|
void refresh();
|
||||||
|
|
||||||
private:
|
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_label;
|
||||||
RefPtr<GUI::Label> m_user_physical_pages_committed_label;
|
RefPtr<GUI::Label> m_user_physical_pages_committed_label;
|
||||||
RefPtr<GUI::Label> m_supervisor_physical_pages_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_kfree_count_label;
|
||||||
RefPtr<GUI::Label> m_kmalloc_difference_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>(
|
auto& refresh_timer = window->add<Core::Timer>(
|
||||||
frequency * 1000, [&] {
|
frequency * 1000, [&] {
|
||||||
process_model->update();
|
process_model->update();
|
||||||
if (auto* memory_stats_widget = MemoryStatsWidget::the())
|
if (auto* memory_stats_widget = SystemMonitor::MemoryStatsWidget::the())
|
||||||
memory_stats_widget->refresh();
|
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;
|
return graphs_container;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue