Arthas command parsing (watch/tt/sc)

Arthas It is an open-source Java diagnostic tool of Alibaba. Arthas supports JDK 6 +, Linux/Mac/Windows, adopts command-line interaction mode, and provides rich Tab automatic completion functions to further facilitate problem location and diagnosis.

Arthas 3.0 uses OGNL expression evaluation library. See OGNL expression official website

Common commands


Function to perform data observation

So that you can easily observe the call of the specified function. The observed range is: return value, throw exception and enter parameter. View the corresponding variables by writing OGNL expression.

Parameter nameParameter description
class-patternClass name expression match
method-patternFunction name matches expression
expressObservation expression, default value: {params, target, returnObj}
condition-expressConditional expression
[b]Observe before function call
[e]Observe after function exception
[s]Observe after the function returns
[f]Observe after the end of the function (normal return and abnormal return)
[E]Enable regular expression matching. The default is wildcard matching
[x:]Specifies the attribute traversal depth of the output result, which is 1 by default

Examples of observing abnormal information

$ watch demo.MathGame primeFactors "{params[0],throwExp}" -e -x 2
Press Ctrl+C to abort.
Affect(class-cnt:1 , method-cnt:1) cost in 62 ms.
ts=2018-12-03 19:38:00; [cost=1.414993ms] result=@ArrayList[
    java.lang.IllegalArgumentException: number is: -1120397038, need >= 2
	at demo.MathGame.primeFactors(
	at demo.MathGame.main(
  • -e means it is triggered when an exception is thrown
  • In express, the variable representing exception information is throwExp

Filter by time

$ watch demo.MathGame primeFactors '{params, returnObj}' '#cost>200' -x 2
Press Ctrl+C to abort.
Affect(class-cnt:1 , method-cnt:1) cost in 66 ms.
ts=2018-12-03 19:40:28; [cost=2112.168897ms] result=@ArrayList[

#Cost > 200 (unit: ms) means that it will be output only when the time is greater than 200ms, and calls with execution time less than 200ms will be filtered out

Description of special parameters:
Special usage:


Method executes the spatiotemporal tunnel of data, records the input and return information of each call of the specified method, and can observe these different time calls

  • -i: Specify a specific index to view the details
  • -t: Each time the print method of the * Test class is executed, it indicates that you want to record.
  • -n: Specify the number of times to be recorded. When the number of times is reached, Arthas will actively interrupt the recording process of tt command to avoid the situation that manual operation cannot be stopped.
  • -p: Redo one call (replay times specifies the number of calls, and replay interval specifies the interval of multiple calls)
  • -w: Observe the spatiotemporal tunnel using ognl expression. Write an expression using all variables in the expression's core variables as known conditions.
Table fieldsField interpretation
INDEXTime segment record number. Each number represents a call. Many subsequent tt commands specify record operations based on this number, which is very important
TIMESTAMPMethod, which records the local time of this time segment
COST(ms)Time consuming method execution
IS-RETWhether the method ends as a normal return
IS-EXPWhether the method ends with an exception thrown
OBJECTExecute the hashCode() of the object. Note that someone once mistakenly thought it was the memory address of the object in the JVM, but unfortunately it was not. But it can help you simply mark the class entity of the current execution method
CLASSClass name of execution
METHODName of method to execute
tt -t com.example.test.CommonInfoService updateInfo -n 5 

Repeat the call with INDEX 1000 twice with an interval of 2000ms

tt -i 1000 -p --replay-times 2 --replay-interval 2000


View the class information loaded by the JVM (sc is the abbreviation of search class)

Parameter nameParameter description
class-patternClass name expression match
method-patternMethod name matches expression
[d]Output the details of the current class, including the source of the original file loaded by this class, the declaration of the class, the loaded ClassLoader and other details. If a class is loaded by multiple classloaders, it will appear multiple times
[E]Enable regular expression matching. The default is wildcard matching
[f]Output the member variable information of the current class (it needs to be used together with the parameter - d)
[x:]Specifies the traversal depth of the property when outputting static variables. The default is 0, that is, toString is directly used for output
[c:]Specifies the hashcode of the ClassLoader of the class
[classLoaderClass:]Specifies the class name of the ClassLoader that executes the expression
[n:]Maximum number of matching classes with details (100 by default)

Class pattern supports fully qualified names, such as com taobao. test. AAA also supports the format of com/taobao/test/AAA. In this way, when we copy the class name from the exception stack, we don't need to manually replace / with la
sc turns on the subclass matching function by default, that is, all subclasses of the current class will be searched out. For accurate matching, please turn on the options disable sub class true switch

//Get classloader hashcode
sc -d *CommonServlet

//Execution method
ognl  -x  3 '@com.example.test.CommonInfoService@updateInfo(new com.example.test.Property())' -c [hashcode]

Common way

Spring Context

//Lower version of spring mvc
tt -t org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter invokeHandlerMethod 
//Higher version of spring mvc
tt -t org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter invokeHandlerMethod

You can use the - i parameter of the tt command to specify the index and the - w parameter to execute the ognl expression to get the spring bean

tt -i 1000 -w 'target.getApplicationContext().getBean("helloWorldService").getHelloMessage()'


In Dubbo, obtain the spring context through the spring extensionfactory and use the corresponding bean
You can use the - i parameter of the tt command to specify the index and the - w parameter to execute the ognl expression to get the spring bean

ognl -x 1 '@org.apache.dubbo.config.spring.extension.SpringExtensionFactory@getContexts()"userServiceImpl").findUser("aaa")'
Can use`tt`Imperative`-i`Parameter index´╝îAnd use`-w`Parameter to execute ognl Expression to get spring bean

reference material:

  1. Arthas user documentation
  2. When DUBBO meets Arthas - Troubleshooting practice
  3. Arthas practice – get Spring Context
  4. Arthas troubleshooting user case
  5. Arthas expression core variable

Keywords: Java Back-end

Added by hasitha on Tue, 22 Feb 2022 06:48:10 +0200