mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-21 10:19:03 +03:00
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:
parent
26d8ac844c
commit
7d53767ce8
Notes:
sideshowbarker
2024-07-16 23:08:48 +09:00
Author: https://github.com/kleinesfilmroellchen Commit: https://github.com/SerenityOS/serenity/commit/7d53767ce8 Pull-request: https://github.com/SerenityOS/serenity/pull/19606 Reviewed-by: https://github.com/linusg
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user