---
title: "Java Flight Recorder from Neovim"
canonical: "https://mnafshin.info/devtools/10-java-flight-recorder/"
author: "Afshin Amini"
date: 2026-11-29
updated: 2026-12-02
---
# Java Flight Recorder from Neovim

Java Flight Recorder, JFR for short, is a profiler built into every modern JDK. It records events from a running JVM, such as which methods use the CPU, garbage collections and thread locks, with low enough overhead to leave on. Neovim has no JFR plugin, and it does not need one: the JDK ships two command-line tools, `jcmd` and `jfr`, that start, save and read recordings, and Neovim can run both and show their output in a buffer.

## The two JDK tools

- **`jcmd`** sends commands to a running JVM. `JFR.start`, `JFR.check`, `JFR.dump` and `JFR.stop` control recordings.
- **`jfr`** reads a recording file. `jfr summary` lists the recorded events, and `jfr view` prints a named view as a text table.

Both come with the JDK from Part 1. The text views of `jfr view` and `jcmd JFR.view` arrived in JDK 21, so use a JDK 21 or newer; our test used JDK 25.

## Record from the start with a run configuration

The easiest recording starts with the app. Part 9 saved this run configuration in `.vscode/launch.json`:

```json
"vmArgs": "-XX:StartFlightRecording=filename=/tmp/shop.jfr,dumponexit=true"
```

[nvim-spring-ide: extras/vscode/launch.json](https://github.com/mnafshin/nvim-spring-ide/blob/main/extras/vscode/launch.json)

`-XX:StartFlightRecording` starts JFR when the JVM starts. `filename` says where to write, and `dumponexit=true` writes the file when the JVM exits. Start "Shop catalog on 8081 with JFR" with `<leader>dc` and call `/catalog` a few times; the recording is now running.

## Control a running app with jcmd

You don't have to stop the app to look at a recording. Open a terminal inside Neovim with `<leader>ft`, or run a single command with `:!`. First find the process id: `jcmd` with no arguments lists running JVMs, including `ShopApp`. Then ask about its recordings:

```sh
jcmd <pid> JFR.check
jcmd <pid> JFR.dump filename=/tmp/shop-dump.jfr
```

In our test `JFR.check` reported *Recording 1 ... (running)*, and `JFR.dump` wrote *1.1 MB* to `/tmp/shop-dump.jfr` while the app kept running. For an app started without the JVM option, `jcmd <pid> JFR.start` begins a recording on the spot.

JDK 21 and newer can also print a view of the live recording without a file. `jcmd <pid> JFR.view hot-methods` shows the methods that used the most CPU so far.

## Read a recording in a buffer

`jfr view` turns a recording into a text table. Text is what Neovim is good at, so read it into a scratch buffer. Run `:enew` for an empty buffer, then:

```vim
:read !jfr view gc /tmp/shop-dump.jfr
```

The buffer fills with a table of garbage collections. A few lines from our recording:

```text
Start    GC ID Type                     Heap Before GC Heap After GC Longest Pause
10:15:11     0 Young Garbage Collection        47.1 MB        9.8 MB       4.13 ms
10:15:11     2 Old Garbage Collection          14.0 MB       14.0 MB       1.89 ms
```

Now search it with `/`, yank lines, or save it next to a bug report. `hot-methods` lists the Java methods that ran most often in the samples; `jfr view` without a view name prints the list of available views, such as `allocation-by-class` and `jvm-information`. `jfr summary /tmp/shop-dump.jfr` shows how many events of each type were recorded.

## Save the commands as tasks

If you profile often, the same commands fit in `.vscode/tasks.json` as overseer tasks (Part 9), for example one that runs `jfr view hot-methods /tmp/shop-dump.jfr`. We ran the JFR commands from the terminal and `:read !`; overseer runs any shell command the same way it ran Maven.

## What needs an external viewer

Text tables answer many questions, but not all. Flame graphs, timelines of threads and the automated analysis pages need a graphical viewer. The standard one is JDK Mission Control, a separate download from the JDK, which opens `.jfr` files directly. We did not use it on the test machine, which had no desktop session for it.

This is the clearest gap compared with IntelliJ IDEA. Its built-in profiler starts JFR for a run configuration with one click and shows flame graphs and call trees inside the IDE, linked to the source. In Neovim the recording is the same JFR file, but reading it graphically happens outside the editor. Part 17 shows how to turn a recording into a flame graph page with a converter you run from Neovim.

## Recap

- JFR is the JDK's built-in profiler; `jcmd` controls recordings and `jfr` reads them.
- Start a recording with `-XX:StartFlightRecording=filename=...,dumponexit=true` in the `vmArgs` of a launch configuration.
- `jcmd <pid> JFR.check`, `JFR.dump` and `JFR.start` work on a running app; `JFR.view hot-methods` shows live data.
- `:read !jfr view gc file.jfr` puts a text view into a Neovim buffer; `jfr view` lists the views.
- Flame graphs need JDK Mission Control or another external viewer; Part 17 builds an HTML one.

**Series: Neovim as a Java IDE.** Previous: [Run configurations and Maven tasks in Neovim](/devtools/09-run-configurations-and-maven-tasks/) · Next: [A database tool in Neovim with vim-dadbod](/devtools/11-database-tool-dadbod/)

## Sources

Official documentation and well-known tutorials read while writing this article. The wording here is our own.

- [JDK 25: The jfr command](https://docs.oracle.com/en/java/javase/25/docs/specs/man/jfr.html)
- [JDK 25: The jcmd command](https://docs.oracle.com/en/java/javase/25/docs/specs/man/jcmd.html)
- [JDK 25: The java command (-XX:StartFlightRecording)](https://docs.oracle.com/en/java/javase/25/docs/specs/man/java.html)
- [JDK 21 release notes: new JFR view command (JDK-8306703)](https://www.oracle.com/java/technologies/javase/21-relnote-issues.html)
- [JDK Mission Control](https://www.oracle.com/java/technologies/jdk-mission-control.html)
- [IntelliJ IDEA: Profiler](https://www.jetbrains.com/help/idea/cpu-and-allocation-profiling-basic-concepts.html)
- [Baeldung: Monitoring Java Applications with Flight Recorder](https://www.baeldung.com/java-flight-recorder-monitoring)
- [Erik Gahlin: View Command](https://egahlin.github.io/2023/05/30/views.html)
- [Baeldung: JFR View Command in Java](https://www.baeldung.com/java-flight-recorder-view)
- [Inside.java: JFR View Command, Sip of Java](https://inside.java/2023/09/26/sip082/)
