java性能火焰图的生成实践
目录
- 序言
- 1、准备程序
- 3、展示
- 总结
序言
如果你经常遇到 Java 线上性能问题束手无策,看着线上服务 CPU 飙升一筹莫展,发现内存不断泄露满脸茫然。
别慌,这里有一款低开销、自带火焰图、让你大呼好用的 Java 性能分析工具 - async-profiler。
1、准备程序
[root@localhost ~]# git clone git://github.com/jvm-profiling-tools/async-profiler [root@localhost async-profiler]# yum -y install gcc+ gcc-c++ [root@localhost async-profiler]# make [root@localhost ~]# more Test.java public class Test { public static void maphpin(String[] args) throws Exception { Test test = new Test(); while (true) { test.func1(); test.func2(); test.func3(); } } public void func1() throws Exception { //调用第一个方法,需要100ms Thread.sleep(100L); } public void func2() throws Exception { //调用第二个方法,需要500ms Thread.sleep(500L); } public void func3() throws Exception { //调用第三个方法,需要1500ms Thread.sleep(1500L); } } [root@localhost ~]# [root@localhost ~]# javac Test.java [root@localhost ~]# java Test
生成火焰图数据
root 21765 7152 0 18:29 pts/1 00:00:00 java Test root 21799 21777 0 18:29 pts/0 00:00:00 grep --color=auto java [root@localhost ~]# cd async-profiler/ [root@localhost async-profiler]# [root@localhost async-profiler]# ./profiler.sh -d 60 -o collapsed -f /tmp/test_01.txt 21765 Profiling for 60 seconds Done [root@localhost async-profiler]# cd .. [root@localhost ~]# ls anaconda-ks.cfg a.out async-profiler FlameGraph jdk-8u121-linux-x64.tar.gz perf.data process.svg test.c Test.cwww.devze.comlass Test.java [root@localhost ~]# cd FlameGraph/ [root@localhost FlameGraph]# perl flamegraph.pl --colors=java /tmp/test_01.txt > test_01.svg [root@localhost FlameGraph]# ls aix-perf.pl example-perf-stacks.txt.gz README.md stackcollapse-instruments.pl stackcollapse-pmc.pl test demos example-perf.svg record-test.sh stackcollapse-java-exceptions.pl stackcollapse-recursive.pl test_01.svg dev files.pl stackcollapse-aix.pl stackcollapse-jstack.pl stackcollapse-sample.awk test.sh difffolded.pl flamegraph.pl stackcollapse-bpftrhttp://www.devze.comace.pl stackcollapse-ljp.awk stackcollapse-stap.pl docs jmaps stackcollapse-elfutils.pl stackcollapse-perf.pl stackcollapse-vsprof.pl example-dtrace-stacks.txt pkgsplit-perf.pl stackcollapse-gdb.pl stackcollapse-perf-sched.awk stackcollapse-vtune.pl example-dtr编程客栈ace.svg rangeandroid-perf.pl stackcollapse-go.pl stackcollapse.pl stackcollapse-xdebug.php [root@localhost FlameGraph]# sz test_01.svg
3、展示
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程客栈(www.devze.com)。
精彩评论