Generate a Java program Flame diagram using the Linux perf tool

Source: Internet
Author: User

Important references:www.brendangregg.com/blog/2017-06-30/package-flame-graph.html

Java flamegraph(flame diagram) can display the performance analysis results of Java programs very intuitively, and it is easy to discover hot spots and further tuning of programs. This article shows you how to use the Linux perf tool to generate a flame diagram of a Java program. The flame diagram looks roughly like this:

Http://www.brendangregg.com/blog/images/2014/cpu-vertx-flamegraph.svg

the horizontal axis of a flame chart represents a time-consuming percentage of a method that occupies a The more CPUs, the vertical axis represents the function call relationship, and the top represents the top of the call.

Linux perf is a powerful performance analysis tool under Linux. For study, please refer to:https://www.ibm.com/developerworks/cn/linux/l-cn-perf1/index.html

Use Perf Tool Generation Java the flame diagram of the program requires only two steps , as shown in the following commands:

Superf record-f 99-a--sleep;./jmapsperf Script |./pkgsplit-perf.pl | grep jav A |./flamegraph.pl > Out.svg

The first step is to use the perf record to collect stack information when the program runs;

The second one uses perf script to generate the analysis results, and the resulting out.svg file is the flame diagram.


The above command also uses theJmaps,pkgsplit-perf.pl,flamegraph.pland other scripts, these scripts are categorized fromGitProjectHttps://github.com/brendangregg/FlameGraph. One of the highlights isJmapsscript that is the role of the script to getJava the symbol table when the program runs , so that in the executionPerf Scriptto generate meaningful stack information, the script relies on theGitProjectHttps://github.com/jvm-profiling-tools/perf-map-agent, the download of the project compiles successfully after theOutgenerated under directoryAttach-main.jarand theLibperfmap.sotwo files, which is gettingJavakey to the symbol table when the program runs. OpenJmapsfile, you can see the following code:

agent_home=${agent_home:-/usr/lib/jvm/perf-map-agent}# from Https://github.com/jvm-profiling-tools/perf-map-agent

you need to manually Agent_home Replace with the per-map-agent/out/directory that you just compiled .


Summary of issues:

perf-map-agent compilation failed

Perf-map-agent compilation requires CMake and jdk, please install cmake and jdk now, and configure Java_home.


Execution ./jmaps script error, error:not root user exiting ...

this is because the current user is not root, just comment out The following code in the Jmaps script:

if [["$USER"! = root]]; Then

echo "Error:not root user?" Exiting ... "

Exit

Fi


Execution ./jmaps script error, chown:changing ownership of '/tmp/perf-xxx. Map ': Operation not permitted

the code in the jmaps

if [[-E "$mapfile"]]; Then

Chown Root $mapfile

chmod 666 $mapfile

Else

Switch

if [[-E "$mapfile"]]; Then

sudo chownroot $mapfile

sudo chmod666 $mapfile

Else

Generate a Java program Flame diagram using the Linux perf tool

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.