CPU Usage Analyses: top

top shows an ordered list of running processes. Default ordering is by CPU usage.

Performance Diagnosis
Technical articles
The two modes of top

Two modes of options can be used to modify how top displays its information
  • command line
  • runtime options

Command Line
The command line options are:
top [d delay] [C] [H] [i] [n iter] [b]

Description of top's command line options:
  • d delay: delay between statistics update
  • C: display the summed CPU statistics
  • H: show the individual threads rather than just displaying a total for each application
  • i: do not display processes that aren't using any of the CPU
  • n iter: number of iterations before exiting
  • b: batch mode, useful if redirecting output to a file or another command. Will not accept input and runs until the iterations limit set with the  -n command-line option or until killed.
  • p: Monitor only processes with specified process IDs.  Option can be given up to 20 times as -pN1 -pN2 ..., or provide a comma delimited list with up to 20 pids such as -pN1,N2,N3.  Co-mingling both approaches is permitted.

Runtime Options
The output of top can be easily customized during runtime. Some options are:
  • A: will switch between full-screen mode and alternate-display mode. The alternate-display mode has a lot of options that are worth experimenting with.
  • I (capital i): Irix/Solaris-Mode toggle: a task's CPU usage will be divided by the total number of CPUs.
  • f: Fields-Management, display a separate screen where you can change which fields are displayed, their order and also designate the sort field.
  • 1 (one): Single/Separate-CPU-States toggle. Affects whether each CPU is displayed separately. By default, the toggle is on for the "%Cpu(s):" information in the summary area and all cpu information is gathered in a single line. After you strike 1, each cpu is displayed separately as: "%Cpu0, %Cpu1," and so on.

Statistics Provided
The following CPU-related statistics are displayed by top:
  • %CPU: The task's share of the elapsed CPU time since the last screen update, expressed as a percentage of total CPU time.
  • Command: the command line used to start a task or the name of the associated program.
  • hi : time spent servicing hardware interrupts
  • id, idle: time spent in the kernel idle handler
  • load average: 1, 5 and 15 minute load average (the number of running processes waiting for or using CPU resources).
  • ni, nice: time running niced user processes
  • NI:  Nice Value of the task.  A negative nice value means higher priority, whereas a positive nice value means lower priority. Zero in this field simply means priority will not be adjusted in determining a task's dispatch-ability.
  • PR: Priority. The scheduling priority of the task.  "rt" in this field means the task is running under real time scheduling priority. However, this is somewhat misleading since the OS itself is often not preemptible. 
  • S: Process Status of the task, which can be one of:  D = uninterruptible sleep; R = running; S = sleeping; T = stopped by job control signal; t = stopped by debugger during trace; Z = zombie
  • si : time spent servicing software interrupts
  • st : time stolen from this vm by the hypervisor
  • sy, system: time running kernel processes
  • TIME: Total CPU time the task has used since it started.  When Cumulative mode is On (interactively toggled with S or with -S on the command line), each process is listed with the CPU time that it and its dead children have used.
  • TIME+ (TIME followed by +): CPU Time, hundredths. The same as TIME, but reflecting more granularity through hundredths of a second.
  • us, user: time running un-niced user processes
  • wa, IO-wait: time waiting for I/O completion
  • WCHAN: Sleeping in Function, shows the name of the kernel function in which the task is currently sleeping.  Running tasks will display a dash  (-) in this column.

Performance Diagnosis
Technical articles