async-profiler性能分析工具

async-profiler性能分析工具

可以对项目进行性能分析,可以追踪 CPU 周期,也可以追踪 Java 堆中的分配、锁争用,以及软件和硬件的性能计数器。

环境准备

async-profiler
cd /tmp // 你的项目目录
git clone https://github.com/jvm-profiling-tools/async-profiler
cd async-profiler
make

运行./profiler.sh可以看到工具的使用命令

$ ./profiler.sh
Usage: ./profiler.sh [action] [options] <pid>
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 <duration> seconds
  -f filename       dump output to <filename>
  -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

<pid> 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

FlameGraph火焰图工具

cd /tmp // 你的目录
git clone https://github.com/brendangregg/FlameGraph

完整操作

cd /tmp
./profiler.sh -d 10 -o collapsed -f /tmp/collapsed.txt pid   // 其中10代表采集10秒数据, pid代表jps的进程id
cd ../FlameGraph // 去到FlameGraph项目目录
./flamegraph.pl --colors=java /tmp/collapsed.txt > ./tmp/flamegraph.svg

这样便在/tmp目录下生成svg的火焰图文件了,可以通过浏览器打开,如下图

其中,绿色代表用户栈,黄色代表jvm,红色代表内核;横坐标代表cpu使用的时间

在这里插入图片描述

喜欢的同学可以多多关注小k
在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值