ali arthas 火焰图_arthas 火焰图神器-async-profiler

一、async-profiler

This project is a low overhead sampling profiler for Java that does not suffer from Safepoint bias problem. It features HotSpot-specific APIs to collect stack traces and to track memory allocations. The profiler works with OpenJDK, Oracle JDK and other Java runtimes based on the HotSpot JVM.(该项目是一个用于Java的低开销采样分析器,不会遇到安全点偏差问题。它具有特定于热点的api来收集堆栈跟踪和跟踪内存分配。探查器与OpenJDK、Oracle JDK和其他基于热点JVM的Java运行时一起工作。)

项目地址:https://github.com/jvm-profiling-tools/async-profiler

Async-profiler 可以跟踪以下类型的事件:

CPU cycles Cpu 周期

Hardware and Software performance counters like cache misses, branch misses, page faults, context switches etc. 硬件和软件性能计数器,如缓存缺失、分支缺失、页面错误、上下文切换等

Allocations in Java Heap Java 堆中的分配

Contented lock attempts, including both Java object monitors and ReentrantLocks 满足的锁尝试,包括 Java 对象监视器和 ReentrantLocks

注意: macOS 分析仅限于用户空间代码。

可以自己下载下来体验一下~ 这里需要知道的几点 async-profiler "基于当前时间段类对于数据进行收集"历史是咋样和当前数据收集没有关系。

profiler

看了下面的几种数据的收集,感觉cpu 收集应该是最好用的!在一个系统中性能优化分析耗死比较大,占用cpu比较大的资源非常有用。

ALLOCATION 内存分配可以让普罗米修斯这种监控工具、或者自己直接dump下来分析内存的占用。

Java method 方法的调用监控这个自己也可以的

Wall-clock 这个我不是很理解

CPU profiling

In this mode profiler collects stack trace samples that include Java methods, native calls, JVM code and kernel functions.(在这种模式下,profiler收集堆栈跟踪样本,包括Java方法、本机调用、JVM代码和内核函数。)

ALLOCATION profiling

Instead of detecting CPU-consuming code, the profiler can be configured to collect call sites where the largest amount of heap memory is allocated.(可以将探查器配置为收集分配最大堆内存的调用站点,而不是检测消耗CPU的代码。) 检查当前分配内存最多的地方。

Wall-clock profiling

-e wall option tells async-profiler to sample all threads equally every given period of time regardless of thread status: Running, Sleeping or Blocked. For instance, this can be helpful when profiling application start-up time. (Wall选项告诉async-profiler在给定的时间内对所有线程平均采样,而不管线程状态如何: 运行、休眠或阻塞。例如,在分析应用程序启动时间时,这可能会有所帮助。) Wall-clock profiler is most useful in per-thread mode: -t.

Java method profiling

-e ClassName.methodName option instruments the given Java method in order to record all invocations of this method with the stack traces.(ClassName.methodName选项使用给定的Java方法,以便使用堆栈跟踪记录此方法的所有调用。)

Usage

$ ./profiler.sh

Usage: ./profiler.sh [action] [options]

Actions:

start start profiling and return immediately

resume resume profiling without resetting collected data

stop stop profiling

check check if the specified profiling event is available

status print profiling status

list list profiling events supported by the target JVM

collect collect profile for the specified period of time

and then stop (default action)

Options:

-e event profiling event: cpu|alloc|lock|cache-misses etc.

-d duration run profiling for seconds

-f filename dump output to

-i interval sampling interval in nanoseconds

-j jstackdepth maximum Java stack depth

-b bufsize frame buffer size

-t profile different threads separately

-s simple class names instead of FQN

-g print method signatures

-a annotate Java method names

-o fmt output format: summary|traces|flat|collapsed|svg|tree|jfr

-I include output only stack traces containing the specified pattern

-X exclude exclude stack traces with the specified pattern

-v, --version display version string

--title string SVG title

--width px SVG width

--height px SVG frame height

--minwidth px skip frames smaller than px

--reverse generate stack-reversed FlameGraph / Call tree

--all-kernel only include kernel-mode events

--all-user only include user-mode events

--cstack mode how to traverse C stack: fp|lbr|no

is a numeric process ID of the target JVM

or 'jps' keyword to find running JVM automatically

Example: ./profiler.sh -d 30 -f profile.svg 3456

./profiler.sh start -i 999000 jps

./profiler.sh stop -o summary,flat jps

# 内存分配

./profiler.sh -d 10 -e alloc -f output-alloc.svg -t 1786

# cpu

./profiler.sh -d 10 -e cpu -f output-cpu.svg --all-user 1786

# trace 方法

./profiler.sh -d 10 -e com.wangji92.arthas.plugin.demo.common.profile.HotCode.hotMethod1 -f output-method.svg --all-user 1786

# cpu

./profiler.sh -d 10 -f output-cpu.svg --all-user 1786

#时钟信号

./profiler.sh -d 10 -e wall -f output-wall.svg -t 1786

# 支持的命令

./profiler.sh list 1786

#帮助文档

./profiler.sh

更多

更多可以参考这篇文章 可以更加深入的了解这个的使用

二、火焰图怎么看?

火焰图里,X轴越长,代表使用的越多,Y轴是调用堆栈信息。当前收集的是什么类型的数据,比如cpu 那么x轴长度越大,占用的cpu资源就越多~。

如何读懂火焰图?

使用Async-profiler 对程序性能优化实战

三、arthas async-profiler

arthas 结合了 async-profiler,看了一下源码和官方的一样的,调用本地方法进行处理,arthas 和 async-profiler 非常爽,命令相对于之前的简单了很多,async-profiler 的理解还是需要好好看一下官方的文档的!这篇文章写得不错,开始接触的时候看一下 使用Async-profiler 对程序性能优化实战。根据上面的一些官方文档 知道async-profiler 主要是解决哪些问题,结合上面的一个实战能够简单的理解火焰图。

基础命令

arthas + async-profiler 命令非常的简单,help profiler https://arthas.gitee.io/profiler.html

profiler start + 采集的命令 ; profiler stop 后即可查看 火焰图。

profiler start

# 等一会就可以查看了

profiler stop

采集信息

如async-profiler 官方一样 cpu、wall、alloc…等等 ,可以通过 下面的命令查看

profiler list

#结果

Basic events:

cpu

alloc

lock

wall

itimer

Java method calls:

ClassName.methodName

这个东西要记住还是特别复杂的

arthas idea 插件简化记忆

这个命令复杂?? 哈哈,更多了解 https://github.com/WangJi92/arthas-idea-plugin 这个版本还未2.13 还未发布敬请期待。想了解 添加钉钉群 32102545 沟通。

profiler start --event alloc --all-user --interval 10000000 --threads

arthas 交流群看到的~ 有兴趣的看一下

1)jprofiler/ async profiler 可以通过分析采样数据,看到聚合统计的方法时间

2)flare-profiler 通过分析采样数据,建立有时间维度的方法调用分析树,可以看到任意一次方法调用估算时间

https://github.com/kylixs/flare-profiler/

四、参考文档

官方文档

async-profiler采样分析器

超好用的自带火焰图的 Java 性能分析工具 Async-profiler 了解一下

https://www.wdbyte.com/2019/12/async-profiler/

Async-profiler介绍

使用Async-profiler 对程序性能优化实战

如何读懂火焰图?

五、总结

从编写插件到了解这个火焰图,用了一整天的来了解这个玩意,看了一些实践的例子,希望当我真正使用的适合能够带给我帮助吧!async-profiler 是基于样本的,对于收集的维度 一般为cpu 要查看一下是否收集到信息 profiler getSamples,火焰图展示的是当前时间段内的一些统计,对于当前时间段相关数据有一点的参考价值。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值