Arthas 火焰图的使用

Arthas 是阿里巴巴开源的 Java 诊断工具,火焰图是其中一个重要功能,用于可视化程序性能分析。

主要特点

  • 可视化性能分析:直观展示代码执行热点和调用栈
  • 实时监控:可实时查看应用性能状况
  • CPU 分析:主要分析 CPU 使用情况和耗时分布

基本命令

1. 生成火焰图

bash 复制代码
profiler start
# 等待一段时间收集数据
profiler stop

2. 指定采样时间

bash 复制代码
profiler start --duration 60

这会采集 60 秒的数据后自动生成火焰图

3. 查看支持的事件类型

bash 复制代码
profiler list

4. 指定特定事件

bash 复制代码
profiler start -e cpu

输出格式

  • 生成的火焰图通常保存为 HTML 文件
  • 可以在浏览器中打开交互式查看
  • 支持缩放和平移操作

实际应用场景

  1. 性能瓶颈定位:快速发现耗时较多的方法
  2. 热点分析:找出频繁调用的方法
  3. 调用链分析:了解方法间的调用关系
  4. CPU 使用优化:识别高 CPU 占用代码

注意事项

  • 需要确保目标进程有足够的权限运行 profiler
  • 采样时间过短可能导致数据不准确
  • 在生产环境使用时要注意对性能的影响

结果解读

  • 横轴表示采样比例,宽度越大表示占用时间越长
  • 纵轴表示调用栈深度
  • 颜色通常是随机分配,不具特殊含义

火焰图是性能分析的强大工具,能够帮助开发人员快速定位性能问题。

https://github.com/async-profiler/async-profiler

使用示例

bash 复制代码
[op@Core-marketo-02 project]$ java -jar  arthas-boot.jar 
[INFO] JAVA_HOME: /project/server/jdk-17.0.2
[INFO] arthas-boot version: 4.0.5
[INFO] Found existing java process, please choose one and input the serial number of the process, eg : 1. Then hit ENTER.
* [1]: 2166 api-8.0.0.jar
  [2]: 1687 org.apache.zookeeper.server.quorum.QuorumPeerMain
  [3]: 151557 web-8.0.0.jar
  [4]: 2136 service-8.0.0.jar


[INFO] local latest version: 4.0.5, remote latest version: 4.1.5, try to download from remote.
[INFO] Start download arthas from remote server: https://arthas.aliyun.com/download/4.1.5?mirror=center
[INFO] Download arthas success.
[INFO] arthas home: /home/op/.arthas/lib/4.1.5/arthas
[INFO] Try to attach process 2166
Picked up JAVA_TOOL_OPTIONS: 
[INFO] Attach process 2166 success.
[INFO] arthas-client connect 127.0.0.1 3658
  ,---.  ,------. ,--------.,--.  ,--.  ,---.   ,---.                           
 /  O  \ |  .--. ''--.  .--'|  '--'  | /  O  \ '   .-'                          
|  .-.  ||  '--'.'   |  |   |  .--.  ||  .-.  |`.  `-.                          
|  | |  ||  |\  \    |  |   |  |  |  ||  | |  |.-'    |                         
`--' `--'`--' '--'   `--'   `--'  `--'`--' `--'`-----'                          

wiki         https://arthas.aliyun.com/doc                                      
tutorials    https://arthas.aliyun.com/doc/arthas-tutorials.html                
version      4.1.5                                                              
main_class   api-8.0.0.jar   
pid          2166                                                               
start_time   2026-01-23 08:04:22.102                                            
current_time 2026-01-28 09:54:56.779                                            

[arthas@2166]$ profiler start
Profiling started
[arthas@2166]$ profiler list
Basic events:
  cpu
  alloc
  nativemem
  lock
  wall
  itimer
  ctimer
Java method calls:
  ClassName.methodName
[arthas@2166]$ profiler stop
OK
profiler output file: /project/20260128-095611.html
[arthas@2166]$ profiler start -e cpu
Profiling started
[arthas@2166]$ profiler stop
OK
profiler output file: /project/20260128-095646.html
[arthas@2166]$ exit
Session has been terminated.
Arthas is still running in the background.
To completely shutdown arthas, please execute the 'stop' command.
[op@Core-marketo-02 project]$ sz /project/20260128-095611.html

下载 20260128-095611.html: 15.0 KB 100%

OO[op@Core-marketo-02 project]sz /project/20260128-095646.html

下载 20260128-095646.html: 8.5 KB 100%
相关推荐
han_hanker2 分钟前
重新认识枚举enum
开发语言
鹏易灵1 小时前
C++——8.移动语义初探(移动构造、移动赋值)
开发语言·c++·php
2601_962341301 小时前
计算机毕业设计之jsp考研在线复习平台
java·大数据·开发语言·hadoop·python·考研·课程设计
凯瑟琳.奥古斯特1 小时前
力扣1008:前序重建BST
开发语言·c++·算法·leetcode·职场和发展
2zcode1 小时前
项目文档:基于MATLAB图像处理的饮料瓶灌装液位检测系统设计与实现
开发语言·图像处理·matlab
云烟成雨TD1 小时前
LangFlow 1.x 系列【7】工作流创建与部署指南
人工智能·python·agent
月疯2 小时前
np.where()[0]的用法
开发语言·python·numpy
z落落2 小时前
C#五大加密算法(AES、DES、MD5、RSA、SHA)
开发语言·c#
namexingyun2 小时前
Scaling Law bug实战启示:从“虚胖“到“精瘦“的算力效率革命
开发语言·网络·人工智能·bug·ai编程
KaMeidebaby2 小时前
卡梅德生物技术快报|纳米抗体技术全套实操流程:AFB1 全合成文库淘选 + 分子对接定点突变参数手册
人工智能·python·tcp/ip·算法·机器学习