Arthas火焰图使用

2023/03/22

Tags: arthas

arthas 火焰图相关命令

arthasprofiler 命令支持生成应用热点的火焰图。本质上是通过不断的采样,然后把收集到的采样结果生成火焰图。

启动arthas:

java -jar arthas-boot.jar

开始收集火焰图:

[arthas@1]$ profiler start
Profiling started
[arthas@1]$ profiler status
Profiling is running for 6 seconds
[arthas@1]$ profiler status
Profiling is running for 27 seconds
[arthas@1]$ profiler getSamples 
2
[arthas@1]$ profiler getSamples 
4
[arthas@1]$ profiler stop --file /tmp/cpu-result-1.html
OK
profiler output file: /tmp/cpu-result-1.html

命令说明:

关键参数说明

event

-e, –event 默认采集 CPU 信息,可设:cpu, alloc, lock, cache-misses etc

如果想采集内存信息,可以用以下命令:

profiler start --event alloc

file

-f, --file <value> 输出的文件,主要支持 html, jfr 两种格式;

profiler stop  --file /tmp/cpu-result-1.html

duration

-d, --duration <value> 指定结束时间;

profiler 执行 30 秒自动结束:

profiler start --duration 30

火焰图分析方法

arthas-output

arthas 火焰图颜色说明:

这里分析java进程,主要看绿色部分;

纵轴表示函数调用栈,每一层是一个函数;

横轴表示抽样数,每一格的宽度越宽,表示它被抽样到的次数越多,侧面反应执行时间越长;火焰图的每一格,鼠标悬浮时会显示完整的函数名、占据总抽样次数的百分比,以此来对比不同函数的耗时差别;

  1. CPU 火焰图,能找出cpu占用高的问题函数,分析代码热路径;
  2. 内存火焰图,能找到内存占用高的对象,申请内存多的函数;

参考:

https://arthas.aliyun.com/doc/profiler.html