mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:37:35 +00:00
ProcessManager: Use a CFile for parsing /proc/memstat.
This commit is contained in:
parent
c931eaa22c
commit
ab539460de
2 changed files with 9 additions and 11 deletions
|
@ -8,7 +8,10 @@
|
||||||
|
|
||||||
MemoryStatsWidget::MemoryStatsWidget(GWidget* parent)
|
MemoryStatsWidget::MemoryStatsWidget(GWidget* parent)
|
||||||
: GWidget(parent)
|
: GWidget(parent)
|
||||||
|
, m_proc_memstat("/proc/memstat")
|
||||||
{
|
{
|
||||||
|
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 });
|
||||||
|
|
||||||
|
@ -54,18 +57,13 @@ static inline size_t bytes_to_kb(size_t bytes)
|
||||||
|
|
||||||
void MemoryStatsWidget::refresh()
|
void MemoryStatsWidget::refresh()
|
||||||
{
|
{
|
||||||
FILE* fp = fopen("/proc/memstat", "r");
|
m_proc_memstat.seek(0);
|
||||||
if (!fp) {
|
|
||||||
perror("failed to open /proc/memstat");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
char buf[BUFSIZ];
|
auto line = m_proc_memstat.read_line(BUFSIZ);
|
||||||
char* ptr = fgets(buf, sizeof(buf), fp);
|
if (line.is_null())
|
||||||
if (!ptr)
|
|
||||||
break;
|
break;
|
||||||
auto parts = String(buf, Chomp).split(',');
|
auto parts = String::from_byte_buffer(line, Chomp).split(',');
|
||||||
if (parts.size() < 9)
|
if (parts.size() < 9)
|
||||||
break;
|
break;
|
||||||
bool ok;
|
bool ok;
|
||||||
|
@ -99,8 +97,6 @@ void MemoryStatsWidget::refresh()
|
||||||
m_kmalloc_count_label->set_text(String::format("%u/%u (+%u)", kmalloc_call_count, kfree_call_count, kmalloc_call_count - kfree_call_count));
|
m_kmalloc_count_label->set_text(String::format("%u/%u (+%u)", kmalloc_call_count, kfree_call_count, kmalloc_call_count - kfree_call_count));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(fp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MemoryStatsWidget::timer_event(CTimerEvent&)
|
void MemoryStatsWidget::timer_event(CTimerEvent&)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <LibGUI/GWidget.h>
|
#include <LibGUI/GWidget.h>
|
||||||
|
#include <LibCore/CFile.h>
|
||||||
|
|
||||||
class GLabel;
|
class GLabel;
|
||||||
|
|
||||||
|
@ -19,4 +20,5 @@ private:
|
||||||
GLabel* m_supervisor_physical_pages_label { nullptr };
|
GLabel* m_supervisor_physical_pages_label { nullptr };
|
||||||
GLabel* m_kmalloc_label { nullptr };
|
GLabel* m_kmalloc_label { nullptr };
|
||||||
GLabel* m_kmalloc_count_label { nullptr };
|
GLabel* m_kmalloc_count_label { nullptr };
|
||||||
|
CFile m_proc_memstat;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue