You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
arthas/site/docs/doc/stack.md

87 lines
3.7 KiB
Markdown

# stack
7 years ago
[`stack`在线教程](https://arthas.aliyun.com/doc/arthas-tutorials.html?language=cn&id=command-stack)
::: tip
输出当前方法被调用的调用路径
:::
7 years ago
很多时候我们都知道一个方法被执行,但这个方法被执行的路径非常多,或者你根本就不知道这个方法是从那里被执行了,此时你需要的是 stack 命令。
## 参数说明
7 years ago
2 years ago
| 参数名称 | 参数说明 |
| ------------------: | :----------------------------------------------------------------- |
| _class-pattern_ | 类名表达式匹配 |
| _method-pattern_ | 方法名表达式匹配 |
| _condition-express_ | 条件表达式 |
| [E] | 开启正则表达式匹配,默认为通配符匹配 |
| `[n:]` | 执行次数限制 |
| `[m <arg>]` | 指定 Class 最大匹配数量,默认值为 50。长格式为`[maxMatch <arg>]`。 |
7 years ago
这里重点要说明的是观察表达式,观察表达式的构成主要由 ognl 表达式组成,所以你可以这样写`"{params,returnObj}"`,只要是一个合法的 ognl 表达式,都能被正常支持。
观察的维度也比较多,主要体现在参数 `advice` 的数据结构上。`Advice` 参数最主要是封装了通知节点的所有信息。
7 years ago
请参考[表达式核心变量](advice-class.md)中关于该节点的描述。
7 years ago
- 特殊用法请参考:[https://github.com/alibaba/arthas/issues/71](https://github.com/alibaba/arthas/issues/71)
- OGNL 表达式官网:[https://commons.apache.org/dormant/commons-ognl/language-guide.html](https://commons.apache.org/dormant/commons-ognl/language-guide.html)
7 years ago
## 使用例子
7 years ago
### 启动 Demo
7 years ago
启动[快速入门](quick-start.md)里的`math-game`。
6 years ago
### stack
6 years ago
```bash
$ stack demo.MathGame primeFactors
7 years ago
Press Ctrl+C to abort.
6 years ago
Affect(class-cnt:1 , method-cnt:1) cost in 36 ms.
ts=2018-12-04 01:32:19;thread_name=main;id=1;is_daemon=false;priority=5;TCCL=sun.misc.Launcher$AppClassLoader@3d4eac69
@demo.MathGame.run()
at demo.MathGame.main(MathGame.java:16)
7 years ago
```
2 years ago
### 指定 Class 最大匹配数量
```bash
$ stack demo.MathGame primeFactors -m 1
Press Q or Ctrl+C to abort.
Affect(class count:1 , method count:1) cost in 561 ms, listenerId: 5.
ts=2022-12-25 21:07:07;thread_name=main;id=1;is_daemon=false;priority=5;TCCL=sun.misc.Launcher$AppClassLoader@b4aac2
@demo.MathGame.primeFactors()
at demo.MathGame.run(MathGame.java:46)
at demo.MathGame.main(MathGame.java:38)
```
### 据条件表达式来过滤
6 years ago
```bash
$ stack demo.MathGame primeFactors 'params[0]<0' -n 2
Press Ctrl+C to abort.
Affect(class-cnt:1 , method-cnt:1) cost in 30 ms.
ts=2018-12-04 01:34:27;thread_name=main;id=1;is_daemon=false;priority=5;TCCL=sun.misc.Launcher$AppClassLoader@3d4eac69
@demo.MathGame.run()
at demo.MathGame.main(MathGame.java:16)
ts=2018-12-04 01:34:30;thread_name=main;id=1;is_daemon=false;priority=5;TCCL=sun.misc.Launcher$AppClassLoader@3d4eac69
@demo.MathGame.run()
at demo.MathGame.main(MathGame.java:16)
7 years ago
6 years ago
Command execution times exceed limit: 2, so command will exit. You can set it with -n option.
7 years ago
```
6 years ago
### 据执行时间来过滤
6 years ago
```bash
$ stack demo.MathGame primeFactors '#cost>5'
7 years ago
Press Ctrl+C to abort.
6 years ago
Affect(class-cnt:1 , method-cnt:1) cost in 35 ms.
ts=2018-12-04 01:35:58;thread_name=main;id=1;is_daemon=false;priority=5;TCCL=sun.misc.Launcher$AppClassLoader@3d4eac69
@demo.MathGame.run()
at demo.MathGame.main(MathGame.java:16)
7 years ago
```