mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 14:38:11 +00:00
WindowServer: Use CProcessStatisticsReader in WSCPUMonitor.
This commit is contained in:
parent
ea6363c540
commit
64d9b43734
2 changed files with 8 additions and 17 deletions
|
@ -1,6 +1,7 @@
|
|||
#include <AK/JsonArray.h>
|
||||
#include <AK/JsonObject.h>
|
||||
#include <AK/JsonValue.h>
|
||||
#include <LibCore/CProcessStatisticsReader.h>
|
||||
#include <WindowServer/WSCPUMonitor.h>
|
||||
#include <WindowServer/WSEventLoop.h>
|
||||
#include <WindowServer/WSWindowManager.h>
|
||||
|
@ -8,11 +9,7 @@
|
|||
#include <unistd.h>
|
||||
|
||||
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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue