stack === > 输出当前方法被调用的调用路径 很多时候我们都知道一个方法被执行,但这个方法被执行的路径非常多,或者你根本就不知道这个方法是从那里被执行了,此时你需要的是 stack 命令。 ### 参数说明 |参数名称|参数说明| |---:|:---| |*class-pattern*|类名表达式匹配| |*method-pattern*|方法名表达式匹配| |*condition-express*|条件表达式| |[E]|开启正则表达式匹配,默认为通配符匹配| |`[n:]`|执行次数限制| 这里重点要说明的是观察表达式,观察表达式的构成主要由 ognl 表达式组成,所以你可以这样写`"{params,returnObj}"`,只要是一个合法的 ognl 表达式,都能被正常支持。 观察的维度也比较多,主要体现在参数 `advice` 的数据结构上。`Advice` 参数最主要是封装了通知节点的所有信息。 请参考[表达式核心变量](advice-class.md)中关于该节点的描述。 * 特殊用法请参考:[https://github.com/alibaba/arthas/issues/71](https://github.com/alibaba/arthas/issues/71) * OGNL表达式官网:[https://commons.apache.org/proper/commons-ognl/language-guide.html](https://commons.apache.org/proper/commons-ognl/language-guide.html) ### 使用例子 #### 启动 Demo 启动[快速入门](quick-start.md)里的`arthas-demo`。 #### stack ```bash $ stack demo.MathGame primeFactors Press Ctrl+C to abort. 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) ``` #### 据条件表达式来过滤 ```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) Command execution times exceed limit: 2, so command will exit. You can set it with -n option. ``` #### 据执行时间来过滤 ```bash $ stack demo.MathGame primeFactors '#cost>5' Press Ctrl+C to abort. 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) ```