CPU运行常规用户进程 CPU运行niced process CPU运行实时进程 2)系统使用CPU的情况
用于系统调用 用于I/O管理:中断和驱动 用于内存:paging and swapping 用于进程管理:context switch and process start 3)WIO:由于进程等待I/O而使CPU处于空闲状态的比率,这些I/O主要指block I/O,raw I/O,VM paging/swapins;
进程创建(process creation) 终端字符进程(teminal character processes(MUX- and LAN-based) 计算密集型进程和实时进程 X-终端和X-服务器进程(X-terminals and X-servers)
利用SAR工具分析CPU的利用率
利用SAR进行CPU的利用率分析的命令形式:
#sar -u,这时数据是通过sa1在后台定时生成; #sar -u 5 100,每隔5秒取样一次,共取100次; SAR -u:Report CPU utilization (the default); portion of time running in one of several modes. On a multi-processor system, if the -M option is used together with the -u option, per-CPU utilization as well as the average CPU utilization of all the processors are reported. If the -M option is not used, only the average CPU utilization of all the processors is reported:
cpu: cpu number (only on a multi-processor system with the -M option); %usr: user mode; %sys: system mode; %wio: idle with some process waiting for I/O (only block I/O, raw I/O, or VM pageins/swapins indicated); %idle: otherwise idle; 对结果的分析
#sar -q,这时数据是通过sa1在后台定时生成; #sar -q 5 100,每隔5秒取样一次,共取100次; SAR -q: Report average queue length while occupied, and percent of time occupied. On a multi-processor machine, if the -M option is used together with the -q option, the per-CPU run queue as well as the average run queue of all the processors are reported. If the -M option is not used, only the average run queue information of all the processors is reported:
cpu: cpu number (only on a multi-processor system with the -M option); runq-sz: Average length of the run queue(s) of processes (in memory and runnable); %runocc: The percentage of time the run queue(s) were occupied by processes (in memory and runnable); swpq-sz: Average length of the swap queue of runnable processes (processes swapped out but ready to run); %swpocc: The percentage of time the swap queue of runnable processes (processes swapped out but ready to run) was occupied. 对结果的分析:
用sar -u命令分析CPU的使用情况; 用sar -w命令分析进程的deactivation/reactivation and switching activities of the system; 也可以用GlancePlus;
利用SAR工具分析系统调用
利用SAR进行系统调用分析的命令形式:
#sar -c,这时数据是通过sa1在后台定时生成; #sar -c 5 100,每隔5秒取样一次,共取100次; SAR -c: Report system calls:
scall/s: Number of system calls of all types per second; sread/s: Number of read() and/or readv() system calls per second; swrit/s: Number of write() and/or writev() system calls per second; swpq-sz: Average length of the swap queue of runnable processes (processes swapped out but ready to run); fork/s: Number of fork() and/or vfork() system calls per second; exec/s: Number of exec() system calls per second; rchar/s: Number of characters transferred by read system calls block devices only) per second; wchar/s: Number of characters transferred by write system calls (block devices only) per second. 对结果的分析:
如果scall/s列的值很大,那么这么多的系统调用的原因就必须仔细分析了。
我们可以查看fork/s和exec/s列的值,看看系统是否在创建大量新的进程。
利用time命令测试某个命令和程序的执行效率
我们可以利用time命令来测试一个命令的执行效率,语法为:
time command
command is executed. Upon completion, time prints the elapsed time during the command, the time spent in the system, and the time spent executing the command. Times are reported in seconds.
Execution time can depend on the performance of the memory in which the program is running.
top [-s time] [-d count] [-q] [-u] [-h] [-n number]
其中各选项的含义为:
-s time: 屏幕刷新的时间间隔time,缺省为5秒; -d count: 屏幕刷新count次后,top命令自己也退出; -q: This option runs the top program at the same priority as if it is executed via a nice -20 command so that it will execute faster (see nice(1)). This can be very useful in discovering any system problem when the system is very sluggish. This option is accessibly only to users who have appropriate privileges. -u: User ID (uid) numbers are displayed instead of usernames. This improves execution speed by eliminating the additional time required to map uid numbers to user names. -h: Hides the individual CPU state information for systems having multiple processors. Only the average CPU status will be displayed. -n number: Show only number processes per screen. Note that this option is ignored if number is greater than the maximum number of processes that can be displayed per screen. 在top命令运行时,我们可用以下几个快捷键来翻屏:
我们通过RES(the current size of the process resident in memory)列可以知道每个进程占用内存的数量。
我们通过NICE列可以知道系统是否使用NICE值来调节该进程的工作负载平衡。
利用uptime命令查看系统整体情况
uptime prints the current time, the length of time the system has been up, the number of users logged on to the system, and the average number of jobs in the run queue over the last 1, 5, and 15 minutes.
w is linked to uptime and prints the same output as uptime -w, displaying a summary of the current activity on the system.
它的语法为:
uptime [-hlsuw] [user]
w [-hlsuw] [user]
其中各选项的含义为:
-h: Suppress the first line and the heading line. This option should not be used with the -u option. This option assumes the use of the -w option to uptime. -l: Use long output. This option assumes the use of the -w option to uptime. -s: Use the short form. of output for displaying terminal information. The terminal name is abbreviated; the login time and CPU times are suppressed. -u: Print only the first line describing the overall state of the system. This is the default for the uptime command.ormation for systems having multiple processors. Only the average CPU status will be displayed. -w: Print a summary of the current activity on the system for each user. This is the default for the w command.