The top tool is an important tool for identifying potential problem areas in a process. This tool displays a periodically sampled set of statistics on system usage. Using top and understanding its output are an excellent way to identify potential performance problems.
The top tool displays periodically updated statistics on CPU usage, memory usage (in various categories), resource usage (such as threads and ports), and paging events. In the default mode, top displays CPU and memory utilization of all system processes. You can use this information to see how much memory your program is using and what percentage of the CPU time it is using. An idle program should not use any CPU time and an active one should consume a proportionate amount of CPU time based on the complexity of the task.
Note: If you want to track CPU usage and other statistics over time, use BigTop instead. BigTop graphs performance trends over time, providing a real-time display of memory usage, page faults, CPU usage, and other data.
Listing 4-1 shows a typical statistical output from top. For application developers, the statistics you should be most interested in are the CPU usage, resident private memory usage (RPRVT), and pagein/pageout rates. These values tell you some key things about your application’s resource usage. High CPU usage may mean that your application tasks are not tuned appropriately. Increased memory usage and page-in/page-out rates may indicate a need to reduce your application’s memory footprint.
Listing 4-1 Typical output of top
Processes: 36 total, 2 running, 34 sleeping... 81 threads |
Load Avg: 0.24, 0.27, 0.23 CPU usage: 12.5% user, 87.5% sys, 0.0% idle |
SharedLibs: num = 77, resident = 10.6M code, 1.11M data, 4.75M LinkEdit |
MemRegions: num = 1207, resident = 16.4M + 4.94M private, 22.2M shared |
PhysMem: 16.0M wired, 25.8M active, 48.9M inactive, 90.7M used, 37.2M free |
VM: 476M + 39.8M 6494(6494) pageins, 0(0) pageouts |
PID COMMAND %CPU TIME #TH #PRTS #MREGS RPRVT RSHRD RSIZE VSIZE |
318 top 0.0% 0:00.36 1 23 13 172K 232K 380K 1.31M |
316 zsh 0.0% 0:00.08 1 18 12 168K 516K 628K 1.67M |
315 Terminal 0.0% 0:02.25 4 112 50 1.32M 3.55M 4.88M 31.7M |
314 CPU Monito 0.0% 0:02.08 1 63 35 896K 1.34M 2.14M 27.9M |
313 Clock 0.0% 0:01.51 1 57 38 1.02M 2.01M 2.69M 29.0M |
312 Dock 0.0% 0:03.72 2 77 78 2.18M 2.28M 3.64M 30.0M |
311 Finder 0.0% 0:07.68 4 86 171 7.96M 9.15M 15.1M 52.1M |
308 pbs 0.0% 0:01.37 4 76 40 928K 684K 1.77M 15.4M |
285 loginwindow 0.0% 0:07.19 2 70 58 1.64M 1.93M 3.45M 29.6M |
282 cron 0.0% 0:00.00 1 11 14 88K 228K 116K 1.50M |
245 sshd 0.0% 0:02.48 1 10 15 176K 312K 356K 1.41M |
222 SecuritySe 0.0% 0:00.14 2 21 24 476K 828K 1.29M 3.95M |
209 automount 0.0% 0:00.03 2 13 20 336K 748K 324K 4.36M |
200 nfsiod 0.0% 0:00.00 1 10 12 4K 224K 52K 1.22M |
199 nfsiod 0.0% 0:00.00 1 10 12 4K 224K 52K 1.2 |
[...] |
In its header area, top displays statistics on the global state of the system. This information includes load averages; total process and thread counts; and total memory, broken down into various categories such as private, shared, wired, and free. It also includes global information concerning the system frameworks. At regular intervals, top updates these statistics to account for recent system activity.
Table 4-1 describes the columnar data that appears in the CPU and memory utilization mode using the -w parameter. For detailed information about how top reports information, see the top(1) man page.
The RPRVT data (for resident private pages) is a good measure of how much real memory an application is using. The RSHRD column (for resident shared pages) shows the resident pages of all the shared mapped files or memory objects that are shared with other tasks.
Note: The top tool does not provide a separate count of the number of pages in shared libraries that are mapped into the task.
The top tool reports memory usage of windows in the “shared memory” category because window buffers are shared with the window server.
Table 4-2 shows the columns displayed in the event-counting mode, which is enabled with either the -e, -d, or -a option on the command line.
Last updated: 2006-10-03