From 2e9fcc17a0480e005c91c2e3a6c9dc2f328b2cc1 Mon Sep 17 00:00:00 2001 From: Michal Grich Date: Fri, 21 Jul 2023 22:21:39 +0200 Subject: [PATCH] SystemMonitor: Fix calculation of CPU percentage This commit addresses an issue when 'Zombie' threads are included in CPU % calculation. This caused negative time_scheduled_diff, resulting in a data type overflow. --- Userland/Applications/SystemMonitor/ProcessModel.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Userland/Applications/SystemMonitor/ProcessModel.cpp b/Userland/Applications/SystemMonitor/ProcessModel.cpp index 3498a6be68..8c812100cb 100644 --- a/Userland/Applications/SystemMonitor/ProcessModel.cpp +++ b/Userland/Applications/SystemMonitor/ProcessModel.cpp @@ -574,6 +574,9 @@ void ProcessModel::update() tids_to_remove.append(it.key); continue; } + if (it.value->current_state.state == "Zombie") { + continue; + } auto& thread = *it.value; u64 time_scheduled_diff = (thread.current_state.time_user + thread.current_state.time_kernel) - (thread.previous_state.time_user + thread.previous_state.time_kernel);