arthas是阿里开发的一个java诊断工具,官网
https://arthas.aliyun.com/zh-cn/
下载地址
https://github.com/alibaba/arthas/releases
首先启动arthas-boot.jar,并选择java程序的pid
java -jar ./arthas-boot.jar [INFO] arthas-boot version: 3.6.0 [INFO] Found existing java process, please choose one and input the serial number of the process, eg : 1. Then hit ENTER. * [1]: 23235 [2]: 66309 math-game.jar [3]: 78485 [4]: 85979 [5]: 16061 org.jd.gui.OsxApp [6]: 90607 org.jetbrains.jps.cmdline.Launcher [7]: 88623 2 [INFO] arthas home: /Users/lintong/Downloads/arthas-bin [INFO] Try to attach process 66309 [INFO] Attach process 66309 success. [INFO] arthas-client connect 127.0.0.1 3658 ,---. ,------. ,--------.,--. ,--. ,---. ,---. / O \ | .--. ''--. .--'| '--' | / O \ ' .-' | .-. || '--'.' | | | .--. || .-. |`. `-. | | | || |\ \ | | | | | || | | |.-' | `--' `--'`--' '--' `--' `--' `--'`--' `--'`-----' wiki https://arthas.aliyun.com/doc tutorials https://arthas.aliyun.com/doc/arthas-tutorials.html version 3.6.0 main_class demo.MathGame pid 66309 time 2022-04-10 17:08:50 [arthas@66309]$
1.查看仪表盘
输入dashboard,退出control+C
2.查看主线程
[arthas@66309]$ thread 1 "main" Id=1 TIMED_WAITING at java.lang.Thread.sleep(Native Method) at java.lang.Thread.sleep(Thread.java:340) at java.util.concurrent.TimeUnit.sleep(TimeUnit.java:386) at demo.MathGame.main(MathGame.java:17)
3.watch命令监控方法
监控返回值
watch demo.MathGame primeFactors returnObj Press Q or Ctrl+C to abort. Affect(class count: 1 , method count: 1) cost in 119 ms, listenerId: 1 method=demo.MathGame.primeFactors location=AtExit ts=2022-04-10 17:16:30; [cost=1.662911ms] result=@ArrayList[ @Integer[2], @Integer[2], @Integer[2], @Integer[2], @Integer[2], @Integer[2], @Integer[2], @Integer[3], @Integer[419], ]
监控参数值
watch demo.MathGame primeFactors params Press Q or Ctrl+C to abort. Affect(class count: 1 , method count: 1) cost in 23 ms, listenerId: 2 method=demo.MathGame.primeFactors location=AtExceptionExit ts=2022-04-10 17:16:44; [cost=0.266471ms] result=@Object[][ @Integer[-150713], ]
4.反编译
jad demo.MathGame
其他参考:https://arthas.aliyun.com/doc/advanced-use.html