mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 03:08:11 +00:00
SystemMonitor: Unbreak the memory stats graph
It was never updating because we'd just seek the start of /proc/memstat over and over, which didn't generate new contents. Instead, open the file on every iteration.
This commit is contained in:
parent
806f19d647
commit
d9385d7d62
2 changed files with 5 additions and 14 deletions
|
@ -1,6 +1,7 @@
|
||||||
#include "MemoryStatsWidget.h"
|
#include "MemoryStatsWidget.h"
|
||||||
#include "GraphWidget.h"
|
#include "GraphWidget.h"
|
||||||
#include <AK/JsonObject.h>
|
#include <AK/JsonObject.h>
|
||||||
|
#include <LibCore/CFile.h>
|
||||||
#include <LibDraw/StylePainter.h>
|
#include <LibDraw/StylePainter.h>
|
||||||
#include <LibGUI/GBoxLayout.h>
|
#include <LibGUI/GBoxLayout.h>
|
||||||
#include <LibGUI/GLabel.h>
|
#include <LibGUI/GLabel.h>
|
||||||
|
@ -18,13 +19,10 @@ MemoryStatsWidget* MemoryStatsWidget::the()
|
||||||
MemoryStatsWidget::MemoryStatsWidget(GraphWidget& graph, GWidget* parent)
|
MemoryStatsWidget::MemoryStatsWidget(GraphWidget& graph, GWidget* parent)
|
||||||
: GWidget(parent)
|
: GWidget(parent)
|
||||||
, m_graph(graph)
|
, m_graph(graph)
|
||||||
, m_proc_memstat(CFile::construct("/proc/memstat"))
|
|
||||||
{
|
{
|
||||||
ASSERT(!s_the);
|
ASSERT(!s_the);
|
||||||
s_the = this;
|
s_the = this;
|
||||||
|
|
||||||
if (!m_proc_memstat->open(CIODevice::OpenMode::ReadOnly))
|
|
||||||
ASSERT_NOT_REACHED();
|
|
||||||
set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||||
set_preferred_size(0, 72);
|
set_preferred_size(0, 72);
|
||||||
|
|
||||||
|
@ -69,9 +67,11 @@ static inline size_t bytes_to_kb(size_t bytes)
|
||||||
|
|
||||||
void MemoryStatsWidget::refresh()
|
void MemoryStatsWidget::refresh()
|
||||||
{
|
{
|
||||||
m_proc_memstat->seek(0);
|
auto proc_memstat = CFile::construct("/proc/memstat");
|
||||||
|
if (!proc_memstat->open(CIODevice::OpenMode::ReadOnly))
|
||||||
|
ASSERT_NOT_REACHED();
|
||||||
|
|
||||||
auto file_contents = m_proc_memstat->read_all();
|
auto file_contents = proc_memstat->read_all();
|
||||||
auto json = JsonValue::from_string(file_contents).as_object();
|
auto json = JsonValue::from_string(file_contents).as_object();
|
||||||
|
|
||||||
unsigned kmalloc_eternal_allocated = json.get("kmalloc_eternal_allocated").to_u32();
|
unsigned kmalloc_eternal_allocated = json.get("kmalloc_eternal_allocated").to_u32();
|
||||||
|
@ -97,8 +97,3 @@ void MemoryStatsWidget::refresh()
|
||||||
m_graph.set_max(page_count_to_kb(user_pages_available));
|
m_graph.set_max(page_count_to_kb(user_pages_available));
|
||||||
m_graph.add_value(page_count_to_kb(user_physical_allocated));
|
m_graph.add_value(page_count_to_kb(user_physical_allocated));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MemoryStatsWidget::timer_event(CTimerEvent&)
|
|
||||||
{
|
|
||||||
refresh();
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <LibCore/CFile.h>
|
|
||||||
#include <LibGUI/GWidget.h>
|
#include <LibGUI/GWidget.h>
|
||||||
|
|
||||||
class GLabel;
|
class GLabel;
|
||||||
|
@ -18,12 +17,9 @@ public:
|
||||||
private:
|
private:
|
||||||
MemoryStatsWidget(GraphWidget& graph, GWidget* parent);
|
MemoryStatsWidget(GraphWidget& graph, GWidget* parent);
|
||||||
|
|
||||||
virtual void timer_event(CTimerEvent&) override;
|
|
||||||
|
|
||||||
GraphWidget& m_graph;
|
GraphWidget& m_graph;
|
||||||
RefPtr<GLabel> m_user_physical_pages_label;
|
RefPtr<GLabel> m_user_physical_pages_label;
|
||||||
RefPtr<GLabel> m_supervisor_physical_pages_label;
|
RefPtr<GLabel> m_supervisor_physical_pages_label;
|
||||||
RefPtr<GLabel> m_kmalloc_label;
|
RefPtr<GLabel> m_kmalloc_label;
|
||||||
RefPtr<GLabel> m_kmalloc_count_label;
|
RefPtr<GLabel> m_kmalloc_count_label;
|
||||||
RefPtr<CFile> m_proc_memstat;
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue