mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:47:44 +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/JsonArray.h>
|
||||||
#include <AK/JsonObject.h>
|
#include <AK/JsonObject.h>
|
||||||
#include <AK/JsonValue.h>
|
#include <AK/JsonValue.h>
|
||||||
|
#include <LibCore/CProcessStatisticsReader.h>
|
||||||
#include <WindowServer/WSCPUMonitor.h>
|
#include <WindowServer/WSCPUMonitor.h>
|
||||||
#include <WindowServer/WSEventLoop.h>
|
#include <WindowServer/WSEventLoop.h>
|
||||||
#include <WindowServer/WSWindowManager.h>
|
#include <WindowServer/WSWindowManager.h>
|
||||||
|
@ -8,11 +9,7 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
WSCPUMonitor::WSCPUMonitor()
|
WSCPUMonitor::WSCPUMonitor()
|
||||||
: m_proc_all("/proc/all")
|
|
||||||
{
|
{
|
||||||
if (!m_proc_all.open(CIODevice::OpenMode::ReadOnly))
|
|
||||||
ASSERT_NOT_REACHED();
|
|
||||||
|
|
||||||
create_thread([](void* context) -> int {
|
create_thread([](void* context) -> int {
|
||||||
auto& monitor = *(WSCPUMonitor*)context;
|
auto& monitor = *(WSCPUMonitor*)context;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
@ -39,18 +36,14 @@ void WSCPUMonitor::get_cpu_usage(unsigned& busy, unsigned& idle)
|
||||||
busy = 0;
|
busy = 0;
|
||||||
idle = 0;
|
idle = 0;
|
||||||
|
|
||||||
m_proc_all.seek(0);
|
auto all_processes = CProcessStatisticsReader::get_all();
|
||||||
auto file_contents = m_proc_all.read_all();
|
|
||||||
auto json = JsonValue::from_string({ file_contents.data(), file_contents.size() });
|
for (auto& it : all_processes) {
|
||||||
json.as_array().for_each([&](auto& value) {
|
if (it.value.pid == 0)
|
||||||
const JsonObject& process_object = value.as_object();
|
idle += it.value.nsched;
|
||||||
pid_t pid = process_object.get("pid").to_u32();
|
|
||||||
unsigned nsched = process_object.get("times_scheduled").to_u32();
|
|
||||||
if (pid == 0)
|
|
||||||
idle += nsched;
|
|
||||||
else
|
else
|
||||||
busy += nsched;
|
busy += it.value.nsched;
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WSCPUMonitor::paint(Painter& painter, const Rect& rect)
|
void WSCPUMonitor::paint(Painter& painter, const Rect& rect)
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/CircularQueue.h>
|
#include <AK/CircularQueue.h>
|
||||||
#include <LibCore/CFile.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
class Painter;
|
class Painter;
|
||||||
|
@ -20,6 +19,5 @@ private:
|
||||||
void get_cpu_usage(unsigned& busy, unsigned& idle);
|
void get_cpu_usage(unsigned& busy, unsigned& idle);
|
||||||
|
|
||||||
CircularQueue<float, 30> m_cpu_history;
|
CircularQueue<float, 30> m_cpu_history;
|
||||||
CFile m_proc_all;
|
|
||||||
bool m_dirty { false };
|
bool m_dirty { false };
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue