diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-04-15 23:57:31 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-04-15 23:57:31 +0200 |
commit | bc6ac1c2f2a63292106f05b1a92460fa7257b5dd (patch) | |
tree | 1644dce81b5e8e072fe8afbd9515c1f513d828f7 /Servers | |
parent | 30b0e5f82ee72ee78b202506b4e12f7992af270d (diff) | |
download | serenity-bc6ac1c2f2a63292106f05b1a92460fa7257b5dd.zip |
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.
Diffstat (limited to 'Servers')
-rw-r--r-- | Servers/WindowServer/WSCPUMonitor.cpp | 9 | ||||
-rw-r--r-- | Servers/WindowServer/WSCPUMonitor.h | 2 |
2 files changed, 7 insertions, 4 deletions
diff --git a/Servers/WindowServer/WSCPUMonitor.cpp b/Servers/WindowServer/WSCPUMonitor.cpp index ea45ac4b70..c00fb2edaf 100644 --- a/Servers/WindowServer/WSCPUMonitor.cpp +++ b/Servers/WindowServer/WSCPUMonitor.cpp @@ -31,14 +31,15 @@ void WSCPUMonitor::get_cpu_usage(unsigned& busy, unsigned& idle) busy = 0; idle = 0; - FILE* fp = fopen("/proc/all", "r"); - if (!fp) { + if (!m_fp) + m_fp = fopen("/proc/all", "r"); + if (!m_fp) { perror("failed to open /proc/all"); ASSERT_NOT_REACHED(); } for (;;) { char buf[BUFSIZ]; - char* ptr = fgets(buf, sizeof(buf), fp); + char* ptr = fgets(buf, sizeof(buf), m_fp); if (!ptr) break; auto parts = String(buf, Chomp).split(','); @@ -55,7 +56,7 @@ void WSCPUMonitor::get_cpu_usage(unsigned& busy, unsigned& idle) else busy += nsched; } - int rc = fclose(fp); + int rc = fseek(m_fp, 0, SEEK_SET); ASSERT(rc == 0); } diff --git a/Servers/WindowServer/WSCPUMonitor.h b/Servers/WindowServer/WSCPUMonitor.h index c2e57968a5..fe2ea5ee64 100644 --- a/Servers/WindowServer/WSCPUMonitor.h +++ b/Servers/WindowServer/WSCPUMonitor.h @@ -1,6 +1,7 @@ #pragma once #include <AK/CircularQueue.h> +#include <stdio.h> class Painter; class Rect; @@ -18,5 +19,6 @@ private: void get_cpu_usage(unsigned& busy, unsigned& idle); CircularQueue<float, 30> m_cpu_history; + FILE* m_fp { nullptr }; bool m_dirty { false }; }; |