项目总结72:Arthas的常用指令使用

 项目总结72:Arthas的常用指令使用

START

官方文档信息文档信息:https://arthas.aliyun.com/doc/tt.html

启动方法

1. java -jar /usr/lib/arthas-packaging-3.3.2-bin/arthas-boot.jar

[root@kaihu-mngjsinterface-container-57599c47b8-mdvhm arthas-packaging-3.3.2-bin]# java -jar /usr/lib/arthas-packaging-3.3.2-bin/arthas-boot.jar ## 启动Arthas
[INFO] arthas-boot version: 3.3.2
[INFO] Found existing java process, please choose one and input the serial number of the process, eg : 1. Then hit ENTER.
* [1]: 1 noble-metal-assets-statistics.jar
1 ##选择PID
[INFO] arthas home: /usr/lib/arthas-packaging-3.3.2-bin
[INFO] Try to attach process 1
[INFO] Attach process 1 success.
[INFO] arthas-client connect 127.0.0.1 3658
  ,---.  ,------. ,--------.,--.  ,--.  ,---.   ,---.
/  O  \ |  .--. ''--.  .--'|  '--'  | /  O  \ '   .-'
|  .-.  ||  '--'.'   |  |   |  .--.  ||  .-.  |`.  `-.
|  | |  ||  |\  \    |  |   |  |  |  ||  | |  |.-'    |
`--' `--'`--' '--'   `--'   `--'  `--'`--' `--'`-----'
wiki      https://alibaba.github.io/arthas
tutorials https://alibaba.github.io/arthas/arthas-tutorials
version   3.3.2
pid       1
time      2020-09-29 16:32:15

常用命令

    常用指令集合

项目总结72:Arthas的常用指令使用

1. dashboard:查看当前进程的信息

[arthas@1]$ dashboard --help
 USAGE:
   dashboard [-h] [-i <value>] [-n <value>]

 SUMMARY:
   Overview of target jvm's thread, memory, gc, vm, tomcat info.

 EXAMPLES:
   dashboard
   dashboard -n 10
   dashboard -i 2000

 WIKI:
   https://alibaba.github.io/arthas/dashboard

 OPTIONS:
 -h, --help                                               this help
 -i, --interval <value>                                   The interval (in ms) between two executions, default is 5000 ms.
 -n, --number-of-execution <value>                        The number of times this command will be executed.

 项目总结72:Arthas的常用指令使用

    2.thread: 查看当前线程信息,查看线程的堆栈

[arthas@1]$ thread --help
 USAGE:
   thread [-h] [-b] [--lockedMonitors] [--lockedSynchronizers] [-i <value>] [--state <value>] [-n <value>] [id]

 SUMMARY:
   Display thread info, thread stack

 EXAMPLES:
   thread
   thread 51
   thread -n -1
   thread -n 5
   thread -b
   thread -i 2000
   thread --state BLOCKED

 WIKI:
   https://alibaba.github.io/arthas/thread

 OPTIONS:
 -h, --help                                               this help
 -b, --include-blocking-thread                            Find the thread who is holding a lock that blocks the most number of threads.
     --lockedMonitors                                     Find the thread info with lockedMonitors flag, default value is false.
     --lockedSynchronizers                                Find the thread info with lockedSynchronizers flag, default value is false.
 -i, --sample-interval <value>                            Specify the sampling interval (in ms) when calculating cpu usage.
     --state <value>                                      Display the thead filter by the state. NEW, RUNNABLE, TIMED_WAITING, WAITING, BLOCKED, TERMINATED is optional.
 -n, --top-n-threads <value>                              The number of thread(s) to show, ordered by cpu utilization, -1 to show all.
 <id>                                                     Show thread stack

 

项目总结72:Arthas的常用指令使用

3. jad:反编译class文件

[arthas@1]$ jsd --help
java.lang.IllegalArgumentException: jsd: command not found
[arthas@1]$ jad --help
 USAGE:
   jad [-c <value>] [-h] [--hideUnicode] [-E] [--source-only] class-pattern [method-name]

 SUMMARY:
   Decompile class

 EXAMPLES:
   jad java.lang.String
   jad java.lang.String toString
   jad --source-only java.lang.String
   jad -c 39eb305e org/apache/log4j/Logger
   jad -c 39eb305e -E org\\.apache\\.*\\.StringUtils

 WIKI:
   https://alibaba.github.io/arthas/jad

 OPTIONS:
 -c, --code <value>                                       The hash code of the special class's classLoader
 -h, --help                                               this help
     --hideUnicode                                        hide unicode, default value false
 -E, --regex                                              Enable regular expression to match (wildcard matching by default)
     --source-only                                        Output source code only
 <class-pattern>                                          Class name pattern, use either '.' or '/' as separator
 <method-name>                                            method name pattern, decompile a specific method instead of the whole class

 

 项目总结72:Arthas的常用指令使用

4. watch   查看函数返回值

[arthas@1]$ watch --help
 USAGE:
   watch [-b] [-e] [-x <value>] [-f] [-h] [-n <value>] [--listenerId <value>] [-E] [-M <value>] [-s] class-pattern method-pattern [express] [condition-express]

 SUMMARY:
   Display the input/output parameter, return object, and thrown exception of specified method invocation
   The express may be one of the following expression (evaluated dynamically):
           target : the object
            clazz : the object's class
           method : the constructor or method
           params : the parameters array of method
     params[0..n] : the element of parameters array
        returnObj : the returned object of method
         throwExp : the throw exception of method
         isReturn : the method ended by return
          isThrow : the method ended by throwing exception
            #cost : the execution time in ms of method invocation
 Examples:
   watch -b org.apache.commons.lang.StringUtils isBlank params
   watch -f org.apache.commons.lang.StringUtils isBlank returnObj
   watch org.apache.commons.lang.StringUtils isBlank '{params, target, returnObj}' -x 2
   watch -bf *StringUtils isBlank params
   watch *StringUtils isBlank params[0]
   watch *StringUtils isBlank params[0] params[0].length==1
   watch *StringUtils isBlank params '#cost>100'
   watch -E -b org\.apache\.commons\.lang\.StringUtils isBlank params[0]


 OPTIONS:
 -b, --before                                             Watch before invocation
 -e, --exception                                          Watch after throw exception
 -x, --expand <value>                                     Expand level of object (1 by default)
 -f, --finish                                             Watch after invocation, enable by default
 -h, --help                                               this help
 -n, --limits <value>                                     Threshold of execution times
     --listenerId <value>                                 The special listenerId
 -E, --regex                                              Enable regular expression to match (wildcard matching by default)
 -M, --sizeLimit <value>                                  Upper size limit in bytes for the result (10 * 1024 * 1024 by default)
 -s, --success                                            Watch after successful invocation
 <class-pattern>                                          The full qualified class name you want to watch
 <method-pattern>                                         The method name you want to watch
 <express>                                                the content you want to watch, written by ognl.
                                                          Examples:
                                                            params
                                                            params[0]
                                                            'params[0]+params[1]'
                                                            '{params[0], target, returnObj}'
                                                            returnObj
                                                            throwExp
                                                            target
                                                            clazz
                                                            method

 <condition-express>                                      Conditional expression in ognl style, for example:
                                                            TRUE  : 1==1
                                                            TRUE  : true
                                                            FALSE : false
                                                            TRUE  : 'params.length>=0'
                                                            FALSE : 1==2

项目总结72:Arthas的常用指令使用

5.monitor:监控方法执行次数

[arthas@1]$ monitor --help
 USAGE:
   monitor [-c <value>] [-h] [-n <value>] [--listenerId <value>] [-E <value>] class-pattern method-pattern

 SUMMARY:
   Monitor method execution statistics, e.g. total/success/failure count, average rt, fail rate, etc.

 Examples:
   monitor org.apache.commons.lang.StringUtils isBlank
   monitor org.apache.commons.lang.StringUtils isBlank -c 5
   monitor -E org\.apache\.commons\.lang\.StringUtils isBlank

 WIKI:
   https://alibaba.github.io/arthas/monitor

 OPTIONS:
 -c, --cycle <value>                                      The monitor interval (in seconds), 60 seconds by default
 -h, --help                                               this help
 -n, --limits <value>                                     Threshold of execution times
     --listenerId <value>                                 The special listenerId
 -E, --regex <value>                                      Enable regular expression to match (wildcard matching by default)
 <class-pattern>                                          Path and classname of Pattern Matching
 <method-pattern>                                         Method of Pattern Matching

 项目总结72:Arthas的常用指令使用

6.TT: 方法执行数据的时空隧道,记录下指定方法每次调用的入参和返回信息,并能对这些不同的时间下调用进行观测

[arthas@1]$ tt --help
 USAGE:
   tt [-d] [--delete-all] [-x <value>] [-h] [-i <value>] [-n <value>] [-l] [--listenerId <value>] [-p] [-E] [--replay-interval <value>] [--replay-times <value>] [-s <val
 ue>] [-M <value>] [-t] [-w <value>] [class-pattern] [method-pattern] [condition-express]

 SUMMARY:
   Time Tunnel
   The express may be one of the following expression (evaluated dynamically):
           target : the object
            clazz : the object's class
           method : the constructor or method
           params : the parameters array of method
     params[0..n] : the element of parameters array
        returnObj : the returned object of method
         throwExp : the throw exception of method
         isReturn : the method ended by return
          isThrow : the method ended by throwing exception
            #cost : the execution time in ms of method invocation
 EXAMPLES:
   tt -t *StringUtils isEmpty
   tt -t *StringUtils isEmpty params[0].length==1
   tt -l
   tt -i 1000
   tt -i 1000 -w params[0]
   tt -i 1000 -p
   tt -i 1000 -p --replay-times 3 --replay-interval 3000
   tt --delete-all

 WIKI:
   https://alibaba.github.io/arthas/tt

 OPTIONS:
 -d, --delete                                             Delete time fragment specified by index
     --delete-all                                         Delete all the time fragments
 -x, --expand <value>                                     Expand level of object (1 by default)
 -h, --help                                               this help
 -i, --index <value>                                      Display the detailed information from specified time fragment
 -n, --limits <value>                                     Threshold of execution times
 -l, --list                                               List all the time fragments
     --listenerId <value>                                 The special listenerId
 -p, --play                                               Replay the time fragment specified by index
 -E, --regex                                              Enable regular expression to match (wildcard matching by default)
     --replay-interval <value>                            replay interval  for  play tt with option r greater than 1
     --replay-times <value>                               execution times when play tt
 -s, --search-express <value>                             Search-expression, to search the time fragments by ognl express.
                                                          The structure of 'advice' like conditional expression
 -M, --sizeLimit <value>                                  Upper size limit in bytes for the result (10 * 1024 * 1024 by default)
 -t, --time-tunnel                                        Record the method invocation within time fragments
 -w, --watch-express <value>                              watch the time fragment by ognl express.
                                                          Examples:
                                                            params
                                                            params[0]
                                                            'params[0]+params[1]'
                                                            '{params[0], target, returnObj}'
                                                            returnObj
                                                            throwExp
                                                            target
                                                            clazz
                                                            method

 <class-pattern>                                          Path and classname of Pattern Matching
 <method-pattern>                                         Method of Pattern Matching
 <condition-express>                                      Conditional expression in ognl style, for example:
                                                            TRUE  : 1==1
                                                            TRUE  : true
                                                            FALSE : false
                                                            TRUE  : 'params.length>=0'
                                                            FALSE : 1==2

 项目总结72:Arthas的常用指令使用

7.trace:方法内部调用路径,并输出方法路径上的每个节点上耗时

[arthas@1]$ trace --help
 USAGE:
   trace [-h] [-n <value>] [--listenerId <value>] [-p <value>] [-E] [--skipJDKMethod <value>] class-pattern method-pattern [condition-express]

 SUMMARY:
   Trace the execution time of specified method invocation.
   The express may be one of the following expression (evaluated dynamically):
           target : the object
            clazz : the object's class
           method : the constructor or method
           params : the parameters array of method
     params[0..n] : the element of parameters array
        returnObj : the returned object of method
         throwExp : the throw exception of method
         isReturn : the method ended by return
          isThrow : the method ended by throwing exception
            #cost : the execution time in ms of method invocation
 EXAMPLES:
   trace org.apache.commons.lang.StringUtils isBlank
   trace *StringUtils isBlank
   trace *StringUtils isBlank params[0].length==1
   trace *StringUtils isBlank '#cost>100'
   trace -E org\\.apache\\.commons\\.lang\\.StringUtils isBlank
   trace -E com.test.ClassA|org.test.ClassB method1|method2|method3
   trace demo.MathGame run -n 5
   trace demo.MathGame run --skipJDKMethod false

 WIKI:
   https://alibaba.github.io/arthas/trace

 OPTIONS:
 -h, --help                                               this help
 -n, --limits <value>                                     Threshold of execution times
     --listenerId <value>                                 The special listenerId
 -p, --path <value>                                       path tracing pattern
 -E, --regex                                              Enable regular expression to match (wildcard matching by default)
     --skipJDKMethod <value>                              skip jdk method trace, default value true.
 <class-pattern>                                          Class name pattern, use either '.' or '/' as separator
 <method-pattern>                                         Method name pattern
 <condition-express>                                      Conditional expression in ognl style, for example:
                                                            TRUE  : 1==1
                                                            TRUE  : true
                                                            FALSE : false
                                                            TRUE  : 'params.length>=0'
                                                            FALSE : 1==2

 项目总结72:Arthas的常用指令使用

8.火焰图

9.连接问题

  如果只是退出当前的连接,可以用quit或者exit命令。Attach到目标进程上的arthas还会继续运行,端口会保持开放,下次连接时可以直接连接上。   如果想完全退出arthas,可以执行stop命令。  

END

上一篇:Arthas安装与使用及详细基础命令解释


下一篇:你还搞不懂Java如何实现热更新?这样解释你应该能看懂了吧?