使用jdk自帶的jstack來分析linux服務器上應用服務性能異常:java
1.top查找出哪一個進程消耗的系統資源狀況linux
[op1@jira ~]$ top服務器
top - 19:23:43 up 22 days, 3:43, 1 user, load average: 3.45, 2.52, 1.19性能
Tasks: 134 total, 1 running, 133 sleeping, 0 stopped, 0 zombie線程
Cpu(s): 57.3%us, 1.9%sy, 0.0%ni, 40.6%id, 0.0%wa, 0.1%hi, 0.1%si, 0.0%st進程
Mem: 6105924k total, 3466656k used, 2639268k free, 47512k buffers資源
Swap: 4194296k total, 42496k used, 4151800k free, 1328268k cachedit
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND test
15995 root 22 0 3437m 1.8g 40m S 355.6 30.9 221:04.19 java jdk
21165 op1 15 0 10876 1052 768 R 0.3 0.0 0:00.34 top
1 root 15 0 10364 580 548 S 0.0 0.0 0:01.07 init
........
2.先輸入top,而後再按shift+h 顯示線程消耗資源
Tasks: 269 total, 1 running, 268 sleeping, 0 stopped, 0 zombie
Cpu(s): 0.1%us, 0.1%sy, 0.0%ni, 99.9%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 6105924k total, 4425172k used, 1680752k free, 170816k buffers
Swap: 4194296k total, 42492k used, 4151804k free, 1729076k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
16215 root 18 0 3474m 2.2g 56m S 9999.0 37.8 112:00.66 java
16208 root 15 0 3474m 2.2g 56m S 1962.2 37.8 0:59.05 java
16114 root 16 0 3474m 2.2g 56m S 305.0 37.8 0:09.18 java
16209 root 15 0 3474m 2.2g 56m S 291.1 37.8 0:08.76 java
.....(這些線程都是進程15995下的)
3.jstack查找這個線程的信息
jstack [進程]|grep -A 10 [線程的16進制]
如:jstack 21125|grep -A 10 52f1(-A 10表示查找到所在行的後10行。21233用計算器轉換爲16進制52f1,注意轉換後的十六進制字母是小寫)
4.使用jstack來dump出全部線程的狀態和調用堆棧並保存到本地文件dump_test
[root@jira bin]# ./jstack 15995 >> dump_test