Commit 9224515c authored by Daniel van Vugt's avatar Daniel van Vugt Committed by Ben

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. Ben's avatarBenoît Dejean <>
parent 2003a54b
......@@ -917,11 +917,13 @@ update_info (GsmApplication *app, ProcInfo *info)
guint64 difference = proctime.rtime - info->cpu_time;
if (difference > 0)
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;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment