“top” command로 CPU usage 정확하게 보는 법

“top” command로 CPU usage 정확하게 보는 법

아래 부분은 “Summary information”이라 한다.
top – 17:03:13 up 51 days,  1:43,  1 user,  load average: 3.06, 3.73, 4.23
Tasks: 222 total,   4 running, 218 sleeping,   0 stopped,   0 zombie
Cpu(s): 14.6% us, 58.7% sy,  0.0% ni, 26.0% id,  0.6% wa,  0.1% hi,  0.0% si
Mem:   3895404k total,  3847444k used,    47960k free,    93316k buffers
Swap:  4192924k total,   527860k used,  3665064k free,  2767296k cached

아래 부분은 “running application field information”이라 한다.
PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
17841 wasadm    16   0 56892  10m 3212 S 15.6  0.3   7319:25 tnslsnr
9298 wasadm    16   0 17768 6228 3920 S  6.6  0.2   0:00.20 sqlldr
9315 wasadm    20   0 17300 5296 3396 S  3.7  0.1   0:00.11 sqlldr
9301 wasadm    19   0 17300 5288 3388 S  3.0  0.1   0:00.09 sqlldr

우선 running application field information의 cpu usage는 Summary information의 %user cpu usage와 같다.
%system cpu usage는 running application field information에 출력되지 않는다.

양 information의 cpu usage를 동일하게 맞추어 보기 위해서는 아래의 방법으로 본다.

– 코어별CPU 사용률을 싱글코어 CPU사용률로 환산하여 보기
Summary information – smp mode off (default)
running application field information – Solaris mode
※ task의 cpu usage는 cpu 코어 총합으로 나뉘어 출력된다.

– 코어별 CPU 사용률 보기
Summary information – smp mode on
running application field information – Irix mode (default)

smp mode는 숫자키 “1”로 on/off 할 수 있다.
Irix mode <-> Solaris mode 간 switching은 Shift + i 이다.

top 실행 옵션을 파일로 export하여 매 실행 때마다 파일로부터 옵션을 읽어들여 실행하는 방법은 아래와 같다.
– top 실행 중 Shift + w 누름
– q 또는 Ctrl + c 눌러 top에서 빠져 나옴
– /root/.toprc 파일을 편집기로 open하여 입맛에 맞게 변경

이 블로그를 돌리고 있는 서버에는 아래 내용으로 .toprc 파일을 구성해서 관리하고 있다.
[root@digimoon ~]# cat /root/.toprc
RCfile for “top with windows”           # shameless braggin’
Id:a, Mode_altscr=0, Mode_irixps=1, Delay_time=3.000, Curwin=0
Def     fieldscur=AEHIOQTWKLNMbcdfgjrpsuvyzX
winflags=97144, sortindx=10, maxtasks=0
summclr=3, msgsclr=1, headclr=3, taskclr=2
Job     fieldscur=ABcefgjlrstuvyzMKNHIWOPQDX
winflags=62777, sortindx=0, maxtasks=0
summclr=6, msgsclr=6, headclr=7, taskclr=6
Mem     fieldscur=ANOPQRSTUVbcdefgjlmyzWHIKX
winflags=62777, sortindx=13, maxtasks=0
summclr=5, msgsclr=5, headclr=4, taskclr=5
Usr     fieldscur=ABDECGfhijlopqrstuvyzMKNWX
winflags=62777, sortindx=4, maxtasks=0
summclr=3, msgsclr=3, headclr=2, taskclr=3
[root@digimoon ~]#

아래는 위 .toprc 구성에 의한 top 출력 결과입니다.

5656630545