 |
 |
Reduce CPU usage of 'top' (awesome tip) .
|
 |
|
 |
|
Mac Elite
Join Date: Feb 2001
Location: Canaduh
Status:
Offline
|
|
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
|
|
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
|
|
"top -ud" uses a lot less time here, too. And less typing.
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Jun 2003
Location: Hyrule
Status:
Offline
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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.
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|