SystemMonitor: Don't reopen process statistics file on every update

This file can just remain open; we seek to its start anyways.
This previously accounted for over 5% of SystemMonitor runtime.
This commit is contained in:
kleines Filmröllchen 2023-06-24 14:41:13 +02:00 committed by Linus Groh
parent 26d8ac844c
commit 7d53767ce8
Notes: sideshowbarker 2024-07-16 23:08:48 +09:00
2 changed files with 20 additions and 1 deletions

View File

@ -440,10 +440,25 @@ static DeprecatedString read_command_line(pid_t pid)
return string_or_error.release_value();
}
ErrorOr<void> ProcessModel::initialize_process_statistics_file()
{
if (!m_process_statistics_file || !m_process_statistics_file->is_open())
m_process_statistics_file = TRY(Core::File::open("/sys/kernel/processes"sv, Core::File::OpenMode::Read));
return {};
}
void ProcessModel::update()
{
auto result = initialize_process_statistics_file();
if (result.is_error()) {
dbgln("Process model couldn't be updated: {}", result.release_error());
return;
}
auto all_processes = Core::ProcessStatisticsReader::get_all(*m_process_statistics_file, true);
auto previous_tid_count = m_threads.size();
auto all_processes = Core::ProcessStatisticsReader::get_all(true);
HashTable<int> live_tids;
u64 total_time_scheduled_diff = 0;

View File

@ -240,6 +240,10 @@ private:
int thread_model_row(Thread const& thread) const;
ErrorOr<void> initialize_process_statistics_file();
OwnPtr<Core::File> m_process_statistics_file;
// The thread list contains the same threads as the Process structs.
HashMap<int, NonnullRefPtr<Thread>> m_threads;
Vector<NonnullOwnPtr<Process>> m_processes;