java占用CPU分析

找到对应进程的PID
[root@master1 rundeck]# top
top - 03:10:32 up8:06,2 users,load average: 0.08, 0.03, 0.05
Tasks: 243 total,2 running, 241 sleeping,0 stopped,0 zombie
%Cpu(s):0.1 us,0.1 sy,0.0 ni, 99.7 id,0.0 wa,0.0 hi,0.0 si,0.0 st
KiB Mem :3874956 total,383964 free,1264232 used,2226760 buff/cache
KiB Swap:4063228 total,4063228 free,0 used.2329668 avail Mem
PID USERPRNIVIRTRESSHR S%CPU %MEMTIME+ COMMAND
25136 root200 4769720 94014816168 S0.6 24.33:56.49 java
25389 root20014820021281420 R0.60.10:00.07 top
1 root2004338836442352 S0.00.10:04.88 systemd
2 root200000 S0.00.00:00.03 kthreadd
3 root200000 S0.00.00:03.43 ksoftirqd/0
5 root0 -20000 S0.00.00:00.00 kworker/0:0H
7 rootrt0000 S0.00.00:00.14 migration/0
8 root200000 S0.00.00:00.00 rcu_bh
9 root200000 S0.00.00:00.00 rcuob/0
10 root200000 S0.00.00:00.00 rcuob/1
11 root200000 S0.00.00:00.00 rcuob/2
12 root200000 S0.00.00:00.00 rcuob/3
13 root200000 S0.00.00:00.00 rcuob/4
显示线程列表,同时按照CPU占用高的线程排序
[root@master1 rundeck]# ps -mp 25136 -o THREAD,tid,time |sort -rn
USER%CPU PRI SCNT WCHANUSER SYSTEMTIDTIME
root5.9-- ---- 00:03:56
root1.519- futex_-- 25148 00:01:01
root1.519- futex_-- 25147 00:01:01
root1.519- futex_-- 25138 00:01:01
root0.219- futex_-- 25151 00:00:08
root0.219- futex_-- 25149 00:00:11
root0.019- inet_c-- 25166 00:00:00
root0.019- futex_-- 25195 00:00:00
root0.019- futex_-- 25194 00:00:00
root0.019- futex_-- 25193 00:00:00
root0.019- futex_-- 25188 00:00:00
root0.019- futex_-- 25187 00:00:01
root0.019- futex_-- 25186 00:00:01
root0.019- futex_-- 25185 00:00:01
root0.019- futex_-- 25184 00:00:00
root0.019- futex_-- 25183 00:00:00
root0.019- futex_-- 25182 00:00:00
root0.019- futex_-- 25181 00:00:01
root0.019- futex_-- 25180 00:00:00
root0.019- futex_-- 25179 00:00:00
root0.019- futex_-- 25178 00:00:01
root0.019- futex_-- 25177 00:00:00
root0.019- futex_-- 25176 00:00:00
root0.019- futex_-- 25175 00:00:00
root0.019- futex_-- 25174 00:00:00
root0.019- futex_-- 25173 00:00:00
root0.019- futex_-- 25172 00:00:00
root0.019- futex_-- 25171 00:00:00
root0.019- futex_-- 25170 00:00:03
root0.019- futex_-- 25168 00:00:00
root0.019- futex_-- 25165 00:00:00
root0.019- futex_-- 25163 00:00:00
root0.019- futex_-- 25162 00:00:00
root0.019- futex_-- 25161 00:00:00
root0.019- futex_-- 25160 00:00:00
root0.019- futex_-- 25158 00:00:00
root0.019- futex_-- 25155 00:00:00
root0.019- futex_-- 25154 00:00:01
root0.019- futex_-- 25150 00:00:00
root0.019- futex_-- 25146 00:00:00
root0.019- futex_-- 25145 00:00:00
root0.019- futex_-- 25144 00:00:00
root0.019- futex_-- 25143 00:00:01
root0.019- futex_-- 25142 00:00:03
root0.019- futex_-- 25141 00:00:03
root0.019- futex_-- 25140 00:00:03
root0.019- futex_-- 25139 00:00:03
root0.019- futex_-- 25136 00:00:00
root0.019- ep_pol-- 25167 00:00:00
root0.019- ep_pol-- 25164 00:00:00
将线程的PID转换为16进制
[root@master1 rundeck]# printf "%x\n" 25148
623c
使用jstack打印该进程下面的此线程的堆栈信息
[root@master1 rundeck]# jstack 25136 | grep "623c" -A 30
"C2 CompilerThread1" #6 daemon prio=9 os_prio=0 tid=0x00007ff4a41e6800 nid=0x623c waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
"C2 CompilerThread0" #5 daemon prio=9 os_prio=0 tid=0x00007ff4a41d7000 nid=0x623b waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
"Signal Dispatcher" #4 daemon prio=9 os_prio=0 tid=0x00007ff4a41d5000 nid=0x623a runnable [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
"Finalizer" #3 daemon prio=8 os_prio=0 tid=0x00007ff4a41ab000 nid=0x6239 in Object.wait() [0x00007ff4941f0000]
java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:144)
- locked <0x00000000c000d3d8> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:165)
at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:216)
"Reference Handler" #2 daemon prio=10 os_prio=0 tid=0x00007ff4a41a6000 nid=0x6238 in Object.wait() [0x00007ff4942f1000]
java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
at java.lang.Object.wait(Object.java:502)
at java.lang.ref.Reference.tryHandlePending(Reference.java:191)
- locked <0x00000000c000d590> (a java.lang.ref.Reference$Lock)
at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:153)
"VM Thread" os_prio=0 tid=0x00007ff4a419c800 nid=0x6237 runnable
"GC task thread#0 (ParallelGC)" os_prio=0 tid=0x00007ff4a405e000 nid=0x6233 runnable
"GC task thread#1 (ParallelGC)" os_prio=0 tid=0x00007ff4a4060000 nid=0x6234 runnable
打印GC 信息
[root@master1 rundeck]# jstat -gcutil 25136 200 50
S0S1EOMCCSYGCYGCTFGCFGCTGCT
52.900.0018.2660.0496.6791.29602.57142.0374.608
52.900.0018.2660.0496.6791.29602.57142.0374.608
52.900.0018.2660.0496.6791.29602.57142.0374.608
52.900.0018.2660.0496.6791.29602.57142.0374.608
52.900.0018.2660.0496.6791.29602.57142.0374.608
52.900.0018.2660.0496.6791.29602.57142.0374.608
52.900.0018.2660.0496.6791.29602.57142.0374.608
52.900.0018.2660.0496.6791.29602.57142.0374.608
52.900.0018.2660.0496.6791.29602.57142.0374.608
52.900.0018.2660.0496.6791.29602.57142.0374.608
52.900.0018.2660.0496.6791.29602.57142.0374.608
52.900.0018.2660.0496.6791.29602.57142.0374.608
52.900.0018.2660.0496.6791.29602.57142.0374.608
52.900.0018.2660.0496.6791.29602.57142.0374.608
52.900.0018.2660.0496.6791.29602.57142.0374.608
52.900.0018.2660.0496.6791.29602.57142.0374.608
52.900.0018.2660.0496.6791.29602.57142.0374.608
52.900.0018.2660.0496.6791.29602.57142.0374.608
52.900.0018.2660.0496.6791.29602.57142.0374.608
52.900.0018.2660.0496.6791.29602.57142.0374.608
52.900.0018.2660.0496.6791.29602.57142.0374.608
52.900.0018.2660.0496.6791.29602.57142.0374.608
52.900.0018.2660.0496.6791.29602.57142.0374.608
52.900.0018.2660.0496.6791.29602.57142.0374.608
52.900.0018.2660.0496.6791.29602.57142.0374.608
52.900.0018.2660.0496.6791.29602.57142.0374.608
52.900.0018.2660.0496.6791.29602.57142.0374.608
52.900.0018.2660.0496.6791.29602.57142.0374.608
52.900.0018.2660.0496.6791.29602.57142.0374.608
52.900.0018.2660.0496.6791.29602.57142.0374.608
52.900.0018.2660.0496.6791.29602.57142.0374.608
52.900.0018.2660.0496.6791.29602.57142.0374.608
52.900.0018.2660.0496.6791.29602.57142.0374.608
52.900.0018.2660.0496.6791.29602.57142.0374.608
52.900.0018.2660.0496.6791.29602.57142.0374.608
52.900.0018.2660.0496.6791.29602.57142.0374.608
52.900.0018.2660.0496.6791.29602.57142.0374.608
52.900.0018.2660.0496.6791.29602.57142.0374.608
52.900.0018.2660.0496.6791.29602.57142.0374.608
52.900.0018.2660.0496.6791.29602.57142.0374.608
52.900.0018.2660.0496.6791.29602.57142.0374.608
52.900.0018.2660.0496.6791.29602.57142.0374.608
52.900.0018.2660.0496.6791.29602.57142.0374.608
52.900.0018.2660.0496.6791.29602.57142.0374.608
52.900.0018.2660.0496.6791.29602.57142.0374.608
52.900.0018.2660.0496.6791.29602.57142.0374.608
52.900.0018.2660.0496.6791.29602.57142.0374.608
52.900.0018.2660.0496.6791.29602.57142.0374.608
52.900.0018.2660.0496.6791.29602.57142.0374.608
52.900.0018.2660.0496.6791.29602.57142.0374.608
导出内存快照
[root@master1 rundeck]# jmap -dump:live,format=b,file=dump.hprof 25136
Dumping heap to /home/rundeck/rundeck/dump.hprof ...
Heap dump file created
【java占用CPU分析】寻找合适的工具分析内存。

    推荐阅读