JFR View Command - Sip of Java

The new JFR view command was added in Java 21, providing a way to analyze JFR recordings from the command line without needing to download a recording and open it in a tool like JDK Mission Control. Let’s take a look at how to use the new JFR View command.

Using the JFR View Command

JFR View can be accessed through the jfr command line tool and the jcmd tool.

JFR Tool

JFR View can be used with the jfr tool with the following pattern:

$ jfr view [view] [recording file] 

JCMD tool

JFR View can be used with the jcmd tool with the following pattern:

$ jcmd [pid] JFR.view [view]

View Options

Over 70 different view options have been provided with the initial release of the the JFR view command, a number likely to increase in the future. Each view provides different perspectives across the stack from the application level, to the JVM, to the environment.

Java virtual machine views:
 class-modifications       gc-concurrent-phases longest-compilations   
 compiler-configuration    gc-configuration     native-memory-committed
 compiler-phases           gc-cpu-time          native-memory-reserved 
 compiler-statistics       gc-pause-phases      safepoints             
 deoptimizations-by-reason gc-pauses            tlabs                  
 deoptimizations-by-site   gc-references        vm-operations          
 gc                        heap-configuration  

Environment views:
 active-recordings        cpu-information       jvm-flags          
 active-settings          cpu-load              native-libraries   
 container-configuration  cpu-load-samples      network-utilization
 container-cpu-throttling cpu-tsc               recording          
 container-cpu-usage      environment-variables system-information 
 container-io-usage       events-by-count       system-processes   
 container-memory-usage   events-by-name        system-properties  

Application views:
 allocation-by-class   exception-count       native-methods       
 allocation-by-site    file-reads-by-path    object-statistics    
 allocation-by-thread  file-writes-by-path   pinned-threads       
 class-loaders         finalizers            socket-reads-by-host 
 contention-by-address hot-methods           socket-writes-by-host
 contention-by-class   latencies-by-type     thread-allocation    
 contention-by-site    longest-class-loading thread-count         
 contention-by-thread  memory-leaks-by-class thread-cpu-load      
 exception-by-message  memory-leaks-by-site  thread-start         
 exception-by-site     modules              

A view can be used like this example:

$ jfr view thread-count [recording-file]

Modifying View Output

There are several options to modify the formatting of the data returned from JFR View:

--width [number-of-columns]
--cell-height [number of rows]
--truncate beginning

These options need to be provided before the view, like in this example:

$ jfr view --width 40 thread-count recording.jfr


         Java Thread Statistics

Time    Acti... Daem... Accu... Peak...
------- ------- ------- ------- -------
21:4...      26      22     145      34

Additional Reading

View Command

Happy coding!