Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Mac OS X > Reduce CPU usage of 'top' (awesome tip) .

Reduce CPU usage of 'top' (awesome tip) .
Thread Tools
Mac Elite
Join Date: Feb 2001
Location: Canaduh
Status: Offline
Reply With Quote
Feb 20, 2004, 02:47 PM
 
This tip was posted at MacOSXHints.com today.

Dramatically reduce the CPU usage of 'top'
_Fri, Feb 20 '04 at 10:09AM • from: axello

I always use the venerable top program in the Terminal to see which program is hogging the CPU. Unfortunately, most of the time it is top itself. Even on a fast 1 GHz dual-processor G4, top can take 20% of the CPU time. On FreeBSD, this is often less than 0.1%. I thought Apple would fix this in subsequent releases of Mac OS X, but I was wrong. It is probably something deeply rooted in the Darwin memory management core that prevents top from being fast, lean and mean.

I am mostly interested in CPU hogs, not in memory usage. Also I always sort on CPU usage, the default behaviour on other OSes. So I made a little shell script to make top use 5 to 10 times fewer CPU cycles. It basically removes all the memory checks from top, so you cannot use it to see how much memory a program occupies, or how much RAM you have left. Use the plain old top for that. This is what I use:

/usr/bin/top -ocpu -R -F -s 2 -n30

It sorts on CPU, it doesn't 'traverse the memory object map,' (a huge time saver), it doesn't calculate library statistics, it only redraws every other second and shows only the first 30 programs. You can put this line in a script called top in your ~/bin/ directory, or make it into an alias. Don't forget to rehash to make it work!

[robg adds: I created it as an alias (in tcsh) by adding

alias ttop 'top -ocpu -R -F -s 2 -n30'

(ttop can be whatever you like, of course) to my .tcshrc file, so I can run both versions easily. Even on my Dual G5, top is a CPU hog -- it takes about 10% - 15% of the CPU; using these command line switches, it's down around 1%.]
--Source: http://www.macosxhints.com/article.p...40213045335693
     
Mac Elite
Join Date: Sep 2001
Location: Chico, CA and Carlsbad, CA.
Status: Offline
Reply With Quote
Feb 20, 2004, 04:33 PM
 
Neat. Very nice. Very neat and nice. I normally top -u, yuck, it always did bug me how that took so much CPU time... I'll use it. Thanks for pointing out this gem, as I don't read macosxhints.com.

"In Nomine Patris, Et Fili, Et Spiritus Sancti"

     
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status: Offline
Reply With Quote
Feb 20, 2004, 06:49 PM
 
"top -ud" uses a lot less time here, too. And less typing.
     
Professional Poster
Join Date: Jun 2003
Location: Hyrule
Status: Offline
Reply With Quote
Feb 20, 2004, 09:19 PM
 
man top

Tons of useful info. My fav when I'm low on ram is top -o rprvt
Aloha
     
Professional Poster
Join Date: Mar 2000
Location: New York, NY, USA
Status: Offline
Reply With Quote
Feb 22, 2004, 01:22 AM
 
I use top -F -s 3, personally. I like to be able to see some memory usage stats, but I don't need an update every second.
     
Grizzled Veteran
Join Date: Jul 2002
Location: Pinching up a storm on the Star Destroyer
Status: Offline
Reply With Quote
Feb 22, 2004, 01:26 AM
 
How much CPU does Activity viewer take?

"If it's broke, you choke."
     
Professional Poster
Join Date: Mar 2000
Location: New York, NY, USA
Status: Offline
Reply With Quote
Feb 22, 2004, 01:30 AM
 
Originally posted by Vader’s Pinch of Death:
How much CPU does Activity viewer take?
Lots. It's a GUI over top with some additional stuff – it can track which processes are tied to which apps – but it's a process hog. I only use it when necessary.
     
Grizzled Veteran
Join Date: Dec 2000
Location: Málaga, Spain, Europe, Earth, Solar System
Status: Offline
Reply With Quote
Feb 22, 2004, 01:32 AM
 
Originally posted by Vader’s Pinch of Death:
How much CPU does Activity viewer take?
In my current test bed (PowerMac G4 400mhz) with a alphabetically ordered list about 8%. If I set it to sort by CPU, so it is more dynamic, it can raise up to 10% often. This is with a 2 second poll time.
     
   
Thread Tools
Forum Links
Forum 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
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 08:52 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2