一、镜像安装:
1、切换到进程运行所在的用户
$sudo su sc #sc为java进程运行的用户
2、安装
$curl -L https://alibaba.github.io/arthas/install.sh | sh #前提是你的机器到alibaba镜像未做隔离
3、从shell进入到arthas
$./as.sh
选择进程编号,比如1
4、查看
$ thread -n 3 #查看CPU占用高的前3个线程所对应的代码
$ thread -b 找到阻塞的线程
注:
$./as.sh PID
Arthas script version: 3.0.4
arthas not found, please check your network.
出现上面报错,卸载重新安装,卸载步骤如下:
$rm -rf ~/.arthas/ ~/.arthas_history
$rm -rf as.sh
二、本地源安装:
1、$ sudo yum-test install greys #你本地的源安装,比如yum-test 是我本地的源
2、$ sudo su sc #切换到java进程运行所在的用户
3、$ jps
20553 xxxx-RELEASE.jar
4601 Jps
4、查看进程20553的阻塞代码块
$ greys 20553
_
____ ____ _____ _ _ ___ _____ _____ ____ _____ _| |_ ___ ____ _ _
/ _ |/ ___) ___ | | | |/___|_____|____ | _ \(____ (_ _) _ \| \| | | |
( (_| | | | ____| |_| |___ | / ___ | | | / ___ | | || |_| | | | | |_| |
\___ |_| |_____)\__ (___/ \_____|_| |_\_____| \__)___/|_|_|_|\__ |
(_____| (____/ (____/
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|v|e|r|s|i|o|n|:|1|.|7|.|6|.|6|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
ga?>top -d -t 2
+------+--------+---------+----------------------+---------------------------------------------------------------------------------------+
| ID | CPU% | USR% | STATE | THREAD_NAME |
+------+--------+---------+----------------------+---------------------------------------------------------------------------------------+
| #718 | 04.33% | WAITING | Thread-Aggregate-Con | at : xxxx(Native Method) |
| | | | | at : xxxx(AggregateDataConsum |
| | | | | er.java:58) |
| | | | | at : java.util.xxxx(ThreadPoolExecutor.java:1149) |
| | | | | at : java.util.xxxx(ThreadPoolExecutor.java:624) |
| | | | | at : java.lang.Thread.run(Thread.java:748) |
+------+--------+---------+----------------------+---------------------------------------------------------------------------
-------+---------+----------------------+-----------------------------------------------------------------------------------+
ga?>