LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 08-31-2009, 06:08 PM   #1
texas_danrob
LQ Newbie
 
Registered: Aug 2009
Location: Austin TX
Posts: 2

Rep: Reputation: 0
top utility: initial display shows incorrect CPU utilization data


Distros:
Redhat (2.6.18-128.2.1.el5 #1 SMP Wed Jul 8 11:54:47 EDT 2009 x86_64 x86_64 x86_64 GNU/Linux)
Ubuntu (2.6.24-24-386 #1 Tue Aug 18 16:24:26 UTC 2009 i686 GNU/Linux)

When I run 'top' in batch mode (specifying 1 iteration), the CPU % idle (%id) value is always the same and not accurate. Even when in interactive mode, the initial data display has incorrect CPU %id data. In interactive mode, the CPU %id value gets updated and by the third or fourth iteration, it looks to be accurate.

I installed the sysstat package on both systems. Using 'mpstat', the CPU utilization percentages don't match what 'top' displays in interactive mode. I can have two shells side-by-side, one with top in interactive mode and one running 'watch -n 3 mpstat'. They are both updating every 3 seconds, but the CPU utilization data is different for each.

Why is the first CPU utilization displayed by 'top' inaccurate?
Between 'top' and 'mpstat', which is most accurate/reliable?
Is there a better utility to fetch CPU utilization data?
Is there a reasonable way for me to calc my own CPU utilization data from /proc/stat?
 
Old 08-31-2009, 07:44 PM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 20,836

Rep: Reputation: 4008Reputation: 4008Reputation: 4008Reputation: 4008Reputation: 4008Reputation: 4008Reputation: 4008Reputation: 4008Reputation: 4008Reputation: 4008Reputation: 4008
Because a number doesn't look like what you want it to doesn't make it inaccurate. /proc/stat maintains numbers since last boot - by definition the first interval is ...
Sampled data on a non-idle machine (below 100%) is unlikely to be consistent.

I like sysstat due to the history data it affords - top also has its place, but is a bit "heavy", and tends to affect the numbers itself on lightly loaded machines.
Re-reading /proc/stat and determining the difference over the interval will allow you to write your own - same as everyone else does it.
 
Old 09-01-2009, 08:25 AM   #3
texas_danrob
LQ Newbie
 
Registered: Aug 2009
Location: Austin TX
Posts: 2

Original Poster
Rep: Reputation: 0
Thanks for the info. I'm actually looking for real-time CPU utilization data. Do both 'top' and 'mpstat' report an average over time?
 
Old 09-01-2009, 08:34 AM   #4
karamarisan
Member
 
Registered: Jul 2009
Location: Illinois, US
Distribution: Fedora 11
Posts: 374

Rep: Reputation: 55
Yep, because that's the only thing that makes sense. What do you want, three billion reports a second on what each processor just did?

If you find existing tools insufficient, look into /proc/stat as syg00 suggested. That's the raw data, straight out of the kernel. It doesn't get more precise than that.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
sar output shows different CPU utilization.. vikas027 Linux - Server 2 07-16-2009 10:58 PM
top, ps, sar which gives accurate data for CPU utilization makam.sreekanth Linux - Newbie 6 03-20-2009 09:39 AM
/proc/cpuinfo shows incorrect CPU frequency, even under load pwc101 Debian 1 07-31-2008 07:54 AM
top shows 150% cpu load crashmeister Linux - General 3 02-02-2008 08:18 AM
high cpu utilization 'top' analysis saarb16 Linux - General 2 03-09-2006 09:58 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:06 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