arthas 查看哪个方法调用最耗时_Arthas 查看方法调用路径上的每个节点上耗时

安装

快速安装

wget https://alibaba.github.io/arthas/arthas-boot.jar && java -jar arthas-boot.jar

选择应用java进程:

$ $ java -jar arthas-boot.jar

* [1]: 35542

[2]: 71560 arthas-demo.jar

Demo进程是第2个,则输入2,再输入回车/enter。Arthas会attach到目标进程上,并输出日志:

2

[INFO] Start download arthas from remote server: https://maven.aliyun.com/repository/public/com/taobao/arthas/arthas-packaging/3.1.1/arthas-packaging-3.1.1-bin.zip

[INFO] Download arthas success.

[INFO] arthas home: /root/.arthas/lib/3.1.1/arthas

[INFO] Try to attach process 74

[INFO] Attach process 74 success.

[INFO] arthas-client connect 127.0.0.1 3658

,---. ,------. ,--------.,--. ,--. ,---. ,---.

/ O \ | .--. ''--. .--'| '--' | / O \ ' .-'

| .-. || '--'.' | | | .--. || .-. |`. `-.

| | | || |\ \ | | | | | || | | |.-' |

`--' `--'`--' '--' `--' `--' `--'`--' `--'`-----'

wiki https://alibaba.github.io/arthas

tutorials https://alibaba.github.io/arthas/arthas-tutorials

version 3.1.1

pid 74

time 2019-07-02 18:05:29

诊断Docker里的Java进程

docker exec -it ${containerId} /bin/bash -c "wget https://alibaba.github.io/arthas/arthas-boot.jar && java -jar arthas-boot.jar"

demo

$ docker exec -it arthas-demo /bin/sh -c "java -jar /opt/arthas/arthas-boot.jar"

* [1]: 9 jar

[INFO] arthas home: /opt/arthas

[INFO] Try to attach process 9

[INFO] Attach process 9 success.

[INFO] arthas-client connect 127.0.0.1 3658

,---. ,------. ,--------.,--. ,--. ,---. ,---.

/ O \ | .--. ''--. .--'| '--' | / O \ ' .-'

| .-. || '--'.' | | | .--. || .-. |`. `-.

| | | || |\ \ | | | | | || | | |.-' |

`--' `--'`--' '--' `--' `--' `--'`--' `--'`-----'

wiki: https://alibaba.github.io/arthas

version: 3.0.5

pid: 9

time: 2018-12-18 11:30:36

诊断k8s里容器里的Java进程

kubectl exec -it ${pod} --container ${containerId} -- /bin/bash -c "wget https://alibaba.github.io/arthas/arthas-boot.jar && java -jar arthas-boot.jar"

sc

查看JVM已加载的类信息

$ sc demo.*

demo.MathGame

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

trace

方法内部调用路径,并输出方法路径上的每个节点上耗时

$ trace demo.MathGame run

Press Ctrl+C to abort.

Affect(class-cnt:1 , method-cnt:1) cost in 42 ms.

`---ts=2018-12-04 00:44:17;thread_name=main;id=1;is_daemon=false;priority=5;TCCL=sun.misc.Launcher$AppClassLoader@3d4eac69

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

+---[0.05638ms] java.util.Random:nextInt()

+---[10.036885ms] demo.MathGame:primeFactors()

`---[0.170316ms] demo.MathGame:print()

过滤掉jdk的函数

$ trace -j demo.MathGame run

Press Ctrl+C to abort.

Affect(class-cnt:1 , method-cnt:1) cost in 31 ms.

`---ts=2018-12-04 01:09:14;thread_name=main;id=1;is_daemon=false;priority=5;TCCL=sun.misc.Launcher$AppClassLoader@3d4eac69

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

+---[4.465779ms] demo.MathGame:primeFactors()

`---[0.375324ms] demo.MathGame:print()

据调用耗时过滤

$ trace demo.MathGame run '#cost > 10'

Press Ctrl+C to abort.

Affect(class-cnt:1 , method-cnt:1) cost in 41 ms.

`---ts=2018-12-04 01:12:02;thread_name=main;id=1;is_daemon=false;priority=5;TCCL=sun.misc.Launcher$AppClassLoader@3d4eac69

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

+---[0.006783ms] java.util.Random:nextInt()

+---[11.852594ms] demo.MathGame:primeFactors()

`---[0.05447ms] demo.MathGame:print()

trace多个类或者多个函数

trace命令只会trace匹配到的函数里的子调用,并不会向下trace多层。因为trace是代价比较贵的,多层trace可能会导致最终要trace的类和函数非常多。

可以用正则表匹配路径上的多个类和函数,一定程度上达到多层trace的效果。

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

layering-cache

为监控而生的多级缓存框架 layering-cache这是我开源的一个多级缓存框架的实现,如果有兴趣可以看一下

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值