Troubleshooting with Java Flight Recorder

background purpose

Let's use Oracle Java Mission Control (JMC) / Java Flight Recorder (JFR), which is a paid monitoring and troubleshooting tool available from Oracle Java7 u40 or later.

What is JMC / JFR?

--Java application monitoring and troubleshooting tool provided by Java SE Advanced, a paid product of Oracle Java. --However, JMC / JFR itself (required binary / mechanism) is already included in the (ordinary) Oracle JDK that can be downloaded free of charge, so it can be used free of charge for verification purposes on a personal PC. In short, the paid product Java SE Advanced offers only usage rights, and the binaries themselves are exactly the same. --So, no special download / installation is required, and you can use it immediately if you have the Oracle JDK installed. ――If you roughly distinguish between JMC and JFR, --JMC is a GUI and simple real-time monitoring, --JFR is a profiler that records the behavior of Java applications (airplane black box --product name after Flight Recorder) ――However, in general, both are called JMC or JFR. --Since the recording (profiling) mechanism itself is included in Oracle's HotSpot JVM, there is little overhead due to recording. --Recording records are output as a file with a ".jfr" extension, so you can analyze this file by viewing it from the JMC GUI. --Originally a feature of jRockIt, a former BEA (acquired by Oracle) JVM, ported by Oracle from Oracle Java7 u40 or later so that it can also be used with the Oracle HotSpot JVM. ――There have been various kinds of diagnostic tools and commands in Java so far, but is Oracle aiming to make it almost covered by JMC / JFR?

Verification environment

--Oracle JDK 8 latest --OS: Windows 7 (Of course, any type of OS can be used as long as the JDK runs)

References

--oracle.com --JMC / JFR --JMC / JFR Official Website --docs.oracle.com --Oracle Commercial Features --JMC / JFR --Official Manual -Marcus Hirt --JMC Tutorial --This is a must! You can understand how to use and analyze JFR based on the sample code. --JavaOne 2016 --Java Mission Control 5.5 --Presentation materials can be downloaded -YouTube --Java Mission Control --JMC / JFR overview video for about 30 minutes -YouTube --Java Mission Control Demo --JMC / JFR demo video of about 10 minutes -docs.oracle.com --Java Platform, Standard Edition Troubleshooting Guide -O'Reilly --Java Performance: The Definitive Guide --Overview of JMC / JFR in "Chapter 3. A Java Performance Toolbox" and other chapters Introducing tuning examples using JFR

Download and install

