Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

选择目标进程,输入对应的序号并输入回车即可进入对该进程的监控。

Image RemovedImage Added


Dashboard

进入监控后,输入dashboard命令,即可看到整个进程的概况。输入Q或Ctrl+c可退出预览。

...

  1. 进程内的线程概况:线程运行时间,线程运行状态等

  2. 进程的内存使用概况:例如堆内和堆外内存使用情况,新生代、老年代等对象占用情况

  3. 运行环境信息:操作系统版本、JDK版本等

Image RemovedImage Added


Profiler

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

注意,linux系统支持所有profiler功能,mac系统支持部分功能,windows系统不支持profiler功能。

常用的profiler指令如下:

Code Block
languagebash
#开始抽样,-e可用于指定抽样的event,可以是cpu或alloc
profiler start -e cpu;
​
#查看抽样任务执行的时间
profiler status;
​
#查看抽样任务的抽样数量
profiler getSamples;
​
#结束抽样,并将结果的火焰图输出为html格式,--file可指定输出的文件
profiler stop --format html --file /mnt/d/arthas/cpu.html;

抽样任务输出火焰图后,就要基于火焰图进行分析。

分析思路总结只有一句话:火焰图里,横条越长,代表使用的越多,从下到上是调用堆栈信息。

越宽表示被调用越多执行时间长,越高表示调用栈越深。

火焰图就是看顶层的哪个函数占据的宽度最大。只要有"平顶"(plateaus),就表示该函数可能存在性能问题。



CPU抽样

启动一次CPU抽样任务,执行一段时间后即可关闭,并输出结果火焰图。

Code Block
profiler start -e cpu;
profiler stop --format html --file /mnt/d/arthas/cpu.html;

下图展示了一次简单的单线程IoTDB写入任务执行过程中某一段时间的CPU抽样片段。

Image Added


内存抽样

...

进行内存分析时,堆分析器需要HotSpot调试符号,Oracle JDK已经将它们嵌入到libjvm.so中,但是OpenJDK在构建时,被打包到了单独的包中,如要在Debian/Ubuntu上安装OpenJDK调试符号

Code Block
apt install openjdk-8-dbg;


启动一次CPU抽样任务,执行一段时间后即可关闭,并输出结果火焰图。

Code Block
profiler start -e alloc;
profiler stop --format html --file /mnt/d/arthas/alloc.html;

下图展示了一次简单的单线程IoTDB写入任务执行过程中某一段时间的内存抽样片段。

Image Added

参考

Arthas 应用诊断利器 (aliyun.com)

...

arthas火焰图性能分析 - 掘金 (juejin.cn)

Async-profiler介绍_冯立彬的博客-CSDN博客_async-profiler