Arthas stack (输出当前方法被调用的调用路径)

wan123 1天前 阅读数 3841 #性能测试

@[toc]

二、命令列表

2.3 monitor/watch/trace/stack/tt 相关

2.3.2 stack (输出当前方法被调用的调用路径)

使用场景:

stack 命令在 Arthas 中用于查看指定线程的调用栈信息,适用于以下场景:

  1. 故障排查:当应用出现性能问题或崩溃时,可以通过查看线程栈来定位问题源头。
  2. 死锁分析:监控线程状态,检查是否存在死锁或线程阻塞的情况。
  3. 性能优化:分析线程的执行路径,识别可能的性能瓶颈。

通过 stack 命令,开发者可以获取详细的线程执行信息,帮助快速定位和解决问题。

提示

输出当前方法被调用的调用路径。

很多时候我们都知道一个方法被执行,但这个方法被执行的路径非常多,或者你根本就不知道这个方法是从那里被执行了,此时你需要的是 stack 命令。

参数说明:

参数名称 参数说明
class-pattern 类名表达式匹配
method-pattern 方法名表达式匹配
condition-express 条件表达式
[E] 开启正则表达式匹配,默认为通配符匹配
[n:] 执行次数限制
[m <arg>] 指定 Class 最大匹配数量,默认值为 50。长格式为[maxMatch <arg>]

这里重点要说明的是观察表达式,观察表达式的构成主要由 ognl 表达式组成,所以你可以这样写"{params,returnObj}",只要是一个合法的 ognl 表达式,都能被正常支持。

观察的维度也比较多,主要体现在参数 advice 的数据结构上。Advice 参数最主要是封装了通知节点的所有信息。

举例1:输出当前方法被调用的调用路径,入口很多从哪调用的?

基础语法

stack 全路径类名 方法名

代码:

@Service
public class LdapService implements ILdapService {

    @Override
        public ResultSet login(LdapLoginRequest request) {
        ...
        }
}
[arthas@7265]$ stack com.hero.lte.ems.security.service.impl.LdapService login
ts=2024-09-19 11:41:56;thread_name=qtp1250442005-15694;id=3d4e;is_daemon=false;priority=5;TCCL=sun.misc.Launcher$AppClassLoader@18b4aac2
    @com.hero.lte.ems.security.service.impl.LdapService.login()
        at com.hero.lte.ems.security.config.shiro.CustomRealm.ldapLogin(CustomRealm.java:289)
        at com.hero.lte.ems.security.config.shiro.CustomRealm.kerberosLoginAuthenticationMode(CustomRealm.java:217)
        at com.hero.lte.ems.security.config.shiro.CustomRealm.doGetAuthenticationInfo(CustomRealm.java:157)

ts=2024-09-19 11:42:18;thread_name=qtp1250442005-15694;id=3d4e;is_daemon=false;priority=5;TCCL=sun.misc.Launcher$AppClassLoader@18b4aac2
    @com.hero.lte.ems.security.service.impl.LdapService.login()
        at com.hero.lte.ems.sysmanager.resources.SystemPersonalController.ldapServerConfigConnectionTest(SystemPersonalController.java:298)
        at com.hero.lte.ems.sysmanager.resources.SystemPersonalController$$FastClassBySpringCGLIB$$855fb4a7.invoke(<generated>:-1)
        at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)

结论:可以看出当前有2个入口调用了该方法,入口1是CustomRealm.ldapLogin,入口2是SystemPersonalController.ldapServerConfigConnectionTest

本人其他相关文章链接

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.

  • 随机文章
  • 热门文章
  • 热评文章
热门