--JMC / JFR itself is built into the JDK, so if you already have the JDK installed, no additional downloads or installations are required! You can start using it according to the execution method below. --If you want to use Eclipse Plugin, download it from the following site (not required) - [Oracle Java Mission Control for Eclipse] (http://download.oracle.com/technology/products/missioncontrol/updatesites/experimental/5.5.0/eclipse/)

Execution method

--Starting JMC / JFR GUI --Execute $ {JAVA_HOME} \ bin \ jmc.exe --Enable JFR --Just add the following parameters to the JVM startup parameters! - -XX:+UnlockCommercialFeatures -XX:+FlightRecorder --There are three ways to start JFR recording (example of outputting with the name my_recording.jfr). ―― 1. Specified by the startup argument - java.exe -XX:+UnlockCommercialFeatures -XX:+FlightRecorder -XX:StartFlightRecording=duration=60s,filename=my_recording.jfr MyJavaApplication --2 Start with jcmd command - jcmd <PID> JFR.start duration=60s filename=my_recording.jfr ―― 3. Start from JMC GUI (easiest) --Described in the next section

Quickly move what it looks like

1. What to prepare

Download the "Java SE Development Kit 8uXXX Demos and Samples Downloads zip" from the JDK Download Site. Actually, the sample file of jfr is also included in this.

--Location: sample \ missioncontrol \ flightrecordings folder in the above downloaded zip file --Sample file --java2d_demo.jfr: JFR recording sample of demo \ jfc \ Java2D \ Java2Demo.jar in the zip file --wldf.jfr: [WebLogic MedRec Sample](http://www.oracle.com/webfolder/technetwork/tutorials/obe/fmw/wls/12c/12_2_1/02-34-004-DeploySampleApplication/deploysampleapplication.html# JFR recording sample in section 4)

2. Browse the already recorded jfr file

Execute $ {JAVA_HOME} \ bin \ jmc.exe image

Select java2d_demo.jfr from File-> Open File ... and open it. Like below If you can see the screen, it's OK. image

3. Try to record it yourself

Let's actually record using Java2Demo.jar included in Java Demos and Samples.

Step1. Run the sample app

Execute the Java2Demo.jar file as follows

SET JDK_HOME=<JDK path>
SET PRG=D:\A_Dev\Java\jdk-8u101-windows-x64-demos\jdk1.8.0_101\demo\jfc\Java2D\Java2Demo.jar
SET JVM=-Xmx32m -Xms16m ← To generate GC frequently. Not required
SET JFR=-XX:+UnlockCommercialFeatures -XX:+FlightRecorder

%JDK_HOME%\bin\java %JVM% %JFR% -jar %PRG%

Click here for the screen image of Java2Demo.jar. To load, select the tab "Transforms" and set the Anim delay on the right side of the screen short.

image

Step2. Start the JMC screen

When you start jmc.exe, the following screen is displayed. You should see the Java2Demo.jar process on the left. The second "The JVM Running Mission Control" process on the left is jmc's own process.

image

Step3. Flight record from JMC screen

Right-click on the process part and select "Start Flight Recording ...". image

From the "Start Flight Recording" screen below, set the recording time to "1 min" and the event setting to "Profiling --on server". Click the "Finish" button to start recording. image

The following pop-up will appear and recording will start. While waiting for 1 minute, play around with the Java2Demo.jar app (with or without load). image

Step4. Browse the recorded jfr

After 1 minute, the .jfr file that has been recorded automatically should start up.

Confirmation point 1-General

You can see the average and maximum values of "heap usage", "CPU usage", and "GC pause time" recorded for 1 minute as shown below. image

Confirmation point 2 --GC

Select the "Memory" main tab on the left and select the "Garbage Collection" subtab. It can be seen that GC occurs frequently as shown below. image

Confirmation point 3 --Hot Methods

Select the "Code" main tab on the left and select the "Hot Methods" subtab. You can see that java.util.HashMap.put, java.awt.TexturePaintContext ... was called most often during the 1 minute of recording. image

JMC / JFR screen configuration

The overall screen configuration consists of the main tab on the left and the sub-tabs for each main tab. The screen configuration for each main tab is as follows (* The WebLogic main tab in the screen capture is what you see if you have the WebLogic plugin installed)

General

image

Memory

image

Code

image

Thread

image

I/O image

System

image

Event

image

List of each main tab / sub tab

(* Below, tab names are written in English. Since most of the various manuals and references are in English, it is easier to get used to them with English names.)

No Main Tab Sub Tab Description
1_1 General Overview Basic information such as maximum heap usage, total CPU usage and GC pause time
1_2 JVM Information JVM information
1_3 System Properties All system properties set at the OS level
1_4 Recording Information at the time of JFR recording (which event was turned on)
2_1 Memory Overview General information about memory usage and statistics about garbage collection
2_2 Garbage Collections Information about memory usage over time and all garbage collection
2_3 GC Times Information about how long it took to run the GC and how long the application paused completely due to the GC
2_4 GC Configuration Information about GC configuration
2_5 Allocations All memory allocations made.* TLAB (Thread Local Area Buffer) -A small memory area to which new objects are allocated
2_6 Object Statistics Class with live set
3_1 Code Overview Shows the packages and classes that spent the most execution time
3_2 Hot Methods Most sampled method
3_3 Call Tree View hot method threads in reverse order
3_4 Exceptions Show thrown exception
3_5 Compilations Shows compiled methods when the application was running
3_6 Class Loading Shows the number of classes loaded over time, the classes actually loaded and the classes unloaded
4_1 Thread Overview Changes in CPU usage and number of threads over time
4_2 Hot Threads Shows threads that do most of the code execution
4_3 Contention Lock contention information
4_4 Latencies Call sleep or wait, read from socket, file I/Show other causes of waiting time, such as waiting for O
4_5 Thread Dumps Shows periodic thread dumps that can be triggered in the record
4_6 Lock Instances Shows the exact instance of the object most waiting for synchronization
5_1 I/O Overview
5_2 File Reads File I/O read
5_3 File Writes File I/O write
5_4 Socket Reads Network I/O read
5_5 Socket Writes Network I/O write
6_1 System Overview CPU, Memory,OS information
6_2 Process System process information at the time of recording
6_3 Environment System environment variable information at the time of recording
7_1 Event Overview
7_2 Log
7_3 Graph
7_4 Threads
7_5 Stack Traces
7_6 Histogram

Recommended Posts

Troubleshooting with Java Flight Recorder
Check heap usage with Java Flight Recorder
I checked Java Flight Recorder (JFR)
Run analysis with OpenJDK11 Java Flight Recorder + Google Kubernetes Engine
OpenJDK 11 Flight Recorder
Install java with Homebrew
Change seats with java
Install Java with Ansible
Docker-Client Java API Troubleshooting
[Java] GlassFish 5 Troubleshooting Log
Switch java with direnv
Download Java with Ansible
Let's scrape with Java! !!
Build Java with Wercker
Endian conversion with JAVA
Easy BDD with (Java) Spectrum?
Use Lambda Layers with Java
Java multi-project creation with Gradle
Java Config with Spring MVC
Let's experiment with Java inlining
[Template] MySQL connection with Java
Rewrite Java try-catch with Optional
Install Java 7 with Homebrew (cask)
[Java] JSON communication with jackson
Java to play with Function
Try DB connection with Java
Enable Java EE with NetBeans 9
[Java] JavaConfig with Static InnerClass
Try gRPC with Java, Maven
Let's operate Excel with Java! !!
Version control Java with SDKMAN
RSA encryption / decryption with java 8
Sort strings functionally with java
Object-oriented (java) with Strike Gundam
[Java] Content acquisition with HttpCliient
Java version control with jenv
Streamline Java testing with Spock
Connect to DB with Java
Connect to MySQL 8 with Java
Error when playing with java
Using Mapper with Java (Spring)
Java study memo 2 with Progate
Getting Started with Java Basics
Seasonal display with Java switch
Use SpatiaLite with Java / JDBC
Study Java with Progate Note 1
Compare Java 8 Optional with Swift
HTML parsing with JAVA (scraping)
Run Java VM with WebAssembly
Screen transition with swing, java
Java unit tests with Mockito
[Java 8] Duplicate deletion (& duplicate check) with Stream
Create an immutable class with JAVA
Java lambda expressions learned with Comparator
[Java, Scala] Image resizing with ImageIO
Install java with Ubuntu 16.04 based Docker
Java to learn with ramen [Part 1]
Use java with MSYS and Cygwin
Distributed tracing with OpenCensus and Java
100% Pure Java BDD with JGiven (Introduction)
Install Java and Tomcat with Ansible