This article, based on Arthas 3.5.1, describes how to debug command execution in Arthas in IDEA.
Download the source code
git clone https://github.com/alibaba/arthas.git
Copy the code
After downloading the code, open it with IDEA.
Pack 2.
First, execute the as-package.sh package script and click on the upper right corner of idea to execute the configuration.
Click the green plus sign to create a new bash configuration. Click execute after configuration, as shown below.
1. Failed to pack
As shown in the figure below, you can see that the packaging failed because the packaging arthas-vmtool module is missing g++ because I don’t have a c++ environment on my Windows computer.
You can either install the environment or package it to skip arthas-vmtool. I have chosen to skip the arthas-vmTool module here because it is not currently available. Just modify the contents of the package command script.
Go to line 36 of as-package.sh and change the command to
"$DIR/mvnw" clean package -pl "! arthas-vmtool" -Dmaven.test.skip=true -DskipTests=true -Dmaven.javadoc.skip=true -f $DIR/pom.xml \Copy the code
At the same time toas-package.sh
Line 48, in quotes, will fail in Windows if the user name has a space.
Execute the script again and the packaged content is automatically packaged into the.arthas folder in the user directory.
3. The Debug demonstration
1. Start an example
This uses two jar files, math-game.jar, which is the project’s own test line, and arthas-boot.jar, which starts the arhtas jar file by executing a command.
java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8000 -jar math-game.jar
Copy the code
2. Remote configuration
Remote debug: Add a remote configuration to idea and set the port to be the same as that used when math-Gamejar is executed, as shown in the following figure.
After execution, you can see that the program executing math-game is working properly.
3. Start arthas
Next, execute java-jar arthas-boot.jar and select the process to debug.
4. Start the debug
In the project com.taobao.arthas.core.com mand. Hidden. JulyCommand. Java file on breakpoints, arthas in the implementation of the interface, enter the command out, you can see already the debug came in.
Let go of the breakpoint, continue and you can see that it prints out. It’s an old classic, “Because of You” by Kelly Clarkson.
You can learn more about the arthas command’s parameters and implementation in this way.