1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 04:48:14 +00:00

ProcessManager: Keep /proc/all open to reduce CPU impact of ProcessManager.

This commit is contained in:
Andreas Kling 2019-05-14 17:12:35 +02:00
parent 2e0d8ee98f
commit 2fa5e2b66b
2 changed files with 10 additions and 7 deletions

View file

@ -7,7 +7,13 @@
ProcessModel::ProcessModel(GraphWidget& graph) ProcessModel::ProcessModel(GraphWidget& graph)
: m_graph(graph) : m_graph(graph)
, m_proc_all("/proc/all")
{ {
if (!m_proc_all.open(CIODevice::ReadOnly)) {
fprintf(stderr, "ProcessManager: Failed to open /proc/all: %s\n", m_proc_all.error_string());
exit(1);
}
setpwent(); setpwent();
while (auto* passwd = getpwent()) while (auto* passwd = getpwent())
m_usernames.set(passwd->pw_uid, passwd->pw_name); m_usernames.set(passwd->pw_uid, passwd->pw_name);
@ -137,12 +143,7 @@ GVariant ProcessModel::data(const GModelIndex& index, Role role) const
void ProcessModel::update() void ProcessModel::update()
{ {
CFile file("/proc/all"); m_proc_all.seek(0);
if (!file.open(CIODevice::ReadOnly)) {
fprintf(stderr, "ProcessManager: Failed to open /proc/all: %s\n", file.error_string());
exit(1);
return;
}
unsigned last_sum_nsched = 0; unsigned last_sum_nsched = 0;
for (auto& it : m_processes) for (auto& it : m_processes)
@ -151,7 +152,7 @@ void ProcessModel::update()
HashTable<pid_t> live_pids; HashTable<pid_t> live_pids;
unsigned sum_nsched = 0; unsigned sum_nsched = 0;
for (;;) { for (;;) {
auto line = file.read_line(1024); auto line = m_proc_all.read_line(1024);
if (line.is_empty()) if (line.is_empty())
break; break;
auto chomped = String((const char*)line.pointer(), line.size() - 1, Chomp); auto chomped = String((const char*)line.pointer(), line.size() - 1, Chomp);

View file

@ -4,6 +4,7 @@
#include <AK/HashMap.h> #include <AK/HashMap.h>
#include <AK/Vector.h> #include <AK/Vector.h>
#include <LibGUI/GModel.h> #include <LibGUI/GModel.h>
#include <LibCore/CFile.h>
#include <unistd.h> #include <unistd.h>
class GraphWidget; class GraphWidget;
@ -64,4 +65,5 @@ private:
RetainPtr<GraphicsBitmap> m_high_priority_icon; RetainPtr<GraphicsBitmap> m_high_priority_icon;
RetainPtr<GraphicsBitmap> m_low_priority_icon; RetainPtr<GraphicsBitmap> m_low_priority_icon;
RetainPtr<GraphicsBitmap> m_normal_priority_icon; RetainPtr<GraphicsBitmap> m_normal_priority_icon;
CFile m_proc_all;
}; };