What if bugs in production cannot be reproduced in development? What should I do if there are no logs at key locations?
Although we defined exceptions and logging specifications last time, the transformation process is always gradual and there may be some slips
help
In an arthas interactive environment, you can type help and all arthas supported commands will appear. If you don’t know the use of the command, you can type help and then use help as an example to see the use of jad
thread
This command lists all threads in order of CPU usage. If there are too many threads, you can specify the number of output lines with the -n argument and output the current stack information for the thread
If a thread is overloaded, use thread PID to output its stack information
You can also use Thread-B to locate deadlocks, as can JStack
[arthas@26982]$ thread -b
No most blocking thread found!
Copy the code
dashboard
Use dashboard commands to dynamically view the health overviewIf the usage of content is increasing and does not decrease after GC, and gc becomes more frequent later on, it is likely a memory leak.
The heapdump command is used to dump snapshots of the memory, just like jmap
Locate the Controller based on the interface request
Let’s go step by step. The SpringBoot we’re using is essentially a Servlet application, but SpringMVC uses DispatcherServlet to create a unified entry point for requests to be sent to handlers. Let’s keep track of servlets
trace javax.servlet.Servlet *
Copy the code
What is actually distributed to handler is the doDispathch method of the DispatherServlet, which decompiles the code using JAD
jad org.springframework.web.servlet.DispatcherServlet doDispatch
Copy the code
Actually in mappedHandler = getHandler(processedRequest); We’ve got the handler that’s handling the request so we can just get the result of getHandler and see what controller is currently handling the request
watch org.springframework.web.servlet.DispatcherServlet getHandler returnObj
Copy the code
You can directly locate the corresponding handler and method. If you want to see the method content, you can decomcompile it using jad
Watch
Watch targets methods and displays input parameters and return values, allowing you to track the results of each step and get the current value of a variable, just like local single step debugging. In the past, to locate online problems, insufficient information required log printing. To locate problems, you may need to restart the application repeatedly. With Arthas, there is no need to add log printing at all, restart to apply these operations
CHCP 65001 watch command to method for parameter watch cn.com.topsec.ti.assetmanage.controller.AccountController listSecDomByCondition x - 3 - b -x indicates the traversal depth, which can be adjusted to print specific arguments and results. The default value is 1. -b indicates the view before the method is calledCopy the code