mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 09:30:24 +00:00
ProcessManager: Use a CFile for parsing /proc/memstat.
This commit is contained in:
parent
c931eaa22c
commit
ab539460de
Notes:
sideshowbarker
2024-07-19 14:40:31 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/ab539460de9
2 changed files with 9 additions and 11 deletions
|
@ -8,7 +8,10 @@
|
|||
|
||||
MemoryStatsWidget::MemoryStatsWidget(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_preferred_size({ 0, 72 });
|
||||
|
||||
|
@ -54,18 +57,13 @@ static inline size_t bytes_to_kb(size_t bytes)
|
|||
|
||||
void MemoryStatsWidget::refresh()
|
||||
{
|
||||
FILE* fp = fopen("/proc/memstat", "r");
|
||||
if (!fp) {
|
||||
perror("failed to open /proc/memstat");
|
||||
exit(1);
|
||||
}
|
||||
m_proc_memstat.seek(0);
|
||||
|
||||
for (;;) {
|
||||
char buf[BUFSIZ];
|
||||
char* ptr = fgets(buf, sizeof(buf), fp);
|
||||
if (!ptr)
|
||||
auto line = m_proc_memstat.read_line(BUFSIZ);
|
||||
if (line.is_null())
|
||||
break;
|
||||
auto parts = String(buf, Chomp).split(',');
|
||||
auto parts = String::from_byte_buffer(line, Chomp).split(',');
|
||||
if (parts.size() < 9)
|
||||
break;
|
||||
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));
|
||||
break;
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
void MemoryStatsWidget::timer_event(CTimerEvent&)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <LibGUI/GWidget.h>
|
||||
#include <LibCore/CFile.h>
|
||||
|
||||
class GLabel;
|
||||
|
||||
|
@ -19,4 +20,5 @@ private:
|
|||
GLabel* m_supervisor_physical_pages_label { nullptr };
|
||||
GLabel* m_kmalloc_label { nullptr };
|
||||
GLabel* m_kmalloc_count_label { nullptr };
|
||||
CFile m_proc_memstat;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue