之前写过一篇java程序造成linux服务器cpu使用率非常高的排除方法_leonnew的博客-CSDN博客
里面提到过arthas程序的简单用法。今天再详细说下几个特殊功能
运行一个demo:wget https://arthas.aliyun.com/math-game.jar
java -jar math-game.jar
如何获得arthas:wget https://arthas.aliyun.com/arthas-boot.jar
如何启动:java -jar arthas-boot.jar
arthas-boot
is the launcher for Arthas
. It lists all the Java processes, and the user can select the target process to be diagnosed.
Select the first process, type 1
,then type Enter
:
After the Attach is successful, Arthas LOGO is printed. Enter help
for more help.
Dashboard
1、The dashboard
command allows you to view the real-time data panel of the current system.
Thread
2、The thread 1
command prints the stack of thread ID 1.
Arthas supports pipes, and you can find main class
with thread 1 | grep 'main('
.
You can see that main class
is demo.MathGame
:
打印线程的栈,可以看到main class是demo.MathGame
$ thread 1 | grep 'main('
at demo.MathGame.main(MathGame.java:17)
Sc
3、The sc
command can be used to find the loaded classes in the JVM:
sc -d *MathGame
用来查询jvm加载的类
Jad
4、The jad
command can be used to decompile the byte code:
jad demo.MathGame
用来反编译代码,可以看到MathGame的main类的代码内容
通过--source-only
参数可以只打印出在反编译的源代码
jad --source-only com.example.demo.arthas.user.UserController
Watch
The watch
command can view the parameter/return value/exception of the method.
watch demo.MathGame primeFactors returnObj
可以查看函数的参数/返回值/异常信息。
Vmtool
The vmtool
command can search object in JVM.
vmtool --action getInstances --className java.lang.String --limit 10
bash $ vmtool --action getInstances --className java.lang.String --limit 10 @String[][ @String[com/taobao/arthas/core/shell/session/Session], @String[com.taobao.arthas.core.shell.session.Session], @String[com/taobao/arthas/core/shell/session/Session], @String[com/taobao/arthas/core/shell/session/Session], @String[com/taobao/arthas/core/shell/session/Session.class], @String[com/taobao/arthas/core/shell/session/Session.class], @String[com/taobao/arthas/core/shell/session/Session.class], @String[com/], @String[java/util/concurrent/ConcurrentHashMap$ValueIterator], @String[java/util/concurrent/locks/LockSupport], ]
可以看到jvm虚拟机运行机制
Arthas can be exited with the exit
or quit
command.
exit和quit可以退出arthas