Arthas常用的命令(二)--trace

发布时间 2023-06-09 22:49:36作者: 乐之者v

trace 参数

参数名称 参数说明
class-pattern 类名表达式匹配
method-pattern 方法名表达式匹配
condition-express 条件表达式
-E 开启正则表达式匹配,默认为通配符匹配
-n 命令执行次数
#cost 方法执行耗时
-m 指定 Class 最大匹配数量,默认值为 50。

trace 统计方法耗时

格式:

trace 包的路径.类名 方法名

示例:

[arthas@19440]$ trace *.MathGame  run
Press Q or Ctrl+C to abort.
Affect(class count: 1 , method count: 1) cost in 88 ms, listenerId: 15
`---ts=2023-06-08 21:26:27;thread_name=main;id=1;is_daemon=false;priority=5;TCCL=sun.misc.Launcher$AppClassLoader@1909752
    `---[0.9027ms] demo.MathGame:run()
        +---[9.72% 0.0877ms ] demo.MathGame:primeFactors() #24
        `---[58.40% 0.5272ms ] demo.MathGame:print() #25

trace 统计最耗时的方法

格式:

trace *.类名 *

*表示任意匹配。

trace根据条件展示耗时

  • 只会展示耗时大于 10ms 的调用
trace demo.MathGame run '#cost > 10'

trace 次数限制

  • 可以用-n参数加上数字,指定捕捉结果的次数
trace demo.MathGame run -n 1

trace 多个类或者多个函数

trace 命令只会 trace 匹配到的函数里的子调用,并不会向下 trace 多层。

可以用正则匹配路径上的多个类和函数,进行多层 trace 。

trace -E com.test.ClassA|org.test.ClassB method1|method2|method3

参考资料:

https://arthas.gitee.io/doc/trace.html