While trying out these examples, I was thinking whether we can generate a CPU Flame Graph from a Java Flight Recording Dump.
Hot Methods and Call Tree tabs in Java Mission Control are there to get an understanding of "hot spots" in your code. But I was really interested to see a Flame Graph visualization by reading the JFR dump. In this way, you can quickly see "hot spots" by using the Flame Graph software.
Even though, this is an easy way, it takes more time and the resulting XML file is quite large. For example, I parsed a JFR dump around 61MB and the XML was around 5.8GB!
Converting JFR Method Profiling Samples to FlameGraph compatible format.
I wrote a simple Java program to read a JFR file and convert all stack traces from "Method Profiling Samples" to FlameGraph compatible format.
I used the JMC Parser in the program. I couldn't find a way to get Method Profiling Samples using the Reference Parser. I was only able to find the "vm/prof/execution_sample" events from the reference parser and there was no way to get the stack trace from that event.
The JMC Parser was very easy to use and I was able to get the stack traces without much trouble.
Following is the FlameGraph created from a sample JFR dump.
I got the JFR dump by running a sample application, which consumes more CPU resources. Original source files were obtained from a StackOverflow answer, which explains a way to find a thread consuming high CPU resources. Please note that the package name and line numbers are different in the FlameGraph output when comparing with original source code in StackOverflow Answer. (I will try to share the complete source code later).
The ELK stack is a popular stack for searching and analyzing data. Many people use it for analyzing logs. WSO2 also has a full-fledged Big Data Analytics Platform, which can analyze logs and do many more things. In this blog post, I'm explaining on how to monitor logs with Elasticsearch , Logstash and Kibana . I will mainly explain logstash configurations. I will not show how to set up Elasticsearch and Kibana. Those are very easy to setup and there are not much configurations. You can just figure it out very easily! :) If you want to test an elasticsearch server, you can just extract the elasticsearch distribution and start an elasticsearch server. If you are using Kibana 3, you need to use a web server to host the Kibana application. With Kibana 4, you can use the standalone server provided in the distribution. Configuring Logstash Logstash is a great tool for managing events and logs. See Getting Started with Logstash if you haven't used ...
Java Virtual Machine can tune itself depending on the environment and this smart tuning is referred to as Ergonomics . When tuning Java , it's important to know which values were used as default for Garbage collector, Heap Sizes, Runtime Compiler by Java Ergonomics There are many JVM command line flags. So, how do we find out which JVM flags are used? It turns out that JVM has flags to print flags. :) I tested following commands with Java 8. $ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 15.04 Release: 15.04 Codename: vivid $ uname -a Linux isurup-ThinkPad-T530 3.19.0-26-generic #28-Ubuntu SMP Tue Aug 11 14:16:32 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux Printing Command Line Flags We can use "-XX:+PrintCommandLineFlags" to print the command line flags used by the JVM. This is a useful flag to see the values selected by Java Ergonomics. $ java -XX:+PrintCommandLineFlags -version -XX:InitialHeapSize=...
Update (September 14, 2015): Java 8 Update 60 was released on August 18, 2015. There are some recent changes to "perf-map-agent". There is no longer a script named "perf-java" and you should use "bin/create-java-perf-map.sh " Brendan Gregg shared an exciting news in his Monitorama talk: The " JDK-8068945 " is fixed in Java 8 Update 60 Build 19 ! Without this fix, it was not possible to see full stack in Java with Linux perf_events and standard JDK (without any patches). For more information, see Brendan's Java CPU Flame Graphs page. The Problem with Java and Perf First of all, let's see what's the problem with using current latest Java and perf. For this example, I used the same program explained in my previous blog post regarding FlameGraphs . java org.wso2.example.JavaThreadCPUUsage.App Then I sampled on-CPU functions for Java program using perf. (See Brendan's Perf Examples ) sudo perf record -F 99 -g -...
Comments