Arthas常用的命令(三)--monitor、jad 、stack

monitor:监控方法的执行情况

监控指定类中方法的执行情况
用来监视一个时间段中指定方法的执行次数,成功次数,失败次数,耗时等这些信息

  • 参数说明

方法拥有一个命名参数 [c:],意思是统计周期(cycle of output),拥有一个整型的参数值

参数名称 参数说明
class-pattern 类名表达式匹配
method-pattern 方法名表达式匹配
-E 开启正则表达式匹配,默认为通配符匹配
-c 统计周期,默认值为120秒
  • 示例: 监控demo.MathGame类,并且每5S更新一次状态。
monitor *.MathGame primeFactors -c 5

执行结果如下:

  • 结果说明 :
监控项 说明
timestamp 时间戳
class Java类
method 方法(构造方法、普通方法)
total 调用次数
success 成功次数
fail 失败次数
rt 平均耗时
fail-rate 失败率

jad 反编译

  • jad 反编译代码:
jad 包的路径.类名 方法名

如果不确定包的路径,也可以用 *. 匹配,比如 Demo类,就是 *.Demo。

示例如下:

jad *.MathGame primeFactors

结果如下:

可以看到反编译后的代码。

[arthas@18228]$ jad *.MathGame primeFactors

ClassLoader:
+-sun.misc.Launcher$AppClassLoader@1909752
  +-sun.misc.Launcher$ExtClassLoader@a14482

Location:
/D:/arthas/math-game.jar

       public List<Integer> primeFactors(int number) {
/*44*/     if (number < 2) {
/*45*/         ++this.illegalArgumentCount;
               throw new IllegalArgumentException("number is: " + number + ", need >= 2");
           }
           ArrayList<Integer> result = new ArrayList<Integer>();
/*50*/     int i = 2;
/*51*/     while (i <= number) {
/*52*/         if (number % i == 0) {
/*53*/             result.add(i);
/*54*/             number /= i;
/*55*/             i = 2;
                   continue;
               }
/*57*/         ++i;
           }
/*61*/     return result;
       }

Affect(row-cnt:1) cost in 103 ms.

stack 参数说明

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

参数名称 参数说明
class-pattern 类名表达式匹配
method-pattern 方法名表达式匹配
condition-express 条件表达式
-E 开启正则表达式匹配,默认为通配符匹配
-n 执行次数限制
-m 指定 Class 最大匹配数量,默认值为 50。
  • stack查看调用路径:
[arthas@19440]$ stack *.MathGame primeFactors
Press Q or Ctrl+C to abort.
Affect(class count: 1 , method count: 1) cost in 63 ms, listenerId: 25
ts=2023-06-09 22:57:47;thread_name=main;id=1;is_daemon=false;priority=5;TCCL=sun.misc.Launcher$AppClassLoader@1909752
    @demo.MathGame.primeFactors()
        at demo.MathGame.run(MathGame.java:24)
        at demo.MathGame.main(null:-1)
  • 根据执行时间来过滤:
[arthas@19440]$ stack demo.MathGame primeFactors '#cost>0.5'
Press Q or Ctrl+C to abort.
Affect(class count: 1 , method count: 1) cost in 29 ms, listenerId: 29
ts=2023-06-09 23:06:37;thread_name=main;id=1;is_daemon=false;priority=5;TCCL=sun.misc.Launcher$AppClassLoader@1909752
    @demo.MathGame.primeFactors()
        at demo.MathGame.run(MathGame.java:24)
        at demo.MathGame.main(null:-1)

参考资料:

https://blog.csdn.net/lydms/article/details/125238249

posted on   乐之者v  阅读(508)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
历史上的今天:
2022-06-23 LeetCode回溯算法的解题思路
< 2025年3月 >
23 24 25 26 27 28 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 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示