Detailed explanation of arthas usage

I wrote an article about how to eliminate the high cpu usage rate of linux server caused by java program - leonnew's blog - CSDN blog

The simple usage of the arthas program is mentioned in it. Let’s talk about some special features in detail today

Run a demo: wget https://arthas.aliyun.com/math-game.jar

java -jar math-game.jar

How to get arthas: wget https://arthas.aliyun.com/arthas-boot.jar

How to start: 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:

Print the thread stack, you can see that the main class is 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

Used to query the class loaded by jvm

Jad

4、The jad command can be used to decompile the byte code:

jad demo.MathGame

用来反编译代码,可以看到MathGame的main类的代码内容

--source-onlyYou can only print out the decompiled source code through parameters

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

You can view the parameter/return value/exception information of the function.

 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], ]

You can see the running mechanism of the jvm virtual machine

 Arthas can be exited with the exit or quit command.

exit and quit can exit arthas

Guess you like

Origin blog.csdn.net/leonnew/article/details/123663080