官方文档:Arthas Install — Arthas 3.5.5 文档
安装
Arthas 是阿里开源的一款 linux/mac 上性能问题排查工具。文档链接: Arthas 用户文档 — Arthas 3.5.5 文档 (这个里边具体步骤和指令讲得很详细)
-
安装启动
wget https://alibaba.github.io/arthas/arthas-boot.jar
java -jar arthas-boot.jar (确保安装了完整 java 且 jps 命令可用)
java -jar arthas-boot.jar --repo-mirror aliyun --use-http (下载真正的运行包,默认到 /Users/shicai.xsc/.arthas/lib/3.1.4/arthas 目录)
下载完后,可以看到 arthas 文件夹里有以下文件。可以将此文件夹打包拷贝到其他机器直接使用。
[admin@iZbp1i1vql5huywx13yay4Z arthas]$ ls
arthas-agent.jar arthas-boot.jar arthas-client.jar arthas-core.jar arthas-demo.jar arthas-spy.jar as.bat as-service.bat as.sh install-local.sh
使用时执行 sh as.sh
-
查看最慢的 n 个进程
thread -n 3
-
根据线程 ID 查看线程堆栈
thread 25 25 是线程 ID
-
利用jad反编译指定class
jad org.slf4j.Logger 出来的每个 hashcode 代表一个 classloader
jad org.slf4j.Logger -c 17a7cec2 反编译相应代码
提示:可以通过 tab 键来补全类名
-
显示所有加载过这个类的 ClassLoader
sc -d org.slf4j.Logger
sc -d *slf4j*Logger
-
输出当前方法被调用的调用路径
stack com.xxxxx.middleware.kkkkkkk.core.applier.opensearch.OpenSearchApplier apply
-
方法内部调用路径,并输出方法路径上的每个节点上耗时
trace com.xxxxx.middleware.kkkkkkk.core.applier.opensearch.OpenSearchApplier apply
-
显示方法执行时出参入参
watch com.XXXX.middleware.kkkkkkk.core.applier.opensearch.OpenSearchApplier apply "{params[0],throwExp}" -e -x 2
watch com.XXXX.middleware.jingwei.api.mc.MetaCenterApi queryTddlRuleCached "{params, returnObj, throwExp}"
watch com.XXXX.middleware.jingwei.common.util.DefaultMessageFilter isSatisfied 'target' target 指的是调用 isSatisfied 的对象
watch com.XXXX.middleware.jingwei.common.util.DefaultMessageFilter isSatisfied 'target.tableActionMap' 然后使用target.field_name访问当前对象的某个属性
Thread
- thread 查看当前进程的所有线程
- thread -n 3 展示当前最忙的前N个线程并打印堆栈
- thread -b 找出当前阻塞其他线程的线程
- thread id 显示指定线程的运行堆栈
- thread -i 指定采样时间间隔
- thread --state WAITING 查看指定状态的线程
- thread –all, 显示所有匹配的线程
refine 动态修改代码
redefine /tmp/com/example/demo/arthas/user/UserController.class
进程不用重启就直接使用新代码逻辑