@toc
使用场景:
profiler
命令支持生成应用热点的火焰图。本质上是通过不断的采样,然后把收集到的采样结果生成火焰图。提示
使用async-profiler在新窗口打开生成火焰图
火焰图的含义:
火焰图是基于 perf 结果产生的SVG 图片,用来展示 CPU 的调用栈。
y 轴表示调用栈,每一层都是一个函数。调用栈越深,火焰就越高,顶部就是正在执行的函数,下方都是它的父函数。
x 轴表示抽样数,如果一个函数在 x 轴占据的宽度越宽,就表示它被抽到的次数多,即执行的时间长。注意,x 轴不代表时间,而是所有的调用栈合并后,按字母顺序排列的。
火焰图就是看顶层的哪个函数占据的宽度最大。只要有"平顶"(plateaus),就表示该函数可能存在性能问题。
颜色没有特殊含义,因为火焰图表示的是 CPU 的繁忙程度,所以一般选择暖色调。
注意
:生成的火焰图要从linux服务器下载到本地然后才能打开,而不是浏览器直接输入IP:端口去打开,那样无效。
profiler
命令支持生成应用热点的火焰图。本质上是通过不断的采样,然后把收集到的采样结果生成火焰图。
profiler 命令基本运行结构是:
profiler action [actionArg]
profiler
命令的格式基本与上游项目 async-profiler在新窗口打开 保持一致,详细的使用方式可参考上游项目的 README、Github Disscussions 以及其他文档资料。
参数说明:
参数名称 | 参数说明 |
---|---|
action | 要执行的操作 |
actionArg | 属性名模式 |
i: | 采样间隔(单位:ns)(默认值:10'000'000,即 10 ms) |
f: | 将输出转储到指定路径 |
d: | 运行评测指定秒 |
e: | 要跟踪哪个事件(cpu, alloc, lock, cache-misses 等),默认是 cpu |
常用命令:
profiler | 命令作用 |
---|---|
profiler start | 启动profiler,默认情况下,生成cpu的火焰图 |
profiler list | 显示所有支持的事件 |
profiler getSamples | 获取已采集的sample的数量 |
profiler status | 查看profiler的状态,运行的时间 |
profiler stop | 停止profiler,生成火焰图的结果,指定输出目录和输出格式:svg或html |
启动profiler
,默认情况下,生成的是 cpu 的火焰图,即 event 为cpu
。可以用event`参数指定其他性能分析模式,见下文。
$ profiler start
Started [cpu] profiling
显示支持的事件
profiler list
获取已采集的sample
的数量
$ profiler getSamples
23
查看profiler
状态(可以查看当前profiler
在采样哪种event
和采样时间。)
$ profiler status
[cpu] profiling is running for 4 seconds
停止profiler
,并同步生成文件(默认在工作目录
下的arthas-output
目录。)
$ profiler stop
profiler output file: /tmp/demo/arthas-output/20240919-155147.svg
通过 --file
参数来指定输出结果路径,在--file
参数指定的文件名后缀为 html
或 jfr
时,文件格式可以被推断出来。比如--file /tmp/result.html
将自动生成火焰图。
# 指定生成的文件名以及路径
profiler stop --file /tmp/result.svg
可以用--format
指定生成格式,默认情况下,结果是 Flame Graph格式的 html
文件,也可以用 -o
或 --format
参数指定其他内容格式,包括 flat、traces、collapsed、flamegraph、tree、jfr。
profiler stop --format html
生成的图
profiler 支持的 events
在不同的平台,不同的 OS 下面,支持的 events 各有不同。比如在 macos 下面:
$ profiler list
Basic events:
cpu
alloc
lock
wall
itimer
在 linux 下面
$ profiler list
Basic events:
cpu
alloc
lock
wall
itimer
Java method calls:
ClassName.methodName
Perf events:
page-faults
context-switches
cycles
instructions
cache-references
cache-misses
branch-instructions
branch-misses
bus-cycles
L1-dcache-load-misses
LLC-load-misses
dTLB-load-misses
rNNN
pmu/event-descriptor/
mem:breakpoint
trace:tracepoint
kprobe:func
uprobe:path
如果遇到 OS 本身的权限/配置问题,然后缺少部分 event,可以参考 async-profiler 的文档在新窗口打开。
可以使用 check
action 测试某个 event 是否可用,此 action 的参数格式与 start 一致。
可以用--event
参数指定要采样的事件,比如 alloc
表示分析内存分配情况:
$ profiler start --event alloc
2.Arthas dashboard(当前系统的实时数据面板)
3.Arthas thread(查看当前JVM的线程堆栈信息)
5.Arthas sysprop(查看和修改JVM的系统属性)
7.Arthas vmoption(查看和修改 JVM里诊断相关的option)
9.Arthas heapdump(dump java heap, 类似 jmap 命令的 heap dump 功能)
10.Arthas logger(查看 logger 信息,更新 logger level)
14.Arthas perfcounter(查看当前 JVM 的 Perf Counter 信息)
15.Arthas vmtool(从 jvm 里查询对象,执行 forceGc)
17.Arthas mc(Memory Compiler/内存编译器 )
18.Arthas redefine(加载外部的.class文件,redefine到JVM里 )
19.Arthas classloader (查看 classloader 的继承树,urls,类加载信息)
23.Arthas stack (输出当前方法被调用的调用路径)
24.Arthas trace (方法内部调用路径,并输出方法路径上的每个节点上耗时)
25.Arthas tt(方法执行数据的时空隧道,记录下指定方法每次调用的入参和返回信息,并能对这些不同的时间下调用进行观测)
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有