I recently found an interesting thing to share with you – Arthas by Ali. Within Alibaba, there are a lot of home-grown tools for developers to use, and one of the tools that almost every Java developer has used is Arthas, a Java diagnostic tool that is incredibly lightening. The tool became open source in September 2018.
From the author: Java introduction to into the grave | link: www.jianshu.com/p/25305a05b…
GitHub address: github.com/alibaba/art…
User documentation: alibaba. Making. IO/arthas
Have you encountered any of the following problems in your daily development:
-
From which JAR is this class loaded? Why are all kinds of class-related exceptions reported?
-
Why didn’t the code I changed execute? Did I not commit? Got the branch wrong?
-
If you encounter a problem, you cannot debug it online. Can you only re-publish it by logging?
-
There is a problem with a user’s data processing online, but it cannot be debugged online, and it cannot be reproduced offline!
-
Is there a global view of the health of the system?
-
Is there any way to monitor the real-time health of the JVM?
Arthas can diagnose all of these problems!! Isn’t it nice and powerful?
Arthas supports JDK 6+, command line interaction, and rich Tab completion functionality to further locate and diagnose problems.
Arthas installation
1. Install arthas-boot
Download arthas-boot.jar and start it with java-jar:
Print help information:
If the download speed is slow, you can use aliyun’s image:
2. Use as.sh to install
Arthas supports one-click installation on Linux/Unix/Mac platforms. Please copy and paste the following contents into the command line and press Enter to execute:
The above command will download the startup script file as.sh to the current directory, which you can place anywhere or add to $PATH.
Run./as.sh directly under the shell to enter the interface.
You can also run the./as.sh -h command to obtain more parameter information.
Quick start
1. Start the Demo
Arthas-demo is a simple program that generates a random number every second, performs a factorization, and prints out the factorization.
2. Start arthas
Execute from the command line:
The user executing the program needs to have the same permissions as the target process. For example, run the sudo su admin && Java -jar arthas-boot.jar command or sudo -u admin -eh Java -jar arthas-boot.jar command as the admin user.
If attatch is not on the target process, look at the logs under ~/logs/arthas/.
If the download is slow, you can use aliyun’s image: Java -jar arthas-boot.jar –repo-mirror aliyun –use-http
Java -jar arthas-boot.jar -h Displays more parameters.
Select apply Java process:
If the Demo process is the second one, enter 2 and enter/Enter. Arthas attaches to the target process and prints a log:
3. Check the dashboard
Input Dashboard and press Enter/Enter to display the current process information. Press CTRL + C to interrupt the execution.
4. Run the sysenv command to obtain the Main Class of the process
5. Use jad to reverse edit Main Class
6. watch
Use the watch command to view the return value of demo.MathGame#primeFactors:
5. Quit arthas
To exit the current connection, use the quit or exit command. Arthas attached to the target process will continue to run and the port will remain open for direct connection next time.
If you want to exit Arthas completely, you can execute the shutdown command.
Common commands
Basic commands
Help — View the command help information
CLS — Clears the current screen area
Session — View information about the current session
Reset — Resets enhanced classes. This will restore all Arthas enhanced classes and reset all enhanced classes when Arthas server is closed
Version – Prints the Arthas version number loaded by the current target Java process
Quit — Exit the current Arthas client, leaving other Arthas clients unaffected
Shutdown — shutdown the Arthas server and exit all Arthas clients
Keymap — Arthas list of shortcuts and custom shortcuts
** JVM related **
Dashboard – Real-time data panel for the current system
Thread – Views the thread stack information for the current JVM
JVM – View information about the current JVM
Sysprop – View and modify system properties of the JVM
New! Getstatic — View the static properties of the class
The class/this correlation
- Sc – View information about classes loaded by the JVM
- Sm — View method information for loaded classes
- Dump — Dumps loaded class byte code to a specific directory
- Re-define — Load an external. Class file, re-define it into the JVM
- Jad – Decompiles the source code of a loaded class
Classloader – view the classloader inheritance tree, urls, class loading information, and use classloader to getResource
Monitor/watch/trace
- Monitor — method performs monitoring
- Watch – method performs data observations
- Trace — calls to the method internally and prints the time spent on each node on the method path
- Stack – Outputs the call path where the current method is called
- Tt – time tunnel of method execution data, recording input and return information for each call to the specified method, and observing these different time calls
Please note that these commands, through the bytecode enhancement technology to realize, will insert some aspects in the specified class methods to implement the data statistics and observation, so online, use pretest, please try to clear need classes, methods and conditions for observation, diagnosis end to perform shutdown or class that will enhance the reset command.
options
Options — View or set the Arthas global switch
The pipe
Arthas supports the use of pipes for further processing, the results of the above command such as sm org.. Apache log4j. Logger | grep
- Grep — Searches for results that meet the criteria
- Plaintext — Removes color from the result of a command
- Wc — Count the output by row
So that’s Arthas in a nutshell, but to really understand Arthas as a problem solving tool, you need to get your hands dirty. Practice is the mother of knowledge.
### Read more
Here are 10 great open source projects
Android Interview (with answers)
The boss said our APP package was too big
Android Quick Start – optimal solution for black and white screen
Android screen compatibility, version compatibility and multi-language support
Believe in yourself, there is nothing impossible, only unexpected
It’s not just technology that’s gained here!