diff --git a/README.html b/README.html index 5bb85eae5..9c8863b19 100644 --- a/README.html +++ b/README.html @@ -32,6 +32,7 @@ + @@ -93,7 +94,7 @@
.class文件,redefine到JVM里-+请注意,这些命令,都通过字节码增强技术来实现的,会在指定类的方法中插入一些切面来实现数据统计和观测,因此在线上、预发使用时,请尽量明确需要观测的类、方法以及条件,诊断结束要执行shutdown或将增强过的类执行reset命令。
Arthas支持使用管道对上述命令的结果进行进一步的处理,如sm org.apache.log4j.Logger | grep <init>
Arthas支持使用管道对上述命令的结果进行进一步的处理,如sm org.apache.log4j.Logger | grep
无论是匹配表达式也好、观察表达式也罢,他们核心判断变量都是围绕着一个 Arthas 中的通用通知对象 Advice 进行。
无论是匹配表达式也好、观察表达式也罢,他们核心判断变量都是围绕着一个 Arthas 中的通用通知对象 Advice 进行。
它的简略代码结构如下
-public class Advice {
+public class Advice {
- private final ClassLoader loader;
- private final Class<?> clazz;
- private final ArthasMethod method;
- private final Object target;
- private final Object[] params;
- private final Object returnObj;
- private final Throwable throwExp;
- private final boolean isBefore;
- private final boolean isThrow;
- private final boolean isReturn;
+ private final ClassLoader loader;
+ private final Class<?> clazz;
+ private final ArthasMethod method;
+ private final Object target;
+ private final Object[] params;
+ private final Object returnObj;
+ private final Throwable throwExp;
+ private final boolean isBefore;
+ private final boolean isThrow;
+ private final boolean isReturn;
- // getter/setter
-}
+ // getter/setter
+}
这里列一个表格来说明不同变量的含义
@@ -235,7 +236,7 @@
辅助判断标记,当前的方法调用以正常返回的形式结束。
-所有变量都可以在表达式中直接使用,如果在表达式中编写了不符合 OGNL 脚本语法或者引入了不在表格中的变量,则退出命令的执行;用户可以根据当前的异常信息修正条件表达式或观察表达式
+所有变量都可以在表达式中直接使用,如果在表达式中编写了不符合 OGNL 脚本语法或者引入了不在表格中的变量,则退出命令的执行;用户可以根据当前的异常信息修正条件表达式或观察表达式
groovy表达式在arthas2.0中大量使用,例如watch表达式
-watch com.alibaba.sample.petstore.web.store.module.screen.ItemList add "params + ' ' + returnObj" params.size()==2
+watch com.alibaba.sample.petstore.web.store.module.screen.ItemList add "params + ' ' + returnObj" params.size()==2
-其中"params + ' ' + returnObj"以及params.size()==2背后其实都使用了groovy来进行表达式求值,如果反复大量的运行这些表达式,groovy会创建大量的classloader,打满perm区从而触发FGC。
+其中"params + ' ' + returnObj"以及params.size()==2背后其实都使用了groovy来进行表达式求值,如果反复大量的运行这些表达式,groovy会创建大量的classloader,打满perm区从而触发FGC。
为了避免这个问题,Arthas 3.0中使用了ognl这个更加轻量的表达式求值库来代替groovy,彻底解决了groovy引起的FGC风险。但由于这个替换,导致原来使用groovy脚本编写的自定义脚本失效。这个问题留待后续解决。
在3.0中,watch命令的表达式部分的书写有了一些改变,详见这里
提升rt统计精度¶
-Arthas 2.0中,统计rt都是以ms为单位,对于某些比较小的方法调用,耗时在毫秒以下的都会被认为是0ms,造成trace总时间和各方法的时间相加不一致等问题(虽然这里面确实会有误差,主要Arthas自身的开销)。Arthas 3.0中所有rt的单位统一改为使用ns来统计,精准捕获你的方法耗时,让0ms这样无意义的统计数据不再出现!
-$ tt -l
+Arthas 2.0中,统计rt都是以ms为单位,对于某些比较小的方法调用,耗时在毫秒以下的都会被认为是0ms,造成trace总时间和各方法的时间相加不一致等问题(虽然这里面确实会有误差,主要Arthas自身的开销)。Arthas 3.0中所有rt的单位统一改为使用ns来统计,精准捕获你的方法耗时,让0ms这样无意义的统计数据不再出现!
+$ tt -l
INDEX TIMESTAMP COST(ms) IS-RET IS-EXP OBJECT CLASS METHOD
------------------------------------------------------------------------------------------------------------------------------------------------------------
1000 2017-02-24 10:56:46 808.743525 true false 0x3bd5e918 TestTraceServlet doGet
@@ -203,18 +204,17 @@
1002 2017-02-24 10:57:04 808.026935 true false 0x3bd5e918 TestTraceServlet doGet
1003 2017-02-24 10:57:22 805.036963 true false 0x3bd5e918 TestTraceServlet doGet
1004 2017-02-24 10:57:24 803.581886 true false 0x3bd5e918 TestTraceServlet doGet
- 1005 2017-02-24 10:57:39 814.657657 true false 0x3bd5e918 TestTraceServlet doGet
-
+ 1005 2017-02-24 10:57:39 814.657657 true false 0x3bd5e918 TestTraceServlet doGet
watch/stack/trace命令支持按耗时过滤¶
-我们在trace的时候,经常会出现某个方法间隙性的rt飙高,但是我们只想知道rt高的时候,是哪里慢了,对于正常rt的方法我们并不关心,Arthas 3.0支持了按#cost(方法执行耗时,单位为ms)进行过滤,只输出符合条件的trace路径,目前,这三个命令的相关文档已经做了更新,增加了该用法的示例。
+我们在trace的时候,经常会出现某个方法间隙性的rt飙高,但是我们只想知道rt高的时候,是哪里慢了,对于正常rt的方法我们并不关心,Arthas 3.0支持了按#cost(方法执行耗时,单位为ms)进行过滤,只输出符合条件的trace路径,目前,这三个命令的相关文档已经做了更新,增加了该用法的示例。
sysprop命令操作SystemProperty¶
sysprop命令支持查看所有的系统属性,以及针对特定属性进行查看和修改。
-$ sysprop
+$ sysprop
...
os.arch x86_64
java.ext.dirs /Users/wangtao/Library/Java/Extensions:/Library/Java/JavaVirtualMachines/jdk1.
@@ -234,14 +234,13 @@ $ sysprop java.version
java.version=1.8.0_51
$ sysprop production.mode true
Successfully changed the system property.
-production.mode=true
-
+production.mode=true
thread命令支持指定采样时间¶
-thread命令计算线程cpu占用的逻辑,默认是采样100ms内各个线程的cpu使用情况并计算cpu消耗占比。有时候100ms的时间间隔太短,看不出问题所在,Arthas3.0中thread命令支持设置采样间隔(以ms为单位),可以观察任意时间段内的cpu消耗占比情况。
-$ thread -i 1000
+thread命令计算线程cpu占用的逻辑,默认是采样100ms内各个线程的cpu使用情况并计算cpu消耗占比。有时候100ms的时间间隔太短,看不出问题所在,Arthas3.0中thread命令支持设置采样间隔(以ms为单位),可以观察任意时间段内的cpu消耗占比情况。
+$ thread -i 1000
Threads Total: 74, NEW: 0, RUNNABLE: 17, BLOCKED: 0, WAITING: 15, TIMED_WAITING: 42, TERMINATED: 0
ID NAME GROUP PRIORITY STATE %CPU TIME INTERRUPTED DAEMON
78 com.taobao.config.client.timer main 5 TIMED_WAITING 22 0:0 false true
@@ -257,8 +256,7 @@ ID NAME GROU
345 nioEventLoopGroup-3-3 system 10 RUNNABLE 2 0:0 false false
358 nioEventLoopGroup-3-4 system 10 RUNNABLE 2 0:0 false false
27 qos-boss-1-1 main 5 RUNNABLE 2 0:0 false true
-22 EagleEye-AsyncAppender-Thread-BizLog main 5 TIMED_WAITING 1 0:0 false true
-
+22 EagleEye-AsyncAppender-Thread-BizLog main 5 TIMED_WAITING 1 0:0 false true
@@ -332,6 +330,15 @@ ID NAME GROU
+
+
+
+
+
@@ -93,7 +94,7 @@
- 进阶使用
- 命令列表
- 用户案例
-- Questions and answers
+- 常见问题
- Fork me at GitHub
- 参与贡献
- Release Notes
@@ -166,7 +167,7 @@
Arthas 3.0新特性介绍¶
-Arthas 3.0在架构上做了重大改造,通过引入termd完整的支持了telnet协议,并基于websocket封装了telnet协议实现了Telnet over HTTP,使得在线诊断成为了可能,并且保证了本地启动,telnet远程访问,在线诊断三种方式的体验完全一致。都支持自动补全,高亮显示等功能。并且支持多人同时在线诊断。
+Arthas 3.0在架构上做了重大改造,通过引入termd完整的支持了telnet协议,并基于websocket封装了telnet协议实现了Telnet over HTTP,使得在线诊断成为了可能,并且保证了本地启动,telnet远程访问,在线诊断三种方式的体验完全一致。都支持自动补全,高亮显示等功能。并且支持多人同时在线诊断。
在线诊断¶
Arthas 3.0最重要的特性,通过Arthas在线诊断平台,无需再登陆目标机器,一键启动Arthas并开启诊断!
@@ -175,53 +176,52 @@
管道支持¶
-Arthas 3.0开始支持管道, 率先提供了grep,wc,plaintext的支持。
- java.vendor.url http://java.oracle.com/
+Arthas 3.0开始支持管道, 率先提供了grep,wc,plaintext的支持。
+ java.vendor.url http://java.oracle.com/
java.vm.vendor Oracle Corporation
- java.runtime.name Java(TM) SE Runtime Environment
+ java.runtime.name Java(TM) SE Runtime Environment
sun.java.command org.apache.catalina.startup.Bootstrap start
java.class.path /Users/wangtao/work/ali-tomcat-home/ant-develop/output/build/bin/bootstrap.jar
java.vm.specification.name Java Virtual Machine Specification
- java.vm.specification.version 1.8
- java.awt.headless true
+ java.vm.specification.version 1.8
+ java.awt.headless true
java.io.tmpdir /Users/wangtao/work/ali-tomcat-home/ant-develop/output/build/temp
java.vendor.url.bug http://bugreport.sun.com/bugreport/
java.awt.graphicsenv sun.awt.CGraphicsEnvironment
java.ext.dirs /Users/wangtao/Library/Java/Extensions:/Library/Java/JavaVirtualMachines/jdk1.
/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java
- java.vm.name Java HotSpot(TM) 64-Bit Server VM
- java.specification.version 1.8
-$ sysprop | grep java | wc -l
-36
+ java.vm.name Java HotSpot(TM) 64-Bit Server VM
+ java.specification.version 1.8
+$ sysprop | grep java | wc -l
+36
启动自检¶
针对启动时经常出现的权限问题,在启动脚本中增加了自检逻辑,脚本会自动判断目标进程是否具备attach权限,并给出进一步的提示。
-[huxing.zhx@v125056161.bja /home/huxing.zhx]
+[huxing.zhx@v125056161.bja /home/huxing.zhx]
$./as.sh 32260
The current user (huxing.zhx) does not match with the owner of process 32260 (admin).
To solve this, choose one of the following command:
1) sudo su admin && ./as.sh
- 2) sudo -u admin -EH ./as.sh
-
+ 2) sudo -u admin -EH ./as.sh
去groovy依赖¶
groovy表达式在arthas2.0中大量使用,例如watch表达式
-watch com.alibaba.sample.petstore.web.store.module.screen.ItemList add "params + ' ' + returnObj" params.size()==2
+watch com.alibaba.sample.petstore.web.store.module.screen.ItemList add "params + ' ' + returnObj" params.size()==2
-其中"params + ' ' + returnObj"以及params.size()==2背后其实都使用了groovy来进行表达式求值,如果反复大量的运行这些表达式,groovy会创建大量的classloader,打满perm区从而触发FGC。
+其中"params + ' ' + returnObj"以及params.size()==2背后其实都使用了groovy来进行表达式求值,如果反复大量的运行这些表达式,groovy会创建大量的classloader,打满perm区从而触发FGC。
为了避免这个问题,Arthas 3.0中使用了ognl这个更加轻量的表达式求值库来代替groovy,彻底解决了groovy引起的FGC风险。但由于这个替换,导致原来使用groovy脚本编写的自定义脚本失效。这个问题留待后续解决。
在3.0中,watch命令的表达式部分的书写有了一些改变,详见这里
提升rt统计精度¶
-Arthas 2.0中,统计rt都是以ms为单位,对于某些比较小的方法调用,耗时在毫秒以下的都会被认为是0ms,造成trace总时间和各方法的时间相加不一致等问题(虽然这里面确实会有误差,主要Arthas自身的开销)。Arthas 3.0中所有rt的单位统一改为使用ns来统计,精准捕获你的方法耗时,让0ms这样无意义的统计数据不再出现!
-$ tt -l
+Arthas 2.0中,统计rt都是以ms为单位,对于某些比较小的方法调用,耗时在毫秒以下的都会被认为是0ms,造成trace总时间和各方法的时间相加不一致等问题(虽然这里面确实会有误差,主要Arthas自身的开销)。Arthas 3.0中所有rt的单位统一改为使用ns来统计,精准捕获你的方法耗时,让0ms这样无意义的统计数据不再出现!
+$ tt -l
INDEX TIMESTAMP COST(ms) IS-RET IS-EXP OBJECT CLASS METHOD
------------------------------------------------------------------------------------------------------------------------------------------------------------
1000 2017-02-24 10:56:46 808.743525 true false 0x3bd5e918 TestTraceServlet doGet
@@ -229,19 +229,17 @@ To solve this, choose one of the following command:
1002 2017-02-24 10:57:04 808.026935 true false 0x3bd5e918 TestTraceServlet doGet
1003 2017-02-24 10:57:22 805.036963 true false 0x3bd5e918 TestTraceServlet doGet
1004 2017-02-24 10:57:24 803.581886 true false 0x3bd5e918 TestTraceServlet doGet
- 1005 2017-02-24 10:57:39 814.657657 true false 0x3bd5e918 TestTraceServlet doGet
-
+ 1005 2017-02-24 10:57:39 814.657657 true false 0x3bd5e918 TestTraceServlet doGet
watch/stack/trace命令支持按耗时过滤¶
-我们在trace的时候,经常会出现某个方法间隙性的rt飙高,但是我们只想知道rt高的时候,是哪里慢了,对于正常rt的方法我们并不关心,Arthas 3.0支持了按#cost(方法执行耗时,单位为ms)进行过滤,只输出符合条件的trace路径。
+我们在trace的时候,经常会出现某个方法间隙性的rt飙高,但是我们只想知道rt高的时候,是哪里慢了,对于正常rt的方法我们并不关心,Arthas 3.0支持了按#cost(方法执行耗时,单位为ms)进行过滤,只输出符合条件的trace路径。
具体用法为:
-trace/watch/stack class_name method cost_expression
-
+trace/watch/stack class_name method cost_expression
例如:
-$ trace test.arthas.TestTraceServlet doGet #cost>800
+$ trace test.arthas.TestTraceServlet doGet #cost>800
Press Ctrl+C to abort.
Affect(class-cnt:1 , method-cnt:1) cost in 137 ms.
trace test.arthas.TestTraceServlet doGet #cost>800
@@ -263,10 +261,9 @@ trace test.arthas.TestTraceServlet doGet #cost>800
+---[0.013107ms] java.lang.StringBuilder:<init>()
+---[min=0.004892ms,max=0.06357ms,total=0.100672ms,count=3] java.lang.StringBuilder:append()
+---[0.018255ms] java.lang.StringBuilder:toString()
- `---[0.028812ms] java.io.PrintWriter:write()
-
+ `---[0.028812ms] java.io.PrintWriter:write()
-上述命令只有当test.arthas.TestTraceServlet#doGet方法执行耗时大于800ms时才会输出。
+上述命令只有当test.arthas.TestTraceServlet#doGet方法执行耗时大于800ms时才会输出。
trace命令优化¶
@@ -282,16 +279,15 @@ trace test.arthas.TestTraceServlet doGet #cost>800
显示当前线程的信息及eagleeye的traceId¶
-trace test.arthas.TestTraceServlet doGet
-`---thread_name=http-bio-8080-exec-10;id=da;is_daemon=true;priority=5;TCCL=org.apache.catalina.loader.WebappClassLoader;trace_id=1e09489014879085429791006d969d
-
+trace test.arthas.TestTraceServlet doGet
+`---thread_name=http-bio-8080-exec-10;id=da;is_daemon=true;priority=5;TCCL=org.apache.catalina.loader.WebappClassLoader;trace_id=1e09489014879085429791006d969d
sysprop命令操作SystemProperty¶
sysprop命令支持查看所有的系统属性,以及针对特定属性进行查看和修改。
-$ sysprop
+$ sysprop
...
os.arch x86_64
java.ext.dirs /Users/wangtao/Library/Java/Extensions:/Library/Java/JavaVirtualMachines/jdk1.
@@ -311,14 +307,13 @@ $ sysprop java.version
java.version=1.8.0_51
$ sysprop production.mode true
Successfully changed the system property.
-production.mode=true
-
+production.mode=true
thread命令支持指定采样时间¶
-thread命令计算线程cpu占用的逻辑,默认是采样100ms内各个线程的cpu使用情况并计算cpu消耗占比。有时候100ms的时间间隔太短,看不出问题所在,Arthas3.0中thread命令支持设置采样间隔(以ms为单位),可以观察任意时间段内的cpu消耗占比情况。
-$ thread -i 1000
+thread命令计算线程cpu占用的逻辑,默认是采样100ms内各个线程的cpu使用情况并计算cpu消耗占比。有时候100ms的时间间隔太短,看不出问题所在,Arthas3.0中thread命令支持设置采样间隔(以ms为单位),可以观察任意时间段内的cpu消耗占比情况。
+$ thread -i 1000
Threads Total: 74, NEW: 0, RUNNABLE: 17, BLOCKED: 0, WAITING: 15, TIMED_WAITING: 42, TERMINATED: 0
ID NAME GROUP PRIORITY STATE %CPU TIME INTERRUPTED DAEMON
78 com.taobao.config.client.timer main 5 TIMED_WAITING 22 0:0 false true
@@ -334,8 +329,7 @@ ID NAME GROU
345 nioEventLoopGroup-3-3 system 10 RUNNABLE 2 0:0 false false
358 nioEventLoopGroup-3-4 system 10 RUNNABLE 2 0:0 false false
27 qos-boss-1-1 main 5 RUNNABLE 2 0:0 false true
-22 EagleEye-AsyncAppender-Thread-BizLog main 5 TIMED_WAITING 1 0:0 false true
-
+22 EagleEye-AsyncAppender-Thread-BizLog main 5 TIMED_WAITING 1 0:0 false true
@@ -404,6 +398,15 @@ ID NAME GROU
+
+
+
+
+
@@ -121,7 +122,7 @@
- 命令列表
- 用户案例
-- Questions and answers
+- 常见问题
- Fork me at GitHub
- 参与贡献
- Release Notes
@@ -200,7 +201,7 @@
1. 使用&在后台执行任务¶
比如希望执行后台执行trace命令,那么调用下面命令
-trace Test t &
+trace Test t &
这时命令在后台执行,可以在console中继续执行其他命令。
@@ -208,18 +209,18 @@
2. 通过jobs查看任务¶
如果希望查看当前有哪些arthas任务在执行,可以执行jobs命令,执行结果如下
-$ jobs
-[10]*
- Stopped watch com.taobao.container.Test test "params[0].{? #this.name == null }" -x 2
- execution count : 19
- start time : Fri Sep 22 09:59:55 CST 2017
- timeout date : Sat Sep 23 09:59:55 CST 2017
- session : 3648e874-5e69-473f-9eed-7f89660b079b (current)
+$ jobs
+[10]*
+ Stopped watch com.taobao.container.Test test "params[0].{? #this.name == null }" -x 2
+ execution count : 19
+ start time : Fri Sep 22 09:59:55 CST 2017
+ timeout date : Sat Sep 23 09:59:55 CST 2017
+ session : 3648e874-5e69-473f-9eed-7f89660b079b (current)
可以看到目前有一个后台任务在执行。
-- job id是10,
* 表示此job是当前session创建
+- job id是10, * 表示此job是当前session创建
- 状态是Stopped
- execution count是执行次数,从启动开始已经执行了19次
- timeout date是超时的时间,到这个时间,任务将会自动超时退出
@@ -227,9 +228,9 @@
3. 任务暂停和取消¶
-当任务正在前台执行,比如直接调用命令trace Test t或者调用后台执行命令trace Test t &后又通过fg命令将任务转到前台。这时console中无法继续执行命令,但是可以接收并处理以下事件:
+当任务正在前台执行,比如直接调用命令trace Test t或者调用后台执行命令trace Test t &后又通过fg命令将任务转到前台。这时console中无法继续执行命令,但是可以接收并处理以下事件:
-- ‘ctrl + z’:将任务暂停。通过
jbos查看任务状态将会变为Stopped,通过bg <job-id>或者fg <job-id>可让任务重新开始执行
+- ‘ctrl + z’:将任务暂停。通过jbos查看任务状态将会变为Stopped,通过bg
或者fg 可让任务重新开始执行
- ‘ctrl + c’:停止任务
- ‘ctrl + d’:按照linux语义应当是退出终端,目前arthas中是空实现,不处理
@@ -237,25 +238,25 @@
4. fg、bg命令,将命令转到前台、后台继续执行¶
-- 任务在后台执行或者暂停状态(
ctrl + z暂停任务)时,执行fg <job-id>将可以把对应的任务转到前台继续执行。在前台执行时,无法在console中执行其他命令
-- 当任务处于暂停状态时(
ctrl + z暂停任务),执行bg <job-id>将可以把对应的任务在后台继续执行
+- 任务在后台执行或者暂停状态(ctrl + z暂停任务)时,执行fg
将可以把对应的任务转到前台继续执行。在前台执行时,无法在console中执行其他命令
+- 当任务处于暂停状态时(ctrl + z暂停任务),执行bg
将可以把对应的任务在后台继续执行
- 非当前session创建的job,只能由当前session fg到前台执行
5. 任务输出重定向¶
-可通过>或者>>将任务输出结果输出到指定的文件中,可以和&一起使用,实现arthas命令的异步调用。比如:
-$ trace Test t >> test.out &
+可通过>或者>>将任务输出结果输出到指定的文件中,可以和&一起使用,实现arthas命令的异步调用。比如:
+$ trace Test t >> test.out &
这时trace命令会在后台执行,并且把结果输出到~/logs/arthas-cache/test.out。可继续执行其他命令。并可查看文件中的命令执行结果。
当连接到远程的arthas server时,可能无法查看远程机器的文件,arthas同时支持了自动重定向到本地缓存路径。使用方法如下:
-$ trace Test t >> &
-job id : 2
+$ trace Test t >> &
+job id : 2
cache location : /Users/gehui/logs/arthas-cache/28198/2
-可以看到并没有指定重定向文件位置,arthas自动重定向到缓存中了,执行命令后会输出job id和cache location。cache location就是重定向文件的路径,在系统logs目录下,路径包括pid和job id,避免和其他任务冲突。命令输出结果到/Users/gehui/logs/arthas-cache/28198/2中,job id为2。
+可以看到并没有指定重定向文件位置,arthas自动重定向到缓存中了,执行命令后会输出job id和cache location。cache location就是重定向文件的路径,在系统logs目录下,路径包括pid和job id,避免和其他任务冲突。命令输出结果到/Users/gehui/logs/arthas-cache/28198/2中,job id为2。
6. 停止命令¶
@@ -343,6 +344,15 @@ cache location : /Users/gehui/logs/arthas-cache/28198/2
+
+
+
+
+
@@ -115,7 +116,7 @@
- 命令列表
- 用户案例
-- Questions and answers
+- 常见问题
- Fork me at GitHub
- 参与贡献
- Release Notes
@@ -196,35 +197,34 @@
使用方法¶
第一步: 创建你的批处理脚本¶
-这里我们新建了一个test.as脚本,为了规范,我们采用了.as后缀名,但事实上任意的本文文件都ok。
+这里我们新建了一个test.as脚本,为了规范,我们采用了.as后缀名,但事实上任意的本文文件都ok。
注意事项
- 目前需要每个命令占一行
-- dashboard务必开启批处理模式(
-b),指定执行次数(-n),否则会导致批处理脚本无法终止
-- watch/tt/trace/monitor/stack等命令务必指定执行次数(
-n),否则会导致批处理脚本无法终止
-- 可以使用异步后台任务,如
watch c.t.X test returnObj > &,让命令一直在后台运行,通过日志获取结果,获取更多异步任务的信息
+- dashboard务必开启批处理模式(-b),指定执行次数(-n),否则会导致批处理脚本无法终止
+- watch/tt/trace/monitor/stack等命令务必指定执行次数(-n),否则会导致批处理脚本无法终止
+- 可以使用异步后台任务,如 watch c.t.X test returnObj > &,让命令一直在后台运行,通过日志获取结果,获取更多异步任务的信息
-➜ arthas git:(develop) cat /var/tmp/test.as
+➜ arthas git:(develop) cat /var/tmp/test.as
help
dashboard -b -n 1
session
thread
-sc -d org.apache.commons.lang.StringUtils
-
+sc -d org.apache.commons.lang.StringUtils
第二步: 运行你的批处理脚本¶
-通过-b开启批处理模式, -f执行脚本文件, 批处理脚本默认会输出到标准输出中,可以将结果重定向到文件中。
-./as.sh -b -f /var/tmp/test.as 56328 > test.out
+通过-b开启批处理模式, -f执行脚本文件, 批处理脚本默认会输出到标准输出中,可以将结果重定向到文件中。
+./as.sh -b -f /var/tmp/test.as 56328 > test.out
第三步: 查看运行结果¶
-cat test.out
+cat test.out
@@ -304,6 +304,15 @@ sc -d org.apache.commons.lang.StringUtils
+
+
+
+
+
@@ -129,7 +130,7 @@
- 用户案例
-- Questions and answers
+- 常见问题
- Fork me at GitHub
- 参与贡献
- Release Notes
@@ -206,8 +207,8 @@
classloader¶
查看classloader的继承树,urls,类加载信息
-classloader 命令将 JVM 中所有的classloader的信息统计出来,并可以展示继承树,urls等。
-可以让指定的classloader去getResources,打印出所有查找到的resources的url。对于ResourceNotFoundException比较有用。
+classloader 命令将 JVM 中所有的classloader的信息统计出来,并可以展示继承树,urls等。
+可以让指定的classloader去getResources,打印出所有查找到的resources的url。对于ResourceNotFoundException比较有用。
参数说明¶
@@ -248,87 +249,87 @@
使用参考¶
按类加载类型查看统计信息¶
-$ classloader
+$ classloader
name numberOfInstances loadedCountTotal
- com.taobao.arthas.agent.ArthasClassloader 1 2115
- BootstrapClassLoader 1 1861
- sun.reflect.DelegatingClassLoader 5 5
- sun.misc.Launcher$AppClassLoader 1 4
- sun.misc.Launcher$ExtClassLoader 1 1
-Affect(row-cnt:5) cost in 3 ms.
+ com.taobao.arthas.agent.ArthasClassloader 1 2115
+ BootstrapClassLoader 1 1861
+ sun.reflect.DelegatingClassLoader 5 5
+ sun.misc.Launcher$AppClassLoader 1 4
+ sun.misc.Launcher$ExtClassLoader 1 1
+Affect(row-cnt:5) cost in 3 ms.
按类加载实例查看统计信息¶
-$ classloader -l
- name loadedCount hash parent
- BootstrapClassLoader 1861 null null
- com.taobao.arthas.agent.ArthasClassloader@68b31f0a 2115 68b31f0a sun.misc.Launcher$ExtClassLoader@66350f69
- sun.misc.Launcher$AppClassLoader@3d4eac69 4 3d4eac69 sun.misc.Launcher$ExtClassLoader@66350f69
- sun.misc.Launcher$ExtClassLoader@66350f69 1 66350f69 null
-Affect(row-cnt:4) cost in 2 ms.
+$ classloader -l
+ name loadedCount hash parent
+ BootstrapClassLoader 1861 null null
+ com.taobao.arthas.agent.ArthasClassloader@68b31f0a 2115 68b31f0a sun.misc.Launcher$ExtClassLoader@66350f69
+ sun.misc.Launcher$AppClassLoader@3d4eac69 4 3d4eac69 sun.misc.Launcher$ExtClassLoader@66350f69
+ sun.misc.Launcher$ExtClassLoader@66350f69 1 66350f69 null
+Affect(row-cnt:4) cost in 2 ms.
查看ClassLoader的继承树¶
-$ classloader -t
+$ classloader -t
+-BootstrapClassLoader
-+-sun.misc.Launcher$ExtClassLoader@66350f69
++-sun.misc.Launcher$ExtClassLoader@66350f69
+-com.taobao.arthas.agent.ArthasClassloader@68b31f0a
- +-sun.misc.Launcher$AppClassLoader@3d4eac69
-Affect(row-cnt:4) cost in 3 ms.
+ +-sun.misc.Launcher$AppClassLoader@3d4eac69
+Affect(row-cnt:4) cost in 3 ms.
查看URLClassLoader实际的urls¶
-$ classloader -c 3d4eac69
+$ classloader -c 3d4eac69
file:/private/tmp/arthas-demo.jar
file:/Users/hengyunabc/.arthas/lib/3.0.5/arthas/arthas-agent.jar
-Affect(row-cnt:9) cost in 3 ms.
+Affect(row-cnt:9) cost in 3 ms.
使用ClassLoader去查找resource¶
-$ classloader -c 3d4eac69 -r META-INF/MANIFEST.MF
+$ classloader -c 3d4eac69 -r META-INF/MANIFEST.MF
jar:file:/System/Library/Java/Extensions/MRJToolkit.jar!/META-INF/MANIFEST.MF
jar:file:/private/tmp/arthas-demo.jar!/META-INF/MANIFEST.MF
jar:file:/Users/hengyunabc/.arthas/lib/3.0.5/arthas/arthas-agent.jar!/META-INF/MANIFEST.MF
也可以尝试查找类的class文件:
-$ classloader -c 1b6d3586 -r java/lang/String.class
+$ classloader -c 1b6d3586 -r java/lang/String.class
jar:file:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/rt.jar!/java/lang/String.class
使用ClassLoader去加载类¶
-$ classloader -c 3d4eac69 --load demo.MathGame
+$ classloader -c 3d4eac69 --load demo.MathGame
load class success.
class-info demo.MathGame
code-source /private/tmp/arthas-demo.jar
name demo.MathGame
- isInterface false
- isAnnotation false
- isEnum false
- isAnonymousClass false
- isArray false
- isLocalClass false
- isMemberClass false
- isPrimitive false
- isSynthetic false
+ isInterface false
+ isAnnotation false
+ isEnum false
+ isAnonymousClass false
+ isArray false
+ isLocalClass false
+ isMemberClass false
+ isPrimitive false
+ isSynthetic false
simple-name MathGame
modifier public
annotation
interfaces
super-class +-java.lang.Object
- class-loader +-sun.misc.Launcher$AppClassLoader@3d4eac69
- +-sun.misc.Launcher$ExtClassLoader@66350f69
+ class-loader +-sun.misc.Launcher$AppClassLoader@3d4eac69
+ +-sun.misc.Launcher$ExtClassLoader@66350f69
classLoaderHash 3d4eac69
@@ -409,6 +410,15 @@ load class success.
+
+
+
+
+
@@ -117,7 +118,7 @@
- 用户案例
-- Questions and answers
+- 常见问题
- Fork me at GitHub
- 参与贡献
- Release Notes
@@ -301,6 +302,15 @@
+
+
+
+
+
@@ -94,7 +95,7 @@
- 进阶使用
- 命令列表
- 用户案例
-- Questions and answers
+- 常见问题
- Fork me at GitHub
- 参与贡献
- Release Notes
@@ -257,6 +258,15 @@
+
+
+
+
+
@@ -122,7 +123,7 @@
- 用户案例
-- Questions and answers
+- 常见问题
- Fork me at GitHub
- 参与贡献
- Release Notes
@@ -202,7 +203,7 @@
当运行在Ali-tomcat时,会显示当前tomcat的实时信息,如HTTP请求的qps, rt, 错误数, 线程池信息等等。
使用参考¶
-$ dashboard
+$ dashboard
ID NAME GROUP PRIORITY STATE %CPU TIME INTERRUPTED DAEMON
889 RMI TCP Connection(15)-30.10.166. RMI Runtime 9 RUNNABLE 48 0:5 false true
1077 Timer-for-arthas-dashboard-0 system 9 RUNNABLE 24 0:0 false true
@@ -235,8 +236,7 @@ java.home error/s
received/s 0B
systemload.average 3.44 sent/s 0B
processors 4 threadpool http-bio-8080
-uptime 16020s busy 0
-
+uptime 16020s busy 0
@@ -248,7 +248,7 @@ uptime 16020s busy
- PRIORITY: 线程优先级, 1~10之间的数字,越大表示优先级越高
- STATE: 线程的状态
- CPU%: 线程消耗的cpu占比,采样100ms,将所有线程在这100ms内的cpu使用量求和,再算出每个线程的cpu使用占比。
-- TIME: 线程运行总时间,数据格式为
分:秒
+- TIME: 线程运行总时间,数据格式为分:秒
- INTERRUPTED: 线程当前的中断位状态
- DAEMON: 是否是daemon线程
@@ -332,6 +332,15 @@ uptime 16020s busy
+
+
+
+
+
@@ -121,7 +122,7 @@
- 用户案例
-- Questions and answers
+- 常见问题
- Fork me at GitHub
- 参与贡献
- Release Notes
@@ -224,17 +225,17 @@
使用参考¶
-$ dump java.lang.String
+$ dump java.lang.String
HASHCODE CLASSLOADER LOCATION
null /Users/admin/logs/arthas/classdump/java/lang/String.class
-Affect(row-cnt:1) cost in 119 ms.
+Affect(row-cnt:1) cost in 119 ms.
-$ dump demo.*
+$ dump demo.*
HASHCODE CLASSLOADER LOCATION
- 3d4eac69 +-sun.misc.Launcher$AppClassLoader@3d4eac69 /Users/admin/logs/arthas/classdump/sun.misc.Launcher$AppClassLoader-3d4eac69/demo/MathGame.class
- +-sun.misc.Launcher$ExtClassLoader@66350f69
-Affect(row-cnt:1) cost in 39 ms.
+ 3d4eac69 +-sun.misc.Launcher$AppClassLoader@3d4eac69 /Users/admin/logs/arthas/classdump/sun.misc.Launcher$AppClassLoader-3d4eac69/demo/MathGame.class
+ +-sun.misc.Launcher$ExtClassLoader@66350f69
+Affect(row-cnt:1) cost in 39 ms.
@@ -313,6 +314,15 @@ Affect(row-cnt:1) cost in
+
+
+
+
+
@@ -227,6 +228,15 @@
+
+
+
+
+
@@ -192,7 +193,7 @@
- help - display Arthas help
- cls - clear the screen
- session - display current session information
-- reset - reset all the enhanced classes. All enhanced classes will also be reset when Arthas server is closed by
shutdown
+- reset - reset all the enhanced classes. All enhanced classes will also be reset when Arthas server is closed by shutdown
- version - print the version for the Arthas attached to the current Java process
- history - view command history
- quit/exit - exit the current Arthas session, without effecting other sessions
@@ -217,15 +218,15 @@
- sc - check the info for the classes loaded by JVM
- sm - check methods info for the loaded classes
- dump - dump the loaded classes in byte code to the specified location
-- redefine - load external
*.class files and re-define it into JVM
+- redefine - load external *.class files and re-define it into JVM
- jad - decompile the specified loaded classes
-- classloader - check the inheritance structure, urls, class loading info for the specified class; using classloader to get the url of the resource e.g.
java/lang/String.class
+- classloader - check the inheritance structure, urls, class loading info for the specified class; using classloader to get the url of the resource e.g. java/lang/String.class
pipe¶
-Arthas provides pipe to process the result returned from commands further, e.g. sm org.apache.log4j.Logger | grep <init>. Commands supported in pipe:
+Arthas provides pipe to process the result returned from commands further, e.g. sm org.apache.log4j.Logger | grep . Commands supported in pipe:
- grep - filter the result with the given keyword
- plaintext - remove the color
@@ -251,9 +252,9 @@
async in background¶
-async can be handy when a problem is hardly to reproduce in the production environment, e.g. one watch condition may happen only once in one single day.
+async can be handy when a problem is hardly to reproduce in the production environment, e.g. one watch condition may happen only once in one single day.
-- job control - use
> to redirect result into the log file, use & to put the job to the background. Job keeps running even if the session is disconnected (the session lifecycle is 1 day by default)
+- job control - use > to redirect result into the log file, use & to put the job to the background. Job keeps running even if the session is disconnected (the session lifecycle is 1 day by default)
- jobs - list all jobs
- kill - forcibly terminate the job
- fg - bring the suspend job to the foreground
@@ -354,6 +355,15 @@
+
+
+
+
+
@@ -201,25 +202,25 @@
Fundamental Fields in Expressions¶
-There is a very fundamental class Advice for the expressions used in filtering, tracing or monitoring and other aspects in commands.
-public class Advice {
+There is a very fundamental class Advice for the expressions used in filtering, tracing or monitoring and other aspects in commands.
+public class Advice {
- private final ClassLoader loader;
- private final Class<?> clazz;
- private final ArthasMethod method;
- private final Object target;
- private final Object[] params;
- private final Object returnObj;
- private final Throwable throwExp;
- private final boolean isBefore;
- private final boolean isThrow;
- private final boolean isReturn;
+ private final ClassLoader loader;
+ private final Class<?> clazz;
+ private final ArthasMethod method;
+ private final Object target;
+ private final Object[] params;
+ private final Object returnObj;
+ private final Throwable throwExp;
+ private final boolean isBefore;
+ private final boolean isThrow;
+ private final boolean isReturn;
- // getter/setter
-}
+ // getter/setter
+}
-Description for the variables in the class Advice:
+Description for the variables in the class Advice:
@@ -348,6 +349,15 @@
+
+
+
+
+
@@ -198,36 +199,36 @@
1. Use & to run the command in the background¶
For example, execute the trace command in the background:
-trace Test t &
+trace Test t &
By doing this, the current command is put to the background to run, you can continue to execute other commands in the console.
2. List background jobs¶
-If you want to list all background jobs, you can execute the jobs command and the results are as follows:
-$ jobs
-[10]*
- Stopped watch com.taobao.container.Test test "params[0].{? #this.name == null }" -x 2
- execution count : 19
- start time : Fri Sep 22 09:59:55 CST 2017
- timeout date : Sat Sep 23 09:59:55 CST 2017
- session : 3648e874-5e69-473f-9eed-7f89660b079b (current)
+If you want to list all background jobs, you can execute the jobs command and the results are as follows:
+$ jobs
+[10]*
+ Stopped watch com.taobao.container.Test test "params[0].{? #this.name == null }" -x 2
+ execution count : 19
+ start time : Fri Sep 22 09:59:55 CST 2017
+ timeout date : Sat Sep 23 09:59:55 CST 2017
+ session : 3648e874-5e69-473f-9eed-7f89660b079b (current)
You can see that there is currently a background job executing:
-- job id is 10,
* indicates that this job is created by the current session.
-- status is
Stopped
+- job id is 10, * indicates that this job is created by the current session.
+- status is Stopped
- execution count is the number of executions, which have been executed 19 times since the start.
- timeout date: timeout timestamp, when the time exceeds this timestamp, the job will be automatically timeout and exit.
3. Suspend and cancel job¶
-When the job is executing in the foreground, for example, directly executing the command trace Test t, or executing the background job command trace Test t &, then putting the job back to the forground via fg command, the console cannot continue to execute other command, but can receive and process the following keyboard events:
+When the job is executing in the foreground, for example, directly executing the command trace Test t, or executing the background job command trace Test t &, then putting the job back to the forground via fg command, the console cannot continue to execute other command, but can receive and process the following keyboard events:
-- ‘ctrl + z’: Suspend the job, the job status will change to
Stopped, and the job can be restarted by bg <job-id> or fg <job-id>
+- ‘ctrl + z’: Suspend the job, the job status will change to Stopped, and the job can be restarted by bg
or fg
- ‘ctrl + c’: Stop the job
- ‘ctrl + d’: According to linux semantics this should lead to exit the terminal, right now Arthas has not implemented this yet, therefore simply ignore this keystroke.
@@ -235,29 +236,29 @@
4. fg/bg, switch the job from the foreground to the background, and vise verse¶
-- When a job is executed in the background or in suspended status (use
ctrl + z to suspend job), fg <job-id> can transfer the job to the foreground to continue to run.
-- When a job is in suspended status (use
ctrl + z to suspend job), bg <job-id> can put the job to the background to continue to run.
-- A job created by other session can only be put to the foreground to run by using
fg in the current session.
+- When a job is executed in the background or in suspended status (use ctrl + z to suspend job), fg
can transfer the job to the foreground to continue to run.
+- When a job is in suspended status (use ctrl + z to suspend job), bg
can put the job to the background to continue to run.
+- A job created by other session can only be put to the foreground to run by using fg in the current session.
5. Redirect the output¶
-The job output can be redirect to the specified file by > or >>, and can be used together with &. By doing this, you can achieve running commands asynchronously, for example:
-$ trace Test t >> test.out &
+The job output can be redirect to the specified file by > or >>, and can be used together with &. By doing this, you can achieve running commands asynchronously, for example:
+$ trace Test t >> test.out &
-The trace command will be running in the background and the output will be redirect to ~/logs/arthas-cache/test.out. You can continue to execute other commands in the console, at the same time, you can also examine the execution result from the output file.
+The trace command will be running in the background and the output will be redirect to ~/logs/arthas-cache/test.out. You can continue to execute other commands in the console, at the same time, you can also examine the execution result from the output file.
When connect to a remote Arthas server, you may not be able to view the output file on the remote machine. In this case, Arthas also supports automatically redirecting the output to the local cache file. Examples are as follows:
-$ trace Test t >> &
-job id : 2
+$ trace Test t >> &
+job id : 2
cache location : /Users/gehui/logs/arthas-cache/28198/2
-If output path is not given, Arthas will automatically redirect the output to the local cache. Job id and cache location will be shown on the console. Cache location is a directory where the output files are put. For one given job, the path of its output file contains PID and job id in order to avoid potential conflict with other jobs. In the above example, pid is 28198 and job id is 2.
+If output path is not given, Arthas will automatically redirect the output to the local cache. Job id and cache location will be shown on the console. Cache location is a directory where the output files are put. For one given job, the path of its output file contains PID and job id in order to avoid potential conflict with other jobs. In the above example, pid is 28198 and job id is 2.
6. Stop job¶
-If you want to stop background job, just kill <job-id>.
+If you want to stop background job, just kill .
7. Others¶
@@ -340,6 +341,15 @@ cache location : /Users/gehui/logs/arthas-cache/28198/2
+
+
+
+
+
@@ -193,10 +194,10 @@
Usage¶
Step 1: Create the script¶
-Create a test.as script suffixed with as. Here as is suggested for the suffix of the filename, but in fact any suffix is acceptable.
-➜ arthas git:(develop) cat /var/tmp/test.as
-help
-dashboard -b -n 1
+Create a test.as script suffixed with as. Here as is suggested for the suffix of the filename, but in fact any suffix is acceptable.
+➜ arthas git:(develop) cat /var/tmp/test.as
+help
+dashboard -b -n 1
session
thread
sc -d org.apache.commons.lang.StringUtils
@@ -205,21 +206,21 @@ sc -d org.apache.commons.lang.StringUtils
Note:
- Each command takes one line.
-- Batch mode (via
-b) and execution times (via -n) must be explicitly specified for dashboard, otherwise batch script cannot terminate.
-- Commands such as
watch/tt/trace/monitor/stack should include -n option to ensure the script can be able to quit.
-- Also consider to use
async (for example: watch c.t.X test returnObj > &) to put commands run at background and get the output from the log file, see more from asynchronous job
+- Batch mode (via -b) and execution times (via -n) must be explicitly specified for dashboard, otherwise batch script cannot terminate.
+- Commands such as watch/tt/trace/monitor/stack should include -n option to ensure the script can be able to quit.
+- Also consider to use async (for example: watch c.t.X test returnObj > &) to put commands run at background and get the output from the log file, see more from asynchronous job
Step 2: Run the script¶
-Use -b to turn on batch mode, and use -f to specify the script file. By default the result will be output to the standard output, but you can redirect the output to the file like this:
-./as.sh -b -f /var/tmp/test.as 56328 > test.out
+Use -b to turn on batch mode, and use -f to specify the script file. By default the result will be output to the standard output, but you can redirect the output to the file like this:
+./as.sh -b -f /var/tmp/test.as 56328 > test.out
Step 3: Check the outputs¶
-cat test.out
+cat test.out
@@ -298,6 +299,15 @@ sc -d org.apache.commons.lang.StringUtils
+
+
+
+
+
@@ -203,7 +204,7 @@
classloader¶
View hierarchy, urls and classes-loading info for the class-loaders.
-classloader can search and print out the URLs for a specified resource from one particular classloader. It is quite handy when analyze ResourceNotFoundException.
+classloader can search and print out the URLs for a specified resource from one particular classloader. It is quite handy when analyze ResourceNotFoundException.
Options¶
@@ -244,87 +245,87 @@
Usage¶
View statistics categorized by class type¶
-$ classloader
+$ classloader
name numberOfInstances loadedCountTotal
- com.taobao.arthas.agent.ArthasClassloader 1 2115
- BootstrapClassLoader 1 1861
- sun.reflect.DelegatingClassLoader 5 5
- sun.misc.Launcher$AppClassLoader 1 4
- sun.misc.Launcher$ExtClassLoader 1 1
-Affect(row-cnt:5) cost in 3 ms.
+ com.taobao.arthas.agent.ArthasClassloader 1 2115
+ BootstrapClassLoader 1 1861
+ sun.reflect.DelegatingClassLoader 5 5
+ sun.misc.Launcher$AppClassLoader 1 4
+ sun.misc.Launcher$ExtClassLoader 1 1
+Affect(row-cnt:5) cost in 3 ms.
View statistics categorized by loaded classes number¶
-$ classloader -l
- name loadedCount hash parent
- BootstrapClassLoader 1861 null null
- com.taobao.arthas.agent.ArthasClassloader@68b31f0a 2115 68b31f0a sun.misc.Launcher$ExtClassLoader@66350f69
- sun.misc.Launcher$AppClassLoader@3d4eac69 4 3d4eac69 sun.misc.Launcher$ExtClassLoader@66350f69
- sun.misc.Launcher$ExtClassLoader@66350f69 1 66350f69 null
-Affect(row-cnt:4) cost in 2 ms.
+$ classloader -l
+ name loadedCount hash parent
+ BootstrapClassLoader 1861 null null
+ com.taobao.arthas.agent.ArthasClassloader@68b31f0a 2115 68b31f0a sun.misc.Launcher$ExtClassLoader@66350f69
+ sun.misc.Launcher$AppClassLoader@3d4eac69 4 3d4eac69 sun.misc.Launcher$ExtClassLoader@66350f69
+ sun.misc.Launcher$ExtClassLoader@66350f69 1 66350f69 null
+Affect(row-cnt:4) cost in 2 ms.
View class-loaders hierarchy¶
-$ classloader -t
+$ classloader -t
+-BootstrapClassLoader
-+-sun.misc.Launcher$ExtClassLoader@66350f69
++-sun.misc.Launcher$ExtClassLoader@66350f69
+-com.taobao.arthas.agent.ArthasClassloader@68b31f0a
- +-sun.misc.Launcher$AppClassLoader@3d4eac69
-Affect(row-cnt:4) cost in 3 ms.
+ +-sun.misc.Launcher$AppClassLoader@3d4eac69
+Affect(row-cnt:4) cost in 3 ms.
Show the URLs of the URLClassLoader¶
-$ classloader -c 3d4eac69
+$ classloader -c 3d4eac69
file:/private/tmp/arthas-demo.jar
file:/Users/hengyunabc/.arthas/lib/3.0.5/arthas/arthas-agent.jar
-Affect(row-cnt:9) cost in 3 ms.
+Affect(row-cnt:9) cost in 3 ms.
Use the classloader to load resource¶
-$ classloader -c 3d4eac69 -r META-INF/MANIFEST.MF
+$ classloader -c 3d4eac69 -r META-INF/MANIFEST.MF
jar:file:/System/Library/Java/Extensions/MRJToolkit.jar!/META-INF/MANIFEST.MF
jar:file:/private/tmp/arthas-demo.jar!/META-INF/MANIFEST.MF
jar:file:/Users/hengyunabc/.arthas/lib/3.0.5/arthas/arthas-agent.jar!/META-INF/MANIFEST.MF
-Use the classloader to load .class resource
-$ classloader -c 1b6d3586 -r java/lang/String.class
+Use the classloader to load .class resource
+$ classloader -c 1b6d3586 -r java/lang/String.class
jar:file:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/rt.jar!/java/lang/String.class
Use the classloader to load class¶
-$ classloader -c 3d4eac69 --load demo.MathGame
+$ classloader -c 3d4eac69 --load demo.MathGame
load class success.
class-info demo.MathGame
code-source /private/tmp/arthas-demo.jar
name demo.MathGame
- isInterface false
- isAnnotation false
- isEnum false
- isAnonymousClass false
- isArray false
- isLocalClass false
- isMemberClass false
- isPrimitive false
- isSynthetic false
+ isInterface false
+ isAnnotation false
+ isEnum false
+ isAnonymousClass false
+ isArray false
+ isLocalClass false
+ isMemberClass false
+ isPrimitive false
+ isSynthetic false
simple-name MathGame
modifier public
annotation
interfaces
super-class +-java.lang.Object
- class-loader +-sun.misc.Launcher$AppClassLoader@3d4eac69
- +-sun.misc.Launcher$ExtClassLoader@66350f69
+ class-loader +-sun.misc.Launcher$AppClassLoader@3d4eac69
+ +-sun.misc.Launcher$ExtClassLoader@66350f69
classLoaderHash 3d4eac69
@@ -404,6 +405,15 @@ load class success.
+
+
+
+
+
@@ -298,6 +299,15 @@
+
+
+
+
+
@@ -196,11 +197,11 @@
dashboard¶
-This is the real time statistics dashboard for the current system, press Ctrl+C to exit.
+This is the real time statistics dashboard for the current system, press Ctrl+C to exit.
When running in Apache Tomcat Alibaba edition, the dashboard will also present the real time statistics of the tomcat, including QPS, RT, error counts, and thread pool, etc.
Usage¶
-$ dashboard
+$ dashboard
ID NAME GROUP PRIORITY STATE %CPU TIME INTERRUPTED DAEMON
889 RMI TCP Connection(15)-30.10.166. RMI Runtime 9 RUNNABLE 48 0:5 false true
1077 Timer-for-arthas-dashboard-0 system 9 RUNNABLE 24 0:0 false true
@@ -233,8 +234,7 @@ java.home error/s
received/s 0B
systemload.average 3.44 sent/s 0B
processors 4 threadpool http-bio-8080
-uptime 16020s busy 0
-
+uptime 16020s busy 0
@@ -246,7 +246,7 @@ uptime 16020s busy
- PRIORITY: thread priority, ranged from 1 to 10. The greater number, the higher priority
- STATE: thread state
- CPU%: the ratio of CPU usage for the thread, sampled every 100ms
-- TIME: total running time in
minute:second format
+- TIME: total running time in minute:second format
- INTERRUPTED: the thread interruption state
- DAEMON: daemon thread or not
@@ -329,6 +329,15 @@ uptime 16020s busy
+
+
+
+
+
@@ -222,17 +223,17 @@
Usage¶
-$ dump java.lang.String
+$ dump java.lang.String
HASHCODE CLASSLOADER LOCATION
null /Users/admin/logs/arthas/classdump/java/lang/String.class
-Affect(row-cnt:1) cost in 119 ms.
+Affect(row-cnt:1) cost in 119 ms.
-$ dump demo.*
+$ dump demo.*
HASHCODE CLASSLOADER LOCATION
- 3d4eac69 +-sun.misc.Launcher$AppClassLoader@3d4eac69 /Users/admin/logs/arthas/classdump/sun.misc.Launcher$AppClassLoader-3d4eac69/demo/MathGame.class
- +-sun.misc.Launcher$ExtClassLoader@66350f69
-Affect(row-cnt:1) cost in 39 ms.
+ 3d4eac69 +-sun.misc.Launcher$AppClassLoader@3d4eac69 /Users/admin/logs/arthas/classdump/sun.misc.Launcher$AppClassLoader-3d4eac69/demo/MathGame.class
+ +-sun.misc.Launcher$ExtClassLoader@66350f69
+Affect(row-cnt:1) cost in 39 ms.
@@ -310,6 +311,15 @@ Affect(row-cnt:1) cost in
+
+
+
+
+
@@ -233,6 +234,15 @@
+
+
+
+
+
@@ -197,48 +198,48 @@
- It is recommended to use the [OGNL] (ognl.md) command, which will be more flexibility.
-Check the static fields of classes conveniently, the usage is getstatic class_name field_name.
-$ getstatic demo.MathGame random
+Check the static fields of classes conveniently, the usage is getstatic class_name field_name.
+$ getstatic demo.MathGame random
field: random
-@Random[
- serialVersionUID=@Long[3905348978240129619],
- seed=@AtomicLong[120955813885284],
- multiplier=@Long[25214903917],
- addend=@Long[11],
- mask=@Long[281474976710655],
- DOUBLE_UNIT=@Double[1.1102230246251565E-16],
- BadBound=@String[bound must be positive],
- BadRange=@String[bound must be greater than origin],
- BadSize=@String[size must be non-negative],
- seedUniquifier=@AtomicLong[-3282039941672302964],
- nextNextGaussian=@Double[0.0],
- haveNextNextGaussian=@Boolean[false],
- serialPersistentFields=@ObjectStreamField[][isEmpty=false;size=3],
- unsafe=@Unsafe[sun.misc.Unsafe@2eaa1027],
- seedOffset=@Long[24],
-]
+@Random[
+ serialVersionUID=@Long[3905348978240129619],
+ seed=@AtomicLong[120955813885284],
+ multiplier=@Long[25214903917],
+ addend=@Long[11],
+ mask=@Long[281474976710655],
+ DOUBLE_UNIT=@Double[1.1102230246251565E-16],
+ BadBound=@String[bound must be positive],
+ BadRange=@String[bound must be greater than origin],
+ BadSize=@String[size must be non-negative],
+ seedUniquifier=@AtomicLong[-3282039941672302964],
+ nextNextGaussian=@Double[0.0],
+ haveNextNextGaussian=@Boolean[false],
+ serialPersistentFields=@ObjectStreamField[][isEmpty=false;size=3],
+ unsafe=@Unsafe[sun.misc.Unsafe@2eaa1027],
+ seedOffset=@Long[24],
+]
-Tip: if the static field is a complex class, you can even use OGNL to traverse, filter and access the inner properties of this class.
+Tip: if the static field is a complex class, you can even use OGNL to traverse, filter and access the inner properties of this class.
-E.g. suppose n is a Map and its key is a Enum, then you can achieve this if you want to pick the key with a specific Enum value:
-$ getstatic com.alibaba.arthas.Test n 'entrySet().iterator.{? #this.key.name()=="STOP"}'
+E.g. suppose n is a Map and its key is a Enum, then you can achieve this if you want to pick the key with a specific Enum value:
+$ getstatic com.alibaba.arthas.Test n 'entrySet().iterator.{? #this.key.name()=="STOP"}'
field: n
-@ArrayList[
- @Node[STOP=bbb],
-]
-Affect(row-cnt:1) cost in 68 ms.
+@ArrayList[
+ @Node[STOP=bbb],
+]
+Affect(row-cnt:1) cost in 68 ms.
-$ getstatic com.alibaba.arthas.Test m 'entrySet().iterator.{? #this.key=="a"}'
+$ getstatic com.alibaba.arthas.Test m 'entrySet().iterator.{? #this.key=="a"}'
field: m
-@ArrayList[
- @Node[a=aaa],
-]
+@ArrayList[
+ @Node[a=aaa],
+]
@@ -315,6 +316,15 @@ field: m
+
+
+
+
+
@@ -169,7 +170,7 @@
Limitations¶
-- Prohibit from alternating the original logic. Like
watch command, The major purpose of scripting is monitoring and observing.
+- Prohibit from alternating the original logic. Like watch command, The major purpose of scripting is monitoring and observing.
- Only allow to monitor at the stages of before/success/exception/finish on one method.
@@ -204,151 +205,151 @@
enable regex match, the default is wildcard match
-
Note: the third parameter script-filepath must be the absolute path of the groovy script, for example /tmp/test.groovy. It is not recommended to use relative path, e.g. ./test.groovy.
+Note: the third parameter script-filepath must be the absolute path of the groovy script, for example /tmp/test.groovy. It is not recommended to use relative path, e.g. ./test.groovy.
Explanation on the important callbacks¶
-/**
- * Listeners for script to enhance the class
- */
-interface ScriptListener {
+/**
+ * Listeners for script to enhance the class
+ */
+interface ScriptListener {
- /**
- * When the script is created
- *
- * @param output Output
- */
- void create(Output output);
+ /**
+ * When the script is created
+ *
+ * @param output Output
+ */
+ void create(Output output);
- /**
- * When the script is destroyed
- *
- * @param output Output
- */
- void destroy(Output output);
+ /**
+ * When the script is destroyed
+ *
+ * @param output Output
+ */
+ void destroy(Output output);
- /**
- * Before the method executes
- *
- * @param output Output
- * @param advice Advice
- */
- void before(Output output, Advice advice);
+ /**
+ * Before the method executes
+ *
+ * @param output Output
+ * @param advice Advice
+ */
+ void before(Output output, Advice advice);
- /**
- * After the method returns
- *
- * @param output Output
- * @param advice Advice
- */
- void afterReturning(Output output, Advice advice);
+ /**
+ * After the method returns
+ *
+ * @param output Output
+ * @param advice Advice
+ */
+ void afterReturning(Output output, Advice advice);
- /**
- * After the method throws exceptions
- *
- * @param output Output
- * @param advice Advice
- */
- void afterThrowing(Output output, Advice advice);
+ /**
+ * After the method throws exceptions
+ *
+ * @param output Output
+ * @param advice Advice
+ */
+ void afterThrowing(Output output, Advice advice);
-}
+}
-Advice parameter¶
-Advice contains all information necessary for notification. Refer to expression core parameters for more details.
+Advice parameter¶
+Advice contains all information necessary for notification. Refer to expression core parameters for more details.
-Output parameter¶
-There are three methods in Output, used for outputting the corresponding text.
-/**
- * Output
- */
-interface Output {
+Output parameter¶
+There are three methods in Output, used for outputting the corresponding text.
+/**
+ * Output
+ */
+interface Output {
- /**
- * Output text without line break
- *
- * @param string Text to output
- * @return this
- */
- Output print(String string);
+ /**
+ * Output text without line break
+ *
+ * @param string Text to output
+ * @return this
+ */
+ Output print(String string);
- /**
- * Output text with line break
- *
- * @param string Text to output
- * @return this
- */
- Output println(String string);
+ /**
+ * Output text with line break
+ *
+ * @param string Text to output
+ * @return this
+ */
+ Output println(String string);
- /**
- * Finish outputting from the script
- *
- * @return this
- */
- Output finish();
+ /**
+ * Finish outputting from the script
+ *
+ * @return this
+ */
+ Output finish();
-}
+}
A groovy sample script to output logs¶
-import com.taobao.arthas.core.command.ScriptSupportCommand
-import com.taobao.arthas.core.util.Advice
+import com.taobao.arthas.core.command.ScriptSupportCommand
+import com.taobao.arthas.core.util.Advice
-import static java.lang.String.format
+import static java.lang.String.format
-/**
- * Output method logs
- */
-public class Logger implements ScriptSupportCommand.ScriptListener {
+/**
+ * Output method logs
+ */
+public class Logger implements ScriptSupportCommand.ScriptListener {
- @Override
- void create(ScriptSupportCommand.Output output) {
- output.println("script create.");
- }
+ @Override
+ void create(ScriptSupportCommand.Output output) {
+ output.println("script create.");
+ }
- @Override
- void destroy(ScriptSupportCommand.Output output) {
- output.println("script destroy.");
- }
+ @Override
+ void destroy(ScriptSupportCommand.Output output) {
+ output.println("script destroy.");
+ }
- @Override
- void before(ScriptSupportCommand.Output output, Advice advice) {
- output.println(format("before:class=%s;method=%s;paramslen=%d;%s;",
- advice.getClazz().getSimpleName(),
- advice.getMethod().getName(),
- advice.getParams().length, advice.getParams()))
- }
+ @Override
+ void before(ScriptSupportCommand.Output output, Advice advice) {
+ output.println(format("before:class=%s;method=%s;paramslen=%d;%s;",
+ advice.getClazz().getSimpleName(),
+ advice.getMethod().getName(),
+ advice.getParams().length, advice.getParams()))
+ }
- @Override
- void afterReturning(ScriptSupportCommand.Output output, Advice advice) {
- output.println(format("returning:class=%s;method=%s;",
- advice.getClazz().getSimpleName(),
- advice.getMethod().getName()))
- }
+ @Override
+ void afterReturning(ScriptSupportCommand.Output output, Advice advice) {
+ output.println(format("returning:class=%s;method=%s;",
+ advice.getClazz().getSimpleName(),
+ advice.getMethod().getName()))
+ }
- @Override
- void afterThrowing(ScriptSupportCommand.Output output, Advice advice) {
- output.println(format("throwing:class=%s;method=%s;",
- advice.getClazz().getSimpleName(),
- advice.getMethod().getName()))
- }
-}
+ @Override
+ void afterThrowing(ScriptSupportCommand.Output output, Advice advice) {
+ output.println(format("throwing:class=%s;method=%s;",
+ advice.getClazz().getSimpleName(),
+ advice.getMethod().getName()))
+ }
+}
Run the script like this:
-$ groovy com.alibaba.sample.petstore.dal.dao.ProductDao getProductById /Users/zhuyong/middleware/arthas/scripts/Logger.groovy -S
+$ groovy com.alibaba.sample.petstore.dal.dao.ProductDao getProductById /Users/zhuyong/middleware/arthas/scripts/Logger.groovy -S
script create.
Press Ctrl+C to abort.
-Affect(class-cnt:1 , method-cnt:1) cost in 102 ms.
-before:class=IbatisProductDao;method=getProductById;paramslen=1;[Ljava.lang.Object;@45df64fc;
-returning:class=IbatisProductDao;method=getProductById;
-before:class=IbatisProductDao;method=getProductById;paramslen=1;[Ljava.lang.Object;@5b0e2d00;
-returning:class=IbatisProductDao;method=getProductById;
+Affect(class-cnt:1 , method-cnt:1) cost in 102 ms.
+before:class=IbatisProductDao;method=getProductById;paramslen=1;[Ljava.lang.Object;@45df64fc;
+returning:class=IbatisProductDao;method=getProductById;
+before:class=IbatisProductDao;method=getProductById;paramslen=1;[Ljava.lang.Object;@5b0e2d00;
+returning:class=IbatisProductDao;method=getProductById;
@@ -417,6 +418,15 @@ returning:class=IbatisProductDao;<
+
+
+
+
+
@@ -279,6 +280,15 @@
+
+
+
+
+
@@ -91,8 +92,8 @@
- Installation
- Quick installation
- Full installation
@@ -180,36 +181,36 @@
Quick installation¶
-Use arthas-boot(Recommend)¶
-Downloadarthas-boot.jar,Start with java command:
-$ wget https://alibaba.github.io/arthas/arthas-boot.jar
+Use arthas-boot(Recommend)¶
+Downloadarthas-boot.jar,Start with java command:
+$ wget https://alibaba.github.io/arthas/arthas-boot.jar
$ java -jar arthas-boot.jar
Print usage:
-$ java -jar arthas-boot.jar -h
+$ java -jar arthas-boot.jar -h
-Use as.sh¶
+Use as.sh¶
You can install Arthas with one single line command on Linux, Unix, and Mac. Pls. copy the following command and paste it into the command line, then press Enter to run:
-$ curl -L https://alibaba.github.io/arthas/install.sh | sh
+$ curl -L https://alibaba.github.io/arthas/install.sh | sh
-The command above will download the bootstrap script as.sh to the current directory. You can move it the any other place you want, or put its location in $PATH.
-You can enter its interactive interface by executing as.sh, or execute as.sh -h for more help information.
+The command above will download the bootstrap script as.sh to the current directory. You can move it the any other place you want, or put its location in $PATH.
+You can enter its interactive interface by executing as.sh, or execute as.sh -h for more help information.
Full installation¶
Latest Version, Click To Download: 
-Download and unzip, find arthas-boot.jar in the directory. Start with java command:
-$ java -jar arthas-boot.jar
+Download and unzip, find arthas-boot.jar in the directory. Start with java command:
+$ java -jar arthas-boot.jar
Print usage:
-$ java -jar arthas-boot.jar -h
+$ java -jar arthas-boot.jar -h
@@ -225,11 +226,11 @@ $ java -jar arthas-boot.jar
Uninstall¶
On Linux/Unix/Mac, delete the files with the following command:
-$ rm -rf ~/.arthas/
+$ rm -rf ~/.arthas/
-
On Windows, delete .arthas directory under user home.
+On Windows, delete .arthas directory under user home.
@@ -307,6 +308,15 @@ $ java -jar arthas-boot.jar
+
+
+
+
+
@@ -106,7 +107,7 @@
- jad
- Options
- Usage
-- Decompile
java.lang.String
+- Decompile java.lang.String
- Decompile the specified method
- Decompile with specified classLoader
@@ -201,7 +202,7 @@
jad¶
Decompile the specified classes.
-jad helps to decompile the byte code running in JVM to the source code to assist you to understand the logic behind better.
+jad helps to decompile the byte code running in JVM to the source code to assist you to understand the logic behind better.
- The decompiled code is syntax highlighted for better readability in Arthas console.
- It is possible that there’s grammar error in the decompiled code, but it should not affect your interpretation.
@@ -233,41 +234,41 @@
Usage¶
-Decompile java.lang.String¶
-$ jad java.lang.String
+Decompile java.lang.String¶
+$ jad java.lang.String
-ClassLoader:
+ClassLoader:
-Location:
+Location:
-/*
-* Decompiled with CFR 0_132.
-*/
-package java.lang;
+/*
+* Decompiled with CFR 0_132.
+*/
+package java.lang;
-import java.io.ObjectStreamField;
-...
-public final class String
-implements Serializable,
-Comparable<String>,
-CharSequence {
- private final char[] value;
- private int hash;
- private static final long serialVersionUID = -6849794470754667710L;
- private static final ObjectStreamField[] serialPersistentFields = new ObjectStreamField[0];
- public static final Comparator<String> CASE_INSENSITIVE_ORDER = new CaseInsensitiveComparator();
+import java.io.ObjectStreamField;
+...
+public final class String
+implements Serializable,
+Comparable<String>,
+CharSequence {
+ private final char[] value;
+ private int hash;
+ private static final long serialVersionUID = -6849794470754667710L;
+ private static final ObjectStreamField[] serialPersistentFields = new ObjectStreamField[0];
+ public static final Comparator<String> CASE_INSENSITIVE_ORDER = new CaseInsensitiveComparator();
- public String(byte[] arrby, int n, int n2) {
- String.checkBounds(arrby, n, n2);
- this.value = StringCoding.decode(arrby, n, n2);
- }
-...
+ public String(byte[] arrby, int n, int n2) {
+ String.checkBounds(arrby, n, n2);
+ this.value = StringCoding.decode(arrby, n, n2);
+ }
+...
Decompile the specified method¶
-$ jad demo.MathGame main
+$ jad demo.MathGame main
ClassLoader:
+-sun.misc.Launcher$AppClassLoader@3d4eac69
@@ -291,23 +292,23 @@ Affect(row-cnt:1) cost in 228 ms.
Decompile with specified classLoader¶
-If the target class is loaded by multiple classloaders, jad outputs the hashcode of the corresponding classloaders, then you can re-run jad and specify -c <hashcode> to decompile the target class from the specified classloader.
-$ jad org.apache.log4j.Logger
+If the target class is loaded by multiple classloaders, jad outputs the hashcode of the corresponding classloaders, then you can re-run jad and specify -c to decompile the target class from the specified classloader.
+$ jad org.apache.log4j.Logger
Found more than one class for: org.apache.log4j.Logger, Please use jad -c hashcode org.apache.log4j.Logger
HASHCODE CLASSLOADER
-69dcaba4 +-monitor's ModuleClassLoader
+69dcaba4 +-monitor's ModuleClassLoader
6e51ad67 +-java.net.URLClassLoader@6e51ad67
+-sun.misc.Launcher$AppClassLoader@6951a712
+-sun.misc.Launcher$ExtClassLoader@6fafc4c2
-2bdd9114 +-pandora-qos-service's ModuleClassLoader
-4c0df5f8 +-pandora-framework's ModuleClassLoader
+2bdd9114 +-pandora-qos-service's ModuleClassLoader
+4c0df5f8 +-pandora-framework's ModuleClassLoader
Affect(row-cnt:0) cost in 38 ms.
$ jad org.apache.log4j.Logger -c 69dcaba4
ClassLoader:
-+-monitor's ModuleClassLoader
++-monitor's ModuleClassLoader
Location:
/Users/admin/app/log4j-1.2.14.jar
@@ -406,6 +407,15 @@ Affect(row-cnt:1) cost in 190 ms.
+
+
+
+
+
@@ -199,7 +200,7 @@
Check the current JVM’s info
Usage¶
-$ jvm
+$ jvm
CATEGORY INFO
------------------------------------------------------------------------------------------------------------------------------------
@@ -284,8 +285,7 @@
MAX-FILE-DESCRIPTOR-COUNT 10240
OPEN-FILE-DESCRIPTOR-COUNT 648
-Affect cost in 2 ms.
-
+Affect cost in 2 ms.