Arthas profiler(使用async-profiler对应用采样,生成火焰图)

在这里插入图片描述

二、命令列表

2.4 profiler(使用async-profiler对应用采样,生成火焰图)

使用场景:

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参数指定的文件名后缀为 htmljfr 时,文件格式可以被推断出来。比如--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

本人其他相关文章链接

1.Arthas 全攻略:让调试变得简单
2.Arthas dashboard(当前系统的实时数据面板)
3.Arthas thread(查看当前JVM的线程堆栈信息)
4.Arthas jvm(查看当前JVM的信息)
5.Arthas sysprop(查看和修改JVM的系统属性)
6.Arthas sysenv(查看JVM的环境变量)
7.Arthas vmoption(查看和修改 JVM里诊断相关的option)
8.Arthas getstatic(查看类的静态属性 )
9.Arthas heapdump(dump java heap, 类似 jmap 命令的 heap dump 功能)
10.Arthas logger(查看 logger 信息,更新 logger level)
11.Arthas mbean(查看 Mbean 的信息)
12.Arthas memory(查看 JVM 内存信息)
13.Arthas ognl(执行ognl表达式)
14.Arthas perfcounter(查看当前 JVM 的 Perf Counter 信息)
15.Arthas vmtool(从 jvm 里查询对象,执行 forceGc)
16.Arthas jad(字节码文件反编译成源代码 )
17.Arthas mc(Memory Compiler/内存编译器 )
18.Arthas redefine(加载外部的.class文件,redefine到JVM里 )
19.Arthas classloader (查看 classloader 的继承树,urls,类加载信息)
20.Arthas sc(查看JVM已加载的类信息 )
21.Arthas sm(查看已加载类的方法信息 )
22.Arthas monitor(方法执行监控)
23.Arthas stack (输出当前方法被调用的调用路径)
24.Arthas trace (方法内部调用路径,并输出方法路径上的每个节点上耗时)
25.Arthas tt(方法执行数据的时空隧道,记录下指定方法每次调用的入参和返回信息,并能对这些不同的时间下调用进行观测)
26.Arthas watch (方法执行数据观测)
27.Arthas profiler(使用async-profiler对应用采样,生成火焰图)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

刘大猫.

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值