Arthas - java diagnostic tools open source, very useful

 

Common Commands

help View Help
help COMMAND View detailed help for the specified command
The COMMAND - H View detailed help for the specified command
 Double the Tab to see all the commands supported

thread View all threads
the Thread 51                View specified thread stacks
the Thread -n 5              before viewing thread stacks 5
the Thread -n - 1             View All thread stacks
the Thread - b View blocked thread
Thread -i 2000           specified sampling interval in the calculation of CPU usage (the output after 2 seconds)

jad javax.servlet.Servlet for jvm loaded classes decompile 
(java -jar cfr-0.148.jar /tmp/TestClass.class can decompile class file, org.benf: cfr0.148)
mc / tmp / Test.java compile java files

sc javax.servlet.Servlet Find jvm loaded classes
sc - d javax.servlet.Servlet Find jvm loaded type, print detailed

stack com.TestClass testMethod method to view the call stack, re-triggered print

Time-consuming method call child trace com.TestClass testMethod View methods

{com.TestClass testMethod the params Watch [ 0 ], throwExp} - E method throws an exception when viewing parameter passing method, only if the method throws an exception when printing (not tested)

Monitor -C . 3 com.TestClass testMethod method for monitoring the number of calls, the success rate and other information, is output once every 3 seconds.

View the number classloader class loader, and the number of each class loader to load

[Redefine + sc + jad] implementation does not restart load class
redefine load external .class file, redefine jvm loaded classes
redefine -c ClassLoaderHash / tmp / TestClass.class the modified compiled class files into the specified directory, and redefine
Wherein ClassLoaderHash class loader for the class HashCode, by " SC com.TestClass -d " Query
You must specify ClassLoaderHash, otherwise the changes will not take effect
Note: After redefine thought through " JAD com.TestClass " decompile look at whether to modify, decompile, however modify it to restore immediately the need to redefine again (this is the way to restore)


【tt】
tt recording method called time-slice information
tt - t com.TestClass testMethod start recording
(HTTPS: // alibaba.github.io/arthas/tt # method overloading problem - solving method overloading) 
tt - L View history
TT - I see a time slice ID information (including parameters)
TT -i ID - W the params [ 0 value] See Method a time slice parameters
TT -i ID - W the params [ 0 ] .length () Check the value of the first parameter of the time slice method, the support object access
TT - ID -i W {the params [ 0 ], param [ . 1 value]} method of viewing time slice a plurality of parameters
( - w watch expressions, HTTPS: // alibaba.github.io/arthas/advice-class.html)

 

Use / Installation Guide

【download tool】
HTTPS: // alibaba.github.io/arthas/arthas-boot.jar 
or
HTTPS: // alibaba.github.io/arthas/install.sh(sh startup script install.sh download as.sh)
 
【Conditions of Use】
Environment need to install java
Dependent JDK / lib / the tools.jar
If only jre, can be copied to tools.jar jdk JRE / lib / lower
as.sh need telnet command, without using telnet Arthas - boot.jar way
 
[Start] tool
from java jar arthas bootjar huo- sh is visited are shown. sh

The first start will download arthas - 3.1 . 4 -bin.zip to /root/.arthas/lib/ 3.1 . 4 / under arthas and extract.
Each time you start detects if a java process, and then enter a number to select the desired diagnostic process. (PS: the principle tool detection process JAVA_HOME $ / bin / JPS the -l - v)
 SH . AS SH --repo-Mirror aliyun          // If the download speed is slower, you can use a mirror aliyun 
SH AS. SH --target- ip 192.168 . 1.9       // specified telnet listening IP 
SH AS. SH -h                            // View more startup configuration 
SH AS. SH PID                           // specify the diagnosis process 

Linux -8ku8: / opt / Arthas # SH . AS SH 
Arthas Script Version: 3.1 . 4
[INFO] JAVA_HOME: /opt/jdk1.8.0_74
[INFO] Process 10528 already using port 3658
[INFO] Process 10528 already using port 8563
Found existing java process, please choose one and hit RETURN.
* [1]: 10528 org.apache.catalina.startup.Bootstrap

[Automatic default download directory]
linux-8ku8:~/.arthas/lib/3.1.4/arthas # ls -lh
total 22M
-rw-r--r-- 1 root root  11M Jun 22 16:13 arthas-3.1.4-bin.zip
-rw-r--r-- 1 root root 8.2K Sep 25  2019 arthas-agent.jar
-rw-r--r-- 1 root root 109K Sep 25  2019 arthas-boot.jar
-rw-r--r-- 1 root root 394K Sep 25  2019 arthas-client.jar
-rw-r--r-- 1 root root  11M Sep 25  2019 arthas-core.jar
-rw-r--r-- 1 root root 3.7K Sep 25  2019 arthas-demo.jar
-rw-r--r-- 1 root root 2.9K Sep 25  2019 arthas-spy.jar
-rwxr-xr-x 1 root root 7.6K Sep 25  2019 as-service.bat
-rwxr-xr-x 1 root root 3.1K Sep 25  2019 as.bat
-rwxr-xr-x 1 root root  28K Sep 25  2019 as.sh
-rwxr-xr-x 1 root root  635 Sep 25  2019 install-local.sh

[Start] success
linux-8ku8:/opt/arthas # sh as.sh
........
  , ---. , ------. , --------., -. -. , ---. , --- .
 / O \ | .--. '' -. .-- ' |  ' - '   | / O \ '    .- '
 | .-. ||  ' - ' . '    | | | .--. || .-. | `. `-. 
| | | || | \ \ | | | | | || | | | .- '     | 
`- ' ` - ' `- '  ' - '    ' - '    ' - '   ' - ' ' - ''
........
[@ Arthas 10528 ] $ Help                    // View help; double tab to see all the commands supported; help COMMAND View detailed help for the specified command 
[@ Arthas 10528 ] $ Exit                    // disconnected, the tool is still running. As.sh may re-enter again performed, or telnet 127.0.0.1 3658 may be reconnectable (which is extremely fast connection) again 
[@ Arthas 10528 ] $ or the shutdown STOP        // closing means

[Installation] Offline
The Arthas - 3.1 . . 4 -bin.zip extract to /root/.arthas/lib/ 3.1 . . 4 / Arthas / directory
Non-root extract to /home/$USER/.arthas/lib/ 3.1 . . 4 / Arthas / directory, a user note file modified is a group
And then start to perform as different user. SH , calls arthas under each user's home directory

[Arthas user documentation]
https://github.com/alibaba/arthas/edit/master/README_CN.md
https://alibaba.github.io/arthas/dashboard

 

Guess you like

Origin www.cnblogs.com/zhangzongjian/p/11790074.html