Files

3.1 KiB

使用async-profiler生成火焰图

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

profiler{{}} 命令基本运行结构是 profiler action [actionArg]{{}}

查看所有支持的 action

profiler actions{{execute T2}}

查看版本

profiler version{{execute T2}}

启动 profiler

profiler start --event cpu{{execute T2}}

默认情况下,生成的是 cpu 的火焰图,即 event 为cpu{{}} 。可以用--event{{}} 参数来指定。

获取已采集的 sample 的数量

profiler getSamples{{execute T2}}

查看 profiler 状态

profiler status{{execute T2}}

停止 profiler

生成 html 格式结果

默认情况下,结果文件是html{{}} 格式。也可以用--format{{}} 参数指定:

profiler stop --format html{{execute T2}}

或者在--file{{}} 参数里用文件名指名格式。比如--file /root/arthas-output/result.html{{}} 。

profiler stop --file /root/arthas-output/result.html{{execute T2}}

通过浏览器查看 arthas-output 下面的 profiler 结果

默认情况下,arthas 使用 8563 http 端口,点击打开 输入账号 arthas 和密码 arthas 查看 arthas-output/ 目录下面的 profiler 结果:

点击可以查看具体的结果:

profiler 支持的 events

profiler list{{execute T2}}

在不同的平台,不同的 OS 下面,支持的 events 各有不同。比如在 macos 下面:

$ profiler list
Basic events:
  cpu
  alloc
  lock
  wall
  itimer

在 linux 下面

$ profiler list
Basic events:
  cpu
  alloc
  lock
  wall
  itimer
Perf events:
  page-faults
  context-switches
  cycles
  instructions
  cache-references
  cache-misses
  branches
  branch-misses
  bus-cycles
  L1-dcache-load-misses
  LLC-load-misses
  dTLB-load-misses
  mem:breakpoint
  trace:tracepoint

如果遇到 OS 本身的权限/配置问题,然后缺少部分 event,可以参考async-profiler{{}} 本身文档:async-profiler

可以用--event{{}} 参数指定要采样的事件,比如对alloc{{}} 事件进入采样:

profiler start --event alloc{{execute T2}}

恢复采样

profiler resume{{execute T2}}

start{{}} 和resume{{}} 的区别是:start{{}} 是新开始采样,resume{{}} 会保留上次stop{{}} 时的数据。

可执行profiler getSamples{{}} 可以查看 samples 的数量来验证。

使用execute{{}} 来执行复杂的命令

比如开始采样:

profiler execute 'start,framebuf=5000000'{{execute T2}}

停止采样,并保存到指定文件里:

profiler execute 'stop,file=/root/arthas-output/result.html'{{execute T2}}

具体的格式参考: arguments.cpp