mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:17:34 +00:00
WindowServer: Use CFile in the CPU monitor code.
This commit is contained in:
parent
34087a9f90
commit
c4c7f224d5
2 changed files with 10 additions and 13 deletions
|
@ -5,7 +5,11 @@
|
||||||
#include <stdio.h>
|
#include <stdio.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 (;;) {
|
||||||
|
@ -31,18 +35,12 @@ void WSCPUMonitor::get_cpu_usage(unsigned& busy, unsigned& idle)
|
||||||
busy = 0;
|
busy = 0;
|
||||||
idle = 0;
|
idle = 0;
|
||||||
|
|
||||||
if (!m_fp)
|
m_proc_all.seek(0);
|
||||||
m_fp = fopen("/proc/all", "r");
|
|
||||||
if (!m_fp) {
|
|
||||||
perror("failed to open /proc/all");
|
|
||||||
ASSERT_NOT_REACHED();
|
|
||||||
}
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
char buf[BUFSIZ];
|
auto line = m_proc_all.read_line(BUFSIZ);
|
||||||
char* ptr = fgets(buf, sizeof(buf), m_fp);
|
if (line.is_null())
|
||||||
if (!ptr)
|
|
||||||
break;
|
break;
|
||||||
auto parts = String(buf, Chomp).split(',');
|
auto parts = String::from_byte_buffer(line).split(',');
|
||||||
if (parts.size() < 17)
|
if (parts.size() < 17)
|
||||||
break;
|
break;
|
||||||
bool ok;
|
bool ok;
|
||||||
|
@ -56,8 +54,6 @@ void WSCPUMonitor::get_cpu_usage(unsigned& busy, unsigned& idle)
|
||||||
else
|
else
|
||||||
busy += nsched;
|
busy += nsched;
|
||||||
}
|
}
|
||||||
int rc = fseek(m_fp, 0, SEEK_SET);
|
|
||||||
ASSERT(rc == 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WSCPUMonitor::paint(Painter& painter, const Rect& rect)
|
void WSCPUMonitor::paint(Painter& painter, const Rect& rect)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#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;
|
||||||
|
@ -19,6 +20,6 @@ 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;
|
||||||
FILE* m_fp { nullptr };
|
CFile m_proc_all;
|
||||||
bool m_dirty { false };
|
bool m_dirty { false };
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue