LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 09-30-2012, 06:30 PM   #1
w1k0
Senior Member
 
Registered: May 2008
Location: Poland
Distribution: Slackware (personalized Window Maker), Mint (customized MATE)
Posts: 1,309

Rep: Reputation: 234Reputation: 234Reputation: 234
CPU usage – how to interpret it?


Some time ago I found the script by Paul Colby which displays the CPU usage (http://colby.id.au/node/39). I changed ‘sleep 1’ command near the end of the script to ‘sleep 3’ in order to align its results with the values reported by top. Then I observed that the mentioned script displays the CPU usage approximately 1.41 times higher than the CPU usage reported by top so I modified the script to divide the reported value by 1.41.

Some time later I configured conky to display the CPU usage with ‘$cpu’ entry and I observed that the displayed value is about 1.41 times higher than the value reported by top so I modified the conky output dividing the reported value by 1.41.

Next I started to wonder why two different tools (Paul Colby’s script and conky) display the CPU usage that differs from the CPU usage reported by top 1.41 times. Maybe these two values are correct and top displays an invalid value? Or all these values are right but I interpret them in a wrong way?

Every assistance will be appreciated.
 
Old 09-30-2012, 08:46 PM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,126

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
"idle" time is not the only "non-using" time. See "man proc" for the stat entry.
Are you seeing large %wa numbers ?. Are you running these commands on a (virtualised) guest ?.
 
Old 09-30-2012, 10:15 PM   #3
w1k0
Senior Member
 
Registered: May 2008
Location: Poland
Distribution: Slackware (personalized Window Maker), Mint (customized MATE)
Posts: 1,309

Original Poster
Rep: Reputation: 234Reputation: 234Reputation: 234
In my system wa reported by top is usually equal 0.0% and I don’t use a virtual machine. I read man proc but it doesn’t reply to my question (or I can’t interpret that in the right way).
 
Old 09-30-2012, 10:54 PM   #4
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,126

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Over-clocked ?.
 
Old 10-01-2012, 02:06 AM   #5
JaseP
Senior Member
 
Registered: Jun 2002
Location: Eastern PA, USA
Distribution: K/Ubuntu 18.04-14.04, Scientific Linux 6.3-6.4, Android-x86, Pretty much all distros at one point...
Posts: 1,802

Rep: Reputation: 157Reputation: 157
It's well established that top and ps, calculate CPU usage pretty well differently,... so why would this script, using /proc/stat be any different???

PS: Think "time slices," and "averages." If you explore it from that perspective, I think you'll discover your answer... Oh,... and please post what you find,... I want to know if what I believe to be the answer is, in fact, right...

Last edited by JaseP; 10-01-2012 at 02:11 AM.
 
Old 10-01-2012, 08:26 AM   #6
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
Indeed ... the algorithms are different, and each set of numbers is meant to be compared only with itself. Otherwise you are comparing apples to oranges.

CPU metrics have two somewhat-conflicting goals:
  • They must "instantaneously" provide a useful figure that nevertheless considers more than just one instant in time.
  • They must not consume a significant amount of CPU time in the doing of it. ("The presence of the experimenter should exercise little or no influence upon the experiment," etc.)
The word "useful" is key, in the sense that it needs to be a fair metric that will allow you (or a computer algorithm) to make appropriate judgments and/or adjustments when using it. What it does not need to do, however, is to be directly comparable to, or against, some other algorithm. The two sets of metrics can be reasonably expected to more-or-less track one another, but to some degree they also provide complementary viewpoints.

Last edited by sundialsvcs; 10-01-2012 at 08:28 AM.
 
Old 10-01-2012, 10:19 PM   #7
w1k0
Senior Member
 
Registered: May 2008
Location: Poland
Distribution: Slackware (personalized Window Maker), Mint (customized MATE)
Posts: 1,309

Original Poster
Rep: Reputation: 234Reputation: 234Reputation: 234
Quote:
Originally Posted by syg00 View Post
Over-clocked ?.
Nope.

Quote:
Originally Posted by JaseP View Post
It's well established that top and ps, calculate CPU usage pretty well differently,... so why would this script, using /proc/stat be any different???
I was amazed that two different tools – the script mentioned in the first post and conky – display the CPU usage which is in both cases 1.41 times higher than the CPU usage reported by top. At the beginning I relied on the values displayed by top so I customized the script by Paul Colby to take into consideration the 1.41 divisor. Then I did the same with the conky output. Finally I started to wonder which value is: 1) closer to the real CPU usage 2) or more reliable that is based on the better algorithm, 3) or closer to the mean value reported by different reliable tools.

Quote:
PS: Think "time slices," and "averages." If you explore it from that perspective, I think you'll discover your answer...
The programs such as the script by Paul Colby or top tell nothing about the preemption (“time slices”) – I can’t guess on the basis of the output of these programs when the scheduler interrupted the task. Even guessing that by chance gives me nothing.

The average calculated on the basis of the unreliable values isn’t reliable. The problem is: I don’t know which values are more and which are less reliable. That’s the essence of my question from the first post.

Quote:
Originally Posted by sundialsvcs View Post
Indeed ... the algorithms are different, and each set of numbers is meant to be compared only with itself. Otherwise you are comparing apples to oranges.
But I can say: “There’s “05:15:31 CEST now” and you can calculate the time when I wrote the present sentence. So we can compare the time but we can’t compare the CPUs?

Quote:
The word "useful" is key, in the sense that it needs to be a fair metric that will allow you (or a computer algorithm) to make appropriate judgments and/or adjustments when using it. What it does not need to do, however, is to be directly comparable to, or against, some other algorithm. The two sets of metrics can be reasonably expected to more-or-less track one another, but to some degree they also provide complementary viewpoints.
So I can choose the values which I like more? I prefer of course the lower ones. So I’ll keep my 1.41 divisors in order to align the values reported by the script by Paul Colby and conky to the values reported by top.
 
Old 10-02-2012, 03:52 AM   #8
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,126

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
I realise this has been "solved", but a final comment (from me).
The "top vs. ps" thing is a "straw man" in this context. The script referenced produces numbers (very) similar to top on this i7 laptop - even under (artificially) high CPU loads. As one might expect in normal usage.
I have a feeling top corrects for CPU frequency, hence my question about over-clocking.

No answer for you here I'm afraid.
 
1 members found this post helpful.
Old 10-02-2012, 04:20 PM   #9
w1k0
Senior Member
 
Registered: May 2008
Location: Poland
Distribution: Slackware (personalized Window Maker), Mint (customized MATE)
Posts: 1,309

Original Poster
Rep: Reputation: 234Reputation: 234Reputation: 234
syg00,

Quote:
Originally Posted by syg00 View Post
No answer for you here I'm afraid.
In fact your answer is the best one so far.

Assuming that on some machines like your i7 laptop the results reported by the script and top are similar it’s reasonable to include in my version of the script the optional coefficient allowing the user to include the correction.

Quote:
I realise this has been "solved", but a final comment (from me).
I marked the thread as solved because it inclined to go towards the philosophical investigations while my question was purely practical.

My former thread in the Programming section had 18 posts before I marked it as solved and gained so far 81 posts after I did it (the total is 100 posts). The problem I asked was so appealing to a few programmers that four of them wrote 12 versions of the same program in 5 languages. The record holder wrote so far 7 versions of that program using 4 languages.

The bottom line is: the thread can be marked as solved while the problem is still unsolved or inspiring.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] High CPU load, but low CPU usage (high idle CPU) baffy Linux - Newbie 5 03-13-2013 09:24 AM
processes/CPU Usage/Mem Usage desktop wallpaper ceantuco Linux - Newbie 2 04-13-2009 01:14 PM
getting realtime info on memory usage-cpu and harddrive usage steering Linux - Newbie 5 03-03-2005 08:43 PM
how to determine cpu usage, memory usage, I/O usage by a particular user logged on li rags2k Programming 4 08-21-2004 04:45 AM
Controlling CPU usage & memory usage Saravana babu Linux - Software 0 02-18-2004 05:55 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 10:47 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration