[gnome-system-monitor] Fix inaccurate %CPU values in the Processes table
- From: Benoît Dejean <bdejean src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-system-monitor] Fix inaccurate %CPU values in the Processes table
- Date: Tue, 31 Oct 2017 18:27:32 +0000 (UTC)
commit 9224515cd6b19ba2dc59afe14684749b4dbf0349
Author: Daniel van Vugt <daniel van vugt canonical com>
Date: Fri Oct 27 19:11:33 2017 +0800
Fix inaccurate %CPU values in the Processes table
Multi-core machines were displaying inaccurate %CPU values due to a
loss of precision from performing integer division before multiplication.
This changes the order of operations so that no precision is lost, and
now all machines will display process %CPU values to within 1% accuracy.
https://bugzilla.gnome.org/show_bug.cgi?id=788922
Signed-off-by: Benoît Dejean <bdejean gmail com>
src/proctable.cpp | 8 +++++---
1 files changed, 5 insertions(+), 3 deletions(-)
---
diff --git a/src/proctable.cpp b/src/proctable.cpp
index e41d6d0..c37a48b 100644
--- a/src/proctable.cpp
+++ b/src/proctable.cpp
@@ -917,11 +917,13 @@ update_info (GsmApplication *app, ProcInfo *info)
guint64 difference = proctime.rtime - info->cpu_time;
if (difference > 0)
info->status = GLIBTOP_PROCESS_RUNNING;
- info->pcpu = difference * 100 / app->cpu_total_time;
- info->pcpu = MIN(info->pcpu, 100);
+ guint cpu_scale = 100;
if (not app->config.solaris_mode)
- info->pcpu *= app->config.num_cpus;
+ cpu_scale *= app->config.num_cpus;
+
+ info->pcpu = difference * cpu_scale / app->cpu_total_time;
+ info->pcpu = MIN(info->pcpu, cpu_scale);
app->processes.cpu_times[info->pid] = info->cpu_time = proctime.rtime;
info->nice = procuid.nice;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]