diff --git a/Applications/ProcessManager/MemoryStatsWidget.cpp b/Applications/ProcessManager/MemoryStatsWidget.cpp index 124636e795a..d114d937d45 100644 --- a/Applications/ProcessManager/MemoryStatsWidget.cpp +++ b/Applications/ProcessManager/MemoryStatsWidget.cpp @@ -1,5 +1,6 @@ #include "MemoryStatsWidget.h" #include "GraphWidget.h" +#include #include #include #include @@ -60,47 +61,31 @@ void MemoryStatsWidget::refresh() { m_proc_memstat.seek(0); - for (;;) { - auto line = m_proc_memstat.read_line(BUFSIZ); - if (line.is_null()) - break; - auto chomped = String((const char*)line.pointer(), line.size() - 1, Chomp); - auto parts = chomped.split_view(','); - if (parts.size() < 9) - break; - bool ok; - unsigned kmalloc_sum_eternal = parts[0].to_uint(ok); - ASSERT(ok); - (void)kmalloc_sum_eternal; - unsigned kmalloc_sum_alloc = parts[1].to_uint(ok); - ASSERT(ok); - unsigned kmalloc_sum_free = parts[2].to_uint(ok); - ASSERT(ok); - unsigned user_pages_alloc = parts[3].to_uint(ok); - ASSERT(ok); - unsigned user_pages_free = parts[4].to_uint(ok); - ASSERT(ok); - unsigned supervisor_pages_alloc = parts[5].to_uint(ok); - ASSERT(ok); - unsigned supervisor_pages_free = parts[6].to_uint(ok); - ASSERT(ok); - unsigned kmalloc_call_count = parts[7].to_uint(ok); - ASSERT(ok); - unsigned kfree_call_count = parts[8].to_uint(ok); - ASSERT(ok); + auto file_contents = m_proc_memstat.read_all(); + auto json = JsonValue::from_string(file_contents).as_object(); - size_t kmalloc_sum_available = kmalloc_sum_alloc + kmalloc_sum_free; - size_t user_pages_available = user_pages_alloc + user_pages_free; - size_t supervisor_pages_available = supervisor_pages_alloc + supervisor_pages_free; + unsigned kmalloc_eternal_allocated = json.get("kmalloc_eternal_allocated").to_dword(); + (void)kmalloc_eternal_allocated; + unsigned kmalloc_allocated = json.get("kmalloc_allocated").to_dword(); + unsigned kmalloc_available = json.get("kmalloc_available").to_dword(); + unsigned user_physical_allocated = json.get("user_physical_allocated").to_dword(); + unsigned user_physical_available = json.get("user_physical_available").to_dword(); + unsigned super_physical_alloc = json.get("super_physical_allocated").to_dword(); + unsigned super_physical_free = json.get("super_physical_available").to_dword(); + unsigned kmalloc_call_count = json.get("kmalloc_call_count").to_dword(); + unsigned kfree_call_count = json.get("kfree_call_count").to_dword(); - m_kmalloc_label->set_text(String::format("%uK/%uK", bytes_to_kb(kmalloc_sum_alloc), bytes_to_kb(kmalloc_sum_available))); - m_user_physical_pages_label->set_text(String::format("%uK/%uK", page_count_to_kb(user_pages_alloc), page_count_to_kb(user_pages_available))); - m_supervisor_physical_pages_label->set_text(String::format("%uK/%uK", page_count_to_kb(supervisor_pages_alloc), page_count_to_kb(supervisor_pages_available))); - m_kmalloc_count_label->set_text(String::format("%u/%u (+%u)", kmalloc_call_count, kfree_call_count, kmalloc_call_count - kfree_call_count)); + size_t kmalloc_sum_available = kmalloc_allocated + kmalloc_available; + size_t user_pages_available = user_physical_allocated + user_physical_available; + size_t supervisor_pages_available = super_physical_alloc + super_physical_free; - m_graph.set_max(page_count_to_kb(user_pages_available)); - m_graph.add_value(page_count_to_kb(user_pages_alloc)); - } + m_kmalloc_label->set_text(String::format("%uK/%uK", bytes_to_kb(kmalloc_allocated), bytes_to_kb(kmalloc_sum_available))); + m_user_physical_pages_label->set_text(String::format("%uK/%uK", page_count_to_kb(user_physical_allocated), page_count_to_kb(user_pages_available))); + m_supervisor_physical_pages_label->set_text(String::format("%uK/%uK", page_count_to_kb(super_physical_alloc), page_count_to_kb(supervisor_pages_available))); + m_kmalloc_count_label->set_text(String::format("%u/%u (+%u)", kmalloc_call_count, kfree_call_count, kmalloc_call_count - kfree_call_count)); + + m_graph.set_max(page_count_to_kb(user_pages_available)); + m_graph.add_value(page_count_to_kb(user_physical_allocated)); } void MemoryStatsWidget::timer_event(CTimerEvent&) diff --git a/Kernel/FileSystem/ProcFS.cpp b/Kernel/FileSystem/ProcFS.cpp index e38ccf10023..e5e1cc4e4ca 100644 --- a/Kernel/FileSystem/ProcFS.cpp +++ b/Kernel/FileSystem/ProcFS.cpp @@ -566,18 +566,17 @@ ByteBuffer procfs$summary(InodeIdentifier) ByteBuffer procfs$memstat(InodeIdentifier) { InterruptDisabler disabler; - StringBuilder builder(128); - builder.appendf("%u,%u,%u,%u,%u,%u,%u,%u,%u\n", - kmalloc_sum_eternal, - sum_alloc, - sum_free, - MM.user_physical_pages_used(), - MM.user_physical_pages() - MM.user_physical_pages_used(), - MM.super_physical_pages_used(), - MM.super_physical_pages() - MM.super_physical_pages_used(), - g_kmalloc_call_count, - g_kfree_call_count); - return builder.to_byte_buffer(); + JsonObject json; + json.set("kmalloc_allocated", sum_alloc); + json.set("kmalloc_available", sum_free); + json.set("kmalloc_eternal_allocated", kmalloc_sum_eternal); + json.set("user_physical_allocated", MM.user_physical_pages_used()); + json.set("user_physical_available", MM.user_physical_pages()); + json.set("super_physical_allocated", MM.super_physical_pages_used()); + json.set("super_physical_available", MM.super_physical_pages()); + json.set("kmalloc_call_count", g_kmalloc_call_count); + json.set("kfree_call_count", g_kfree_call_count); + return json.serialized().to_byte_buffer(); } ByteBuffer procfs$all(InodeIdentifier)