trace java_trace

动态trace¶

3.3.0 版本后支持。

打开终端1,trace上面demo里的run函数,可以看到打印出 listenerId: 1:

[arthas@59161]$ trace demo.MathGame run

Press Q or Ctrl+C to abort.

Affect(class count: 1 , method count: 1) cost in 112 ms, listenerId: 1

`---ts=2020-07-09 16:48:11;thread_name=main;id=1;is_daemon=false;priority=5;TCCL=sun.misc.Launcher$AppClassLoader@3d4eac69

`---[1.389634ms] demo.MathGame:run()

`---[0.123934ms] demo.MathGame:primeFactors() #24 [throws Exception]

`---ts=2020-07-09 16:48:12;thread_name=main;id=1;is_daemon=false;priority=5;TCCL=sun.misc.Launcher$AppClassLoader@3d4eac69

`---[3.716391ms] demo.MathGame:run()

+---[3.182813ms] demo.MathGame:primeFactors() #24

`---[0.167786ms] demo.MathGame:print() #25

现在想要深入子函数primeFactors,可以打开一个新终端2,使用telnet localhost 3658连接上arthas,再trace primeFactors时,指定listenerId。

[arthas@59161]$ trace demo.MathGame primeFactors --listenerId 1

Press Q or Ctrl+C to abort.

Affect(class count: 1 , method count: 1) cost in 34 ms, listenerId: 1

这时终端2打印的结果,说明已经增强了一个函数:Affect(class count: 1 , method count: 1),但不再打印更多的结果。

再查看终端1,可以发现trace的结果增加了一层,打印了primeFactors函数里的内容:

`---ts=2020-07-09 16:49:29;thread_name=main;id=1;is_daemon=false;priority=5;TCCL=sun.misc.Launcher$AppClassLoader@3d4eac69

`---[0.492551ms] demo.MathGame:run()

`---[0.113929ms] demo.MathGame:primeFactors() #24 [throws Exception]

`---[0.061462ms] demo.MathGame:primeFactors()

`---[0.001018ms] throw:java.lang.IllegalArgumentException() #46

`---ts=2020-07-09 16:49:30;thread_name=main;id=1;is_daemon=false;priority=5;TCCL=sun.misc.Launcher$AppClassLoader@3d4eac69

`---[0.409446ms] demo.MathGame:run()

+---[0.232606ms] demo.MathGame:primeFactors() #24

| `---[0.1294ms] demo.MathGame:primeFactors()

`---[0.084025ms] demo.MathGame:print() #25

通过指定listenerId的方式动态trace,可以不断深入。另外 watch/tt/monitor等命令也支持类似的功能。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值