Installation and basic use of Arthas

background

When developing projects, you often encounter the following scenarios:

  1. Which jar package is this class loaded from? Why are various types of Exceptions reported?
  2. Why is the code I changed not executed? Could it be that I didn't commit? Wrong branch?
  3. If you encounter a problem and cannot debug it online, can you only add logs and re-release it?
  4. There is a problem with a user's data processing online, but it cannot be debugged online and cannot be reproduced offline!
  5. Is there a global view of how the system is performing?
  6. Is there any way to monitor the real-time running status of the JVM?
  7. How to quickly locate application hot spots and generate flame graphs?
  8. How to find an instance of a class directly from the JVM?

At this time, we can use Arthas to solve the above problem.
Official documentation of Arthas: Arthas usage instructions

Install

Because Arthas is a project written by Spring boot, when installing and using it, we only need to download the corresponding jar package, and then use java -jar to run the project.

curl -O https://arthas.aliyun.com/arthas-boot.jar

When executing the above jar package, we must first run a java process in the memory, otherwise there will be an error that the java process cannot be found [!!#ff0000 You can use jps to view the processes running on the system!!]

java -jar arthas-boot.jar

Simple to use

1. thread

Use the thread command to view the thread stack information of the current JVM.
Insert image description here
You need to use the command with parameters, which can be spliced ​​later.

parameter name Parameter Description
number Thread id
[n:] Find the top N busiest threads and print the stack
[b] Find the thread currently blocking other threads
[i] Specify the sampling interval for CPU ratio statistics, in milliseconds
thred -n 3
thread -b 

Insert image description here

2. jad

When we want to know whether an online branch has its own code, we can decompile it through the jad command

jad 类全路径名

![

3. monitor

Function: Monitor the execution of methods in the specified class.
For classes matching class-pattern / method-pattern, repeatedly call to monitor. The
monitor command is a non-real-time return command. It continuously waits for the target java process to return information until the user enters Ctrl + C. until

monitor 类全路径名 方法名  -n 监控次数 --cycle 间隔采样的时间[单位s]

Insert image description here

4. watch

Observe the calling status of the specified method.
Method execution data rules allow you to easily observe the calling status of the specified method.
The scope of observation is: return value, throwing exception, entering parameters, and viewing variables by writing ONGL expressions.

watch 类名 方法名 '{params,returnObj,throwExp}'  -n 5  -x 3

'{params,returnObj,throwExp}' here is a type of so-called ognl expression, which indicates the need to output parameters, return values, and throw exceptions

Insert image description here

5. trace

Trace is to track the calling path within the method and output the time consumption of each node on the method path.

Parameter Description

parameter name Parameter Description
class-pattern class name expression
method-pattern method name expression
condition-express Conditional expression, default is wildcard matching
[E] Enable regular expression matching. The default is wildcard matching.
[n:] Set the number of command execution times
#cost Method execution time, unit is milliseconds
trace 类名 方法名 调用次数 限制条件

Insert image description here

A brief introduction to the Arthas Idea plug-in

The above briefly introduces some common commands of Arthas. During normal development, we can completely use some compiler plug-ins without typing commands by hand.
Insert image description here
Simple use
After enabling the plug-in, we can modify it with some common commands
Insert image description here
Insert image description here

Guess you like

Origin blog.csdn.net/TheWindOfSon/article/details/135292739