Mac OS X includes many diagnostic utilities that you can use to monitor your system and investigate problems.
The top utility displays memory statistics and a list of running processes. It is divided into two regions : the top region contains memory statistics, and the bottom region contains details on each process.
You can specify the number of processes to show by supplying a numeric argument. By default, top refreshes its display every second and sorts the list of processes by process ID (PID) in descending order. You can set top to sort by CPU utilization with - u , and you can specify the refresh delay with the - s option. Figure 15-1 shows the output of top -u 10 (if you wanted to refresh the output every 3 seconds, you could run top -s3 -u 10 ).
Figure 15-1. Sample output from top
Table 15-1 describes the values shown in the top region, and Table 15-2 describes the columns in the bottom region (process information).
Table 15-1. Memory information displayed by top
Table 15-2. Process information displayed by top
The fs_usage utility shows a continuous display of filesystem- related system calls and page faults. You must run fs_usage as root . By default, it ignores anything originating from fs_usage , Terminal , telnetd , sshd , rlogind , tcsh , csh , or sh .
Figure 15-2 shows the output of fs_usage , which displays the following columns:
Figure 15-2. Monitoring filesystem operations with fs_usage
latency measures the number of context switches and interrupts, and reports on the resulting delays, updating the display once per second. This utility must be run as root . Example 15-1 shows a portion of its output.
Example 15-1. Partial output from latency
Tue Dec 30 14:33:41 0:07:00 SCHEDULER INTERRUPTS --------------------------------------------- total_samples 339307 548794 delays < 10 usecs 296044 547403 delays < 20 usecs 17033 1199 delays < 30 usecs 5376 158 delays < 40 usecs 3020 29 delays < 50 usecs 1147 5 delays < 60 usecs 812 0 delays < 70 usecs 497 0 delays < 80 usecs 358 0 delays < 90 usecs 354 0 delays < 100 usecs 308 0 total < 100 usecs 324949 548794
The SCHEDULER column lists the number of context switches and the INTERRUPTS column lists the number of interrupts.
The sc_usage utility samples system calls and page faults, then displays them onscreen. sc_usage must be run by root or by someone with superuser privileges. The display is updated once per second. You must specify a PID, a command name, or a program to execute with the - E switch. For example, to monitor the Finder, use sudo sc_usage Finder . Figure 15-3 shows the output of running sc_usage on the Finder. Table 15-3 explains sc_usage 's output.
Figure 15-3. sc_usage monitoring the Finder
Table 15-3. Information displayed by sc_usage
The vm_stat utility displays virtual memory statistics. Unlike implementations of vm_stat in other Unix systems, it does not default to continuous display. Instead, it displays accumulated statistics.
To obtain a continuous display, specify an interval argument (in seconds), as in vm_stat 1 . Figure 15-4 shows the output of vm_stat with no arguments.
Figure 15-4. vm_stat displaying accumulated statistics
Figure 15-5 shows the output of vm_stat 1 . Table 15-4 describes the information that vm_stat displays (the item numbers correspond to the callouts in both figures).
Figure 15-5. vm_stat's continuous output
Table 15-4. Information displayed by vm_stat