CPU Usage: Why ‘top’ Numbers Differ from System Monitor and Conky

conkycpucpu usagememorytop

When my laptop gets slow for a moment during somewhat heavier processing I expect to see higher numbers (for CPU use) than what I in fact see in the conky Process Panel that I have on the desktop and in the System Monitor.

Using top in terminal I see numbers that justify that momentary slowness of the computer. For example, while Firefox is running with some addons that use relatively high CPU resources (displayed as "Web Content") the conky script (just like Gnome System Monitor) shows around 25% of CPU resources used, while top shows around 71%, which seems more "real" given the fact that the PC has indeed become slow.

enter image description here

How could I get those "real" numbers in the conky I use? And why is top different from that and from the System Monitor?

The part of the conky script that is significant here is this:

${top name 1} $alignr ${top cpu 1}%
${top name 2} $alignr ${top cpu 2}%
${top name 3} $alignr ${top cpu 3}%

etc.

Best Answer

This is because top is showing the value as a percentage of a single CPU core, while conky is showing the percentage of total available CPU power. If you run top and press I you should see the same (almost the same, there will always be a race condition: the time that top polls the CPU won't be the exact same time that conky does) numbers.

This is documented in man top (emphasis mine):

  1. %CPU -- CPU Usage

    The task's share of the elapsed CPU time since the last screen update, expressed as a percentage of total CPU time.

    In a true SMP environment, if a process is multi-threaded and top is not operating in Threads mode, amounts greater than 100% may be reported. You toggle Threads mode with the `H' interactive command.

    Also for multi-processor environments, if Irix mode is Off, top will operate in Solaris mode where a task's cpu usage will be divided by the total number of CPUs. You toggle Irix/Solaris modes with the `I' interactive command.

So, what you are seeing in your example is that top is in Irix mode and reporting the %CPU value as a percentage of a single CPU, while conky is reporting it as a percentage of all available CPUs.

And, just to illustrate, this is what top looks like in Irix mode on my 8-core laptop when running pigz which can use multiple threads:

PID     USER      PR  NI    VIRT    RES  %CPU  %MEM     TIME+ S COMMAND                                                               
1090509 terdon    20   0  657.6m   4.5m 605.3   0.0   0:33.18 R pigz                                                                  

See how the %CPU is well above 100? Now, the same thing in Solaris mode, shows:

PID     USER      PR  NI    VIRT    RES  %CPU  %MEM     TIME+ S COMMAND                                                               
1100171 terdon    20   0  657.6m   4.5m  82.0   0.0   1:24.08 S pigz                                                                  

The numbers don't match exactly since I ran the command twice to get the output, but you should be able to see the genera idea.

Related Question