You are on page 1of 3

Under Sun Solaris UNIX (and other UNIX oses like HP-UX and *BSD oses) you can

use following commands to gather CPU information: => sar : System activity reporter => mpstat : Report per-processor or per-processor-set statistics => ps / top commands

UNIX sar command examples

The System Activity Reporter (SAR) checks the processor at regular intervals and logs it either to the console or to a file you specify. It takes at least one argument: the delay, in seconds, between each time that it checks the processor. Additionally, you can specify a file to log the information in as well as the number of times to perform the check before stopping. The following command would check the CPU usage every five seconds for one minute and log the information in a file named "cpuinfo:" SAR is a good choice for administrators who want a long-term log of CPU utilization over time.

General syntax is as follows: sar t [n]

In the first instance, sar samples cumulative activity counters in the operating system at n intervals of t seconds, where t should be 5 or greater. If t is specified with more than one option, all headers are printed together and the output may be difficult to read.
Task: Display today's CPU activity, use

# sar

Task:Watching system activity evolve i.e. reports CPU Utilization

# sar -u 12 5


-u 12 5: Comparison of CPU utilization; 12 seconds apart; 5 times.

Output includes: 1. %usr: User time (% of CPU) 2. %sys: System time (% of CPU) 3. %wio: Percent of CPU running idle with a process waiting for block I/O 4. %idle: Percent of CPU that is idle Task: You can watch CPU activity evolve for 10 minutes and save data

# sar -o file-name 60 10

Task: You can just sar and logout and let the report store in files

# nohup sar -A -o output-file 60 10 1>/dev/null 2>&1 &

Note to display data stored in output-file pass -f option to sar command:

# sar -f output-file

UNIX mpstat example

MPStat has the same format as the SAR command, but displays extra information for multiprocessor computers regarding the utilization on each individual processor. It is only installed on some systems
Type the following command to display per-processor statistics; 12 seconds apart; 5 times
# mpstat 12 5

UNIX top example

While SAR and MPStat provide information about overall CPU usage, Top allows you to analyze CPU usage by individual processes in intimate detail. It also provides real

time data, unlike SAR and MPStat. To use it, simply type "top" into your terminal. You can also type "top -o cpu" to tell Top to sort its results in order of processes that are using the most CPU time. You can exit Top by hitting "q" at any time. Top is a good choice for users who want a fast, one-time idea of what CPU utilization is at that moment in order to diagnose sluggish performance.

You can also use traditional ps and top command:

# top

UNIX Process Status(PS) example

Process Status (PS) can be also be used to check the percentage of CPU used by each process. In fact, it is where Top gets its information; however, it takes a little more typing to use. To get a report from PS, type the following: "ps -e -o pcpu -o pid -o user -o args." The only advantage of using PS over Top is that PS will generate a report and return to the command line immediately.

# ps -e -o pcpu -o pid -o user -o args

@Read man pages of ps, top, mpstat and sar for more information.