1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 19:37:35 +00:00

SystemMonitor: Prefer Core::File, poll ProcessStatisticsReader correctly

The signature of Core::ProcessStatisticsReader::get_all changed, and
instead of requiring a pointer to an open file, it now needs a bool to
indicate whether usernames should be polled or not. `m_proc_all` was
always converted to `false` in `RefPtr::operator bool()`, so we were
missing usernames for a long time.
This commit is contained in:
Ben Wiederhake 2023-05-13 14:52:21 +02:00 committed by Andreas Kling
parent 07b6fb9104
commit b23a0b409d
2 changed files with 13 additions and 13 deletions

View file

@ -10,7 +10,6 @@
#include <AK/JsonValue.h> #include <AK/JsonValue.h>
#include <AK/NonnullRefPtr.h> #include <AK/NonnullRefPtr.h>
#include <AK/NumberFormat.h> #include <AK/NumberFormat.h>
#include <LibCore/DeprecatedFile.h>
#include <LibCore/ProcessStatisticsReader.h> #include <LibCore/ProcessStatisticsReader.h>
#include <LibGUI/FileIconProvider.h> #include <LibGUI/FileIconProvider.h>
#include <LibGUI/Icon.h> #include <LibGUI/Icon.h>
@ -31,16 +30,18 @@ ProcessModel::ProcessModel()
VERIFY(!s_the); VERIFY(!s_the);
s_the = this; s_the = this;
auto file = Core::DeprecatedFile::construct("/sys/kernel/cpuinfo"); auto file_or_error = Core::File::open("/sys/kernel/cpuinfo"sv, Core::File::OpenMode::Read);
if (file->open(Core::OpenMode::ReadOnly)) { if (!file_or_error.is_error()) {
auto buffer = file->read_all(); auto buffer_or_error = file_or_error.value()->read_until_eof();
auto json = JsonValue::from_string({ buffer }); if (!buffer_or_error.is_error()) {
auto cpuinfo_array = json.value().as_array(); auto json = JsonValue::from_string({ buffer_or_error.value() });
cpuinfo_array.for_each([&](auto& value) { auto cpuinfo_array = json.value().as_array();
auto& cpu_object = value.as_object(); cpuinfo_array.for_each([&](auto& value) {
auto cpu_id = cpu_object.get_u32("processor"sv).value(); auto& cpu_object = value.as_object();
m_cpus.append(make<CpuInfo>(cpu_id)); auto cpu_id = cpu_object.get_u32("processor"sv).value();
}); m_cpus.append(make<CpuInfo>(cpu_id));
});
}
} }
if (m_cpus.is_empty()) if (m_cpus.is_empty())
@ -442,7 +443,7 @@ static DeprecatedString read_command_line(pid_t pid)
void ProcessModel::update() void ProcessModel::update()
{ {
auto previous_tid_count = m_threads.size(); auto previous_tid_count = m_threads.size();
auto all_processes = Core::ProcessStatisticsReader::get_all(m_proc_all); auto all_processes = Core::ProcessStatisticsReader::get_all(true);
HashTable<int> live_tids; HashTable<int> live_tids;
u64 total_time_scheduled_diff = 0; u64 total_time_scheduled_diff = 0;

View file

@ -244,7 +244,6 @@ private:
HashMap<int, NonnullRefPtr<Thread>> m_threads; HashMap<int, NonnullRefPtr<Thread>> m_threads;
Vector<NonnullOwnPtr<Process>> m_processes; Vector<NonnullOwnPtr<Process>> m_processes;
Vector<NonnullOwnPtr<CpuInfo>> m_cpus; Vector<NonnullOwnPtr<CpuInfo>> m_cpus;
RefPtr<Core::DeprecatedFile> m_proc_all;
GUI::Icon m_kernel_process_icon; GUI::Icon m_kernel_process_icon;
u64 m_total_time_scheduled { 0 }; u64 m_total_time_scheduled { 0 };
u64 m_total_time_scheduled_kernel { 0 }; u64 m_total_time_scheduled_kernel { 0 };