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 primeFactorsClassLoader:
+-sun.misc.Launcher$AppClassLoader@1909752+-sun.misc.Launcher$ExtClassLoader@a14482Location:
/D:/arthas/math-game.jarpublic 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