29

是谁在调用我?使用arthas+jprofiler做复杂链路分析

 3 years ago
source link: https://mp.weixin.qq.com/s/atCmxnpgfnv7Q_kklnec_g
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Arthas是阿里巴巴开源的应用诊断利器,提供了profiler命令,可以生成热点火焰图。通过采样录制调用链路来做性能分析,极大提升了线上排查性能问题的效率。

但是有一个问题,当async-profiler全量采样导出的svg文件太大时,想要找到关键的调用点,就非常困难。

比如下图:

640?wx_fmt=jpeg

没有办法做聚合或过滤,这方面本地的profiler工具比如jprofiler、yourkits就方便很多,有没有办法将两者结合起来呢?

经过分析发现,async-profiler支持jfr (Java Flight Recorder)格式输出,jprofiler也支持打开jfr快照,成了!具体操作步骤如下:

1. arthas采样生成jfr文件

启动arthas之后,执行以下采样命令:

profiler start -f /home/admin/yourAppName/target/arthas-output/%t.jfr -d 180

%t 表示当前时间,-d 后面是采样秒数,更多参数参见:https://alibaba.github.io/arthas/profiler.htmlhttps://github.com/jvm-profiling-tools/async-profiler/blob/v1.6/src/arguments.cpp

2. 下载jfr到本地

可以用oss倒腾,或者szrz等其他途径倒腾到本地。

3. jprofiler分析

在做性能分析时我们常常想要找出:是谁在调用我,是谁调用我最多。下面举例介绍怎么做的。

3.1 打开快照

使用jprofiler打开jfr文件,选择Open a snapshot, 打开之后选择CPU views

640?wx_fmt=jpeg

2

3.2 反向分析

View -> Find 查找要分析的类和方法,然后选择 Analyze -> Calculate Backtraces to Selected Method

640?wx_fmt=jpeg

3

3.3 分析结果

修改Summation mode 为Total times,即可看到这个方法被哪些上游调用到,调用量和占比

640?wx_fmt=jpeg

4

  1. 通过Arthas profiler命令生成jfr文件;
  2. 在本地通过jprofiler来分析jfr文件,定位谁在调用我;
  3. 运用之妙,存乎一心。工具的互相结合,可以产生奇妙的化学反应。

Arthas正在征文:那些年,用Arthas排查过的问题。欢迎大家在“原文链接”里投稿,有丰富的奖品等你噢。

  • 凡提交满足投稿要求文章的同学,将获得 Arthas Most Valuable User 福袋一份(礼品随机),包含淘公仔、Arthas 贴纸、阿里云 T 恤、JetBrains 周边礼包;

  • 第一期最受欢迎的 top3 文章,获得天猫精灵一台;

  • 年度 top 20 文章,将有机会获得 cherry 键盘及 JetBrains 提供的包括 Coupon 等周边礼包 。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK