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

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使用的时间

async-profiler性能分析工具_第1张图片

喜欢的同学可以多多关注小k
async-profiler性能分析工具_第2张图片

你可能感兴趣的:(debug)