Create Custom Events for Flight Recorder
In this custom events for JFR exercise we will use an example from a different repository – the java-svc repo. Clone the following repository:
Follow the instructions to build the application which uses custom Flight Recorder events. Make sure you use a JDK 11 or later.
Open a command line and go to the java-svc/jfr folder.
Next run target/bin/runFibonacci.
View custom Flight Recorder events
Connect to the process with JMC. The process starts with a recording already running, so you can simply dump the whole thing when you feel ready. Either let it run for a few minutes and then dump it, or go with the pre-recorded recording present in the 09_JFR_CustomEvents project.
Open the Threads view. Sort on Thread Groups and shift-click to select the two threads in the Fibonacci thread group:
Inspect custom Mission Control events
Right click on the graph and enable the viewing of other event types in a separate lane per thread:
You can now hover over the events to see what they contain.
Custom Flight Recorder Events Example Exercises
- How long did it take to calculate the longest Fibonacci number? How long did it take to calculate the shortest one?
Hint: Go to the Event Browser, click on the Fibonacci Event. Sort on Duration.
- Verify that the iterative version is not cheating by making sure that the calculation of both the iterative and recursive version of the algorithm come to the same value.
Hint: Go to the Event Browser, click on the Fibonacci Event. Sort on Fibonnaci Number.
- Did you notice any difference in performance between the two algorithms?
Here are some additional videos and articles of mine (Cameron McKenzie) about Java Mission Control and Java Flight Recorder:
- Quick Introduction to Java Mission Control
- Java Mission Control 8 Eclipse plugin Install
- Fix Java memory leaks without costly JVM heap dumps
- The performance cost of autoboxing Java primitive types
- How to start Java's JVM Flight Recorder 3 easy ways
- Performance Problems with Synchronized Methods