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%
相关推荐
Cooper251 小时前
DDC 命令成功但屏幕不动:用 gamma 表重做亮度映射
python·mac
师夷长技以自愈1 小时前
手搓 AI Agent 第 7 篇:菜做砸了别硬炒——错误分类 + 双账本熔断
人工智能·python
用户956256254292 小时前
15 分钟社媒简报 Agent:我只用了搜索和模型两步
python·api
Dumbness2 小时前
关键词回复里写了 {订单号},群机器人整条消息都炸了
python·微信
调接口的阿光2 小时前
调用对话接口时输出被截断怎么办:先看 finish_reason,再决定是续写一次、缩小范围,还是换成更短的格式(Python)
人工智能·python
Cooper252 小时前
单文件 Flask 跑通微信服务器校验:先跑通再谈工程化
python·flask
Cooper252 小时前
三源热榜去重加 AI 摘要:URL 唯一键踩出的三个坑
前端·python
用户4019925568612 小时前
多源异构 B2B 公开需求信号去重与企业实体证据链存储设计(64-bit SimHash 分桶 + Jaccard)
python
aifannihao2 小时前
GitHub Actions 锁文件实测:6 个 uses 只锁住 2 个
python·ci/cd·标准库·供应链安全·github actions
2601_967980113 小时前
使用gensim处理文本(1)语料库与词向量空间
python·自然语言处理·gensim·词向量·文本分析