From fac8dd5470e96109366fb55dddeef13eb6cba220 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=AA=E5=90=89?= <983433479@qq.com> Date: Mon, 11 Jan 2021 01:47:07 -0600 Subject: [PATCH] update faq.md (#1660) --- site/src/site/sphinx/en/faq.md | 17 +++++++++++-- site/src/site/sphinx/en/tt.md | 41 ++++++++++++++++++++++++++++++-- site/src/site/sphinx/en/watch.md | 17 +++++++++++++ site/src/site/sphinx/faq.md | 16 ++++++++++++- site/src/site/sphinx/tt.md | 38 +++++++++++++++++++++++++++++ site/src/site/sphinx/watch.md | 17 +++++++++++++ 6 files changed, 141 insertions(+), 5 deletions(-) diff --git a/site/src/site/sphinx/en/faq.md b/site/src/site/sphinx/en/faq.md index fea44b934..cb9f8beb5 100644 --- a/site/src/site/sphinx/en/faq.md +++ b/site/src/site/sphinx/en/faq.md @@ -37,7 +37,7 @@ No. No. But you can use some tricks to intercept the object with the `tt` command, or fetch it from a static method. -#### How to filter method with the same name? +##### How to filter method with the same name? You can used all variables in [fundamental fields in expressions](advice-class.md) for the condition express to filter method with the same name, you can use the number of parameters `params.length ==1`,parameter type `params[0] instanceof java.lang.Integer`,return value type `returnObj instanceof java.util.List` and so on in one or more combinations as condition express. @@ -47,4 +47,17 @@ example [arthas-demo](quick-start.md) ```bash watch demo.MathGame primeFactors traceE '{params,returnObj,throwExp}' -v -n 5 -x 3 'params.length >0 && returnObj instanceof java.util.List' -``` \ No newline at end of file +``` + +##### How to watch or trace constructor? + +```bash +watch demo.MathGame '{params,returnObj,throwExp}' -v -n 5 -x 3 '1==1' +``` + + +##### java.lang.ClassFormatError: null, skywalking arthas compatible use + +When error log appear `java.lang.ClassFormatError: null`, it is usually modified by other bytecode tools that are not compatible with arthas modified bytecode. + +For example: use skywalking V8.1.0 below [cannot trace, watch classes enhanced by skywalking agent](https://github.com/alibaba/arthas/issues/1141), V8.1.0 or above is compatible, refer to skywalking configuration for more details. [skywalking compatible with other javaagent bytecode processing](https://github.com/apache/skywalking/blob/v8.1.0/docs/en/FAQ/Compatible-with-other-javaagent-bytecode-processing.md). \ No newline at end of file diff --git a/site/src/site/sphinx/en/tt.md b/site/src/site/sphinx/en/tt.md index 6c0845af6..da877a462 100644 --- a/site/src/site/sphinx/en/tt.md +++ b/site/src/site/sphinx/en/tt.md @@ -127,7 +127,7 @@ $ tt -i 1003 Affect(row-cnt:1) cost in 11 ms. ``` -### Replay record +#### Replay record Since Arthas stores the context of the call, you can even *replay* the method calling afterwards with extra option `-p` to replay the issue for advanced troubleshooting, option `--replay-times` define the replay execution times, option `--replay-interval` define the interval(unit in ms,with default value 1000) of replays @@ -152,13 +152,50 @@ Time fragment[1004] successfully replayed. Affect(row-cnt:1) cost in 14 ms. ``` +#### Watch express + +`-w, --watch-express` watch the time fragment by ognl express. + +* You can used all variables in [fundamental fields in expressions](advice-class.md) for the watch express。 + +```bash +[arthas@10718]$ tt -t demo.MathGame run -n 5 +Press Q or Ctrl+C to abort. +Affect(class count: 1 , method count: 1) cost in 56 ms, listenerId: 1 + INDEX TIMESTAMP COST(ms) IS-RET IS-EXP OBJECT CLASS METHOD +---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + 1000 2021-01-08 21:54:17 0.901091 true false 0x7699a589 MathGame run +[arthas@10718]$ tt -w 'target.illegalArgumentCount' -x 1 -i 1000 +@Integer[60] +Affect(row-cnt:1) cost in 7 ms. +``` + +* Get a static field and calling a static method + +```bash +[arthas@10718]$ tt -t demo.MathGame run -n 5 +Press Q or Ctrl+C to abort. +Affect(class count: 1 , method count: 1) cost in 56 ms, listenerId: 1 + INDEX TIMESTAMP COST(ms) IS-RET IS-EXP OBJECT CLASS METHOD +---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + 1000 2021-01-08 21:54:17 0.901091 true false 0x7699a589 MathGame run +[arthas@10718]$ tt -w '@demo.MathGame@random.nextInt(100)' -x 1 -i 1000 +@Integer[46] +``` + +Note that `com.taobao.arthas.core.advisor.Advice#getLoader` is used here, and that it is better to use the exact `classloader` [ognl](ognl.md). + + +Advanced usage [get spring context to call the bean method](https://github.com/alibaba/arthas/issues/482) + + F.Y.I 1. **Loss** of the `ThreadLocal` Arthas save params into an array, then invoke the method with the params again. The method execute in another thread, so the `ThreadLocal` **lost**. -1. params may be modified +2. params may be modified Arthas save params into an array, they are object references. The Objects may be modified by other code. diff --git a/site/src/site/sphinx/en/watch.md b/site/src/site/sphinx/en/watch.md index c1d67bcde..56373011a 100644 --- a/site/src/site/sphinx/en/watch.md +++ b/site/src/site/sphinx/en/watch.md @@ -235,6 +235,23 @@ ts=2018-12-03 20:04:34; [cost=131.303498ms] result=@Integer[8] ts=2018-12-03 20:04:35; [cost=0.961441ms] result=@Integer[8] ``` +#### Get a static field and calling a static method + +```bash +watch demo.MathGame * '{params,@demo.MathGame@random.nextInt(100)}' -v -n 1 -x 2 +[arthas@6527]$ watch demo.MathGame * '{params,@demo.MathGame@random.nextInt(100)}' -n 1 -x 2 +Press Q or Ctrl+C to abort. +Affect(class count: 1 , method count: 5) cost in 34 ms, listenerId: 3 +ts=2021-01-05 21:35:20; [cost=0.173966ms] result=@ArrayList[ + @Object[][ + @Integer[-138282], + ], + @Integer[89], +] +``` + +* Note that here you use `Thread.currentThread().getContextClassLoader()` to load, and it is better to use the exact `classloader` [ognl](ognl.md). + #### Exclude the specified class diff --git a/site/src/site/sphinx/faq.md b/site/src/site/sphinx/faq.md index 08a6a777f..4462e545d 100644 --- a/site/src/site/sphinx/faq.md +++ b/site/src/site/sphinx/faq.md @@ -48,4 +48,18 @@ options json-format true ```bash watch demo.MathGame primeFactors traceE '{params,returnObj,throwExp}' -v -n 5 -x 3 'params.length >0 && returnObj instanceof java.util.List' -``` \ No newline at end of file +``` + +##### 怎么watch、trace 构造函数 ? + +```bash +watch demo.MathGame '{params,returnObj,throwExp}' -v -n 5 -x 3 '1==1' +``` + + +##### java.lang.ClassFormatError: null、skywalking arthas 兼容使用 + +当出现这个错误日志`java.lang.ClassFormatError: null`,通常情况下都是被其他字节码工具修改过与arthas修改字节码不兼容。 + +比如: 使用 skywalking V8.1.0 以下版本 [无法trace、watch 被skywalking agent 增强过的类](https://github.com/alibaba/arthas/issues/1141), V8.1.0 以上版本可以兼容使用,更多参考skywalking配置 [skywalking compatible with other javaagent bytecode processing](https://github.com/apache/skywalking/blob/v8.1.0/docs/en/FAQ/Compatible-with-other-javaagent-bytecode-processing.md)。 + diff --git a/site/src/site/sphinx/tt.md b/site/src/site/sphinx/tt.md index bb3ea4580..165d65c9e 100644 --- a/site/src/site/sphinx/tt.md +++ b/site/src/site/sphinx/tt.md @@ -175,6 +175,44 @@ Affect(row-cnt:1) cost in 14 ms. 你会发现结果虽然一样,但调用的路径发生了变化,由原来的程序发起变成了 Arthas 自己的内部线程发起的调用了。 + +#### 观察表达式 + +`-w, --watch-express` 观察时空隧道使用`ognl` 表达式 + +* 使用[表达式核心变量](advice-class.md)中所有变量作为已知条件编写表达式。 + +```bash +[arthas@10718]$ tt -t demo.MathGame run -n 5 +Press Q or Ctrl+C to abort. +Affect(class count: 1 , method count: 1) cost in 56 ms, listenerId: 1 + INDEX TIMESTAMP COST(ms) IS-RET IS-EXP OBJECT CLASS METHOD +---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + 1000 2021-01-08 21:54:17 0.901091 true false 0x7699a589 MathGame run +[arthas@10718]$ tt -w 'target.illegalArgumentCount' -x 1 -i 1000 +@Integer[60] +Affect(row-cnt:1) cost in 7 ms. +``` + +* 获取类的静态字段、调用类的静态方法 + +```bash +[arthas@10718]$ tt -t demo.MathGame run -n 5 +Press Q or Ctrl+C to abort. +Affect(class count: 1 , method count: 1) cost in 56 ms, listenerId: 1 + INDEX TIMESTAMP COST(ms) IS-RET IS-EXP OBJECT CLASS METHOD +---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + 1000 2021-01-08 21:54:17 0.901091 true false 0x7699a589 MathGame run +[arthas@10718]$ tt -w '@demo.MathGame@random.nextInt(100)' -x 1 -i 1000 +@Integer[46] +``` + +注意这里使用 `com.taobao.arthas.core.advisor.Advice#getLoader`加载,使用精确`classloader` [ognl](ognl.md)更好。 + + +高级用法 [获取spring context 调用bean 方法](https://github.com/alibaba/arthas/issues/482) + + - 需要强调的点 1. **ThreadLocal 信息丢失** diff --git a/site/src/site/sphinx/watch.md b/site/src/site/sphinx/watch.md index e843dbc7f..85937ac33 100644 --- a/site/src/site/sphinx/watch.md +++ b/site/src/site/sphinx/watch.md @@ -235,6 +235,23 @@ ts=2018-12-03 20:04:34; [cost=131.303498ms] result=@Integer[8] ts=2018-12-03 20:04:35; [cost=0.961441ms] result=@Integer[8] ``` +#### 获取类的静态字段、调用类的静态方法的例子 + +```bash +watch demo.MathGame * '{params,@demo.MathGame@random.nextInt(100)}' -v -n 1 -x 2 +[arthas@6527]$ watch demo.MathGame * '{params,@demo.MathGame@random.nextInt(100)}' -n 1 -x 2 +Press Q or Ctrl+C to abort. +Affect(class count: 1 , method count: 5) cost in 34 ms, listenerId: 3 +ts=2021-01-05 21:35:20; [cost=0.173966ms] result=@ArrayList[ + @Object[][ + @Integer[-138282], + ], + @Integer[89], +] +``` + +* 注意这里使用 `Thread.currentThread().getContextClassLoader()` 加载,使用精确`classloader` [ognl](ognl.md)更好。 + #### 排除掉指定的类 > watch/trace/monitor/stack/tt 命令都支持 `--exclude-class-pattern` 参数