mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:17:34 +00:00
WindowServer: Let the CPU monitor keep /proc/all open between refreshes.
Just seek to the beginning on every iteration and start over. This avoids a bunch of syscalls.
This commit is contained in:
parent
30b0e5f82e
commit
bc6ac1c2f2
2 changed files with 7 additions and 4 deletions
|
@ -31,14 +31,15 @@ void WSCPUMonitor::get_cpu_usage(unsigned& busy, unsigned& idle)
|
||||||
busy = 0;
|
busy = 0;
|
||||||
idle = 0;
|
idle = 0;
|
||||||
|
|
||||||
FILE* fp = fopen("/proc/all", "r");
|
if (!m_fp)
|
||||||
if (!fp) {
|
m_fp = fopen("/proc/all", "r");
|
||||||
|
if (!m_fp) {
|
||||||
perror("failed to open /proc/all");
|
perror("failed to open /proc/all");
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
}
|
}
|
||||||
for (;;) {
|
for (;;) {
|
||||||
char buf[BUFSIZ];
|
char buf[BUFSIZ];
|
||||||
char* ptr = fgets(buf, sizeof(buf), fp);
|
char* ptr = fgets(buf, sizeof(buf), m_fp);
|
||||||
if (!ptr)
|
if (!ptr)
|
||||||
break;
|
break;
|
||||||
auto parts = String(buf, Chomp).split(',');
|
auto parts = String(buf, Chomp).split(',');
|
||||||
|
@ -55,7 +56,7 @@ void WSCPUMonitor::get_cpu_usage(unsigned& busy, unsigned& idle)
|
||||||
else
|
else
|
||||||
busy += nsched;
|
busy += nsched;
|
||||||
}
|
}
|
||||||
int rc = fclose(fp);
|
int rc = fseek(m_fp, 0, SEEK_SET);
|
||||||
ASSERT(rc == 0);
|
ASSERT(rc == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/CircularQueue.h>
|
#include <AK/CircularQueue.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
class Painter;
|
class Painter;
|
||||||
class Rect;
|
class Rect;
|
||||||
|
@ -18,5 +19,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 };
|
||||||
bool m_dirty { false };
|
bool m_dirty { false };
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue