借助arthas工具打火焰图

小丫11个月前技术文章1528

1、下载arthas

在命令行下面执行(使用和目标进程一致的用户启动,否则可能 attach 失败):

curl -O https://arthas.aliyun.com/arthas-boot.jar
java -jar arthas-boot.jar
  • 执行该程序的用户需要和目标进程具有相同的权限。比如以admin用户来执行:sudo su admin && java -jar arthas-boot.jarsudo -u admin -EH java -jar arthas-boot.jar

  • 如果 attach 不上目标进程,可以查看~/logs/arthas/ 目录下的日志。

  • 如果下载速度比较慢,可以使用 aliyun 的镜像:java -jar arthas-boot.jar --repo-mirror aliyun --use-http

  • java -jar arthas-boot.jar -h 打印更多参数信息。

2、选择应用 java 进程

$ $ java -jar arthas-boot.jar
* [1]: 35542
  [2]: 71560 math-game.jar

3、借助profiler 打火焰图

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

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

参数说明

参数名称参数说明
action要执行的操作
actionArg属性名模式
[i:]采样间隔(单位:ns)(默认值:10'000'000,即 10 ms)
[f:]将输出转储到指定路径
[d:]运行评测指定秒
[e:]要跟踪哪个事件(cpu, alloc, lock, cache-misses 等),默认是 cpu

3.1 启动profile

$ profiler start
Started [cpu] profiling

提示

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

3.2 获取已采集的 sample 的数量

$ profiler getSamples
23

3.3 查看 profiler 状态

$ profiler status
[cpu] profiling is running for 4 seconds

3.4停止 profiler

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

$ profiler stop --format html
profiler output file: /tmp/test/arthas-output/20211207-111550.html
OK

3.5 通过浏览器查看  profiler 结果

默认情况下,arthas 使用 3658 端口,则可以打开: http://localhost:3658/arthas-output/在新窗口打开 查看到arthas-output目录下面的 profiler 结果:

image.png

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

image.png

通常情况下我们的目标服务器和本地电脑网络不通,可以将结果文件下载到本地电脑,然后用浏览器打开查看。

4、profiler 支持的 events

在不同的平台,不同的 OS 下面,支持的 events 各有不同。比如,在 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


相关文章

开源大数据集群部署(十五)Zookeeper集群部署

开源大数据集群部署(十五)Zookeeper集群部署

1、集群规划主机版本角色系统用户hd1.dtstack.com3.7.1followerzookeeperhd2.dtstack.com3.7.1leaderzookeeperhd3.dtstack....

数据湖技术之iceberg(六)Iceberg表数据组织与查询

数据湖技术之iceberg(六)Iceberg表数据组织与查询

1     Iceberg表数据组织与查询1) 下载avro-tools jar包由于后期需要查看avro文件内容,我们可以通过avro-tool.jar来查看...

大数据组件--Hive与Impala的异同

大数据组件--Hive与Impala的异同

一、同数据存储:使用相同的存储数据池都支持把数据存储于HDFS, HBase。元数据:两者使用相同的元数据。SQL语法:基本类似。二、异1)、底层运行使用的技术hive底层默认使用mapreduce引...

Presto开发语句简介

Presto开发语句简介

根据presto中的结构配置,catalog表示连接,主要看presto中catalog文件夹下的配置,一般包含hive、mysql等,其中可以根据业务的不同设置多个配置文件。schema表示连接中的...

clickhouse集群部署(一)

clickhouse集群部署(一)

1、rpm包下载安装部署完整包地址:https://packages.clickhouse.com/rpm/stable/📎clickhouse-common-static-dbg-22.8.4.7....

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。