diff --git a/Servers/WindowServer/WSCPUMonitor.cpp b/Servers/WindowServer/WSCPUMonitor.cpp index 1c6783897b..5554a9493a 100644 --- a/Servers/WindowServer/WSCPUMonitor.cpp +++ b/Servers/WindowServer/WSCPUMonitor.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -8,11 +9,7 @@ #include WSCPUMonitor::WSCPUMonitor() - : m_proc_all("/proc/all") { - if (!m_proc_all.open(CIODevice::OpenMode::ReadOnly)) - ASSERT_NOT_REACHED(); - create_thread([](void* context) -> int { auto& monitor = *(WSCPUMonitor*)context; for (;;) { @@ -39,18 +36,14 @@ void WSCPUMonitor::get_cpu_usage(unsigned& busy, unsigned& idle) busy = 0; idle = 0; - m_proc_all.seek(0); - auto file_contents = m_proc_all.read_all(); - auto json = JsonValue::from_string({ file_contents.data(), file_contents.size() }); - json.as_array().for_each([&](auto& value) { - const JsonObject& process_object = value.as_object(); - pid_t pid = process_object.get("pid").to_u32(); - unsigned nsched = process_object.get("times_scheduled").to_u32(); - if (pid == 0) - idle += nsched; + auto all_processes = CProcessStatisticsReader::get_all(); + + for (auto& it : all_processes) { + if (it.value.pid == 0) + idle += it.value.nsched; else - busy += nsched; - }); + busy += it.value.nsched; + } } void WSCPUMonitor::paint(Painter& painter, const Rect& rect) diff --git a/Servers/WindowServer/WSCPUMonitor.h b/Servers/WindowServer/WSCPUMonitor.h index e850029638..2a87bc1e90 100644 --- a/Servers/WindowServer/WSCPUMonitor.h +++ b/Servers/WindowServer/WSCPUMonitor.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include class Painter; @@ -20,6 +19,5 @@ private: void get_cpu_usage(unsigned& busy, unsigned& idle); CircularQueue m_cpu_history; - CFile m_proc_all; bool m_dirty { false }; };