Summary
Add the option -XX:FlightRecorderOptions:preserve-repository to keep JDK Flight Recorder repository files after the Java Virtual Machine has exited.
Problem
JDK Flight Recorder writes recording data continuously to a directory called the repository. A new file is created in the repository after every 16 MB is written. If -XX:StartFlightRecording:dumponexit=true is specified at startup, the files belonging to the recording are concatenated and written to a dump file when the application ends. Before the JVM exits, all the files in the repository are deleted. This prevents the disk from filling up if the JVM is often restarted.
This works well in most cases, but sometimes there is a need to keep the repository files:
If all recording data is to be kept, not just the last X minutes, the resulting dump file can become very large, potentially tens of GBs. This makes the file hard to use. It cannot be opened in JMC. It may be too large to archive, for example, in cloud storage or provided as a download from a web server.
When OpenJDK JFR tests fail, it will simplify troubleshooting if repository files can be kept as they were written to disk.
Today a large recording file can be split using the 'jfr disassemble file' command. It solves the issue, but it is cumbersome to use a separate tool. Spending time concatenating files in the repository is also unnecessary if the resulting file is to be separated later.
Another way to avoid a large file is to write a script that periodically dumps recording data to a file using 'jcmd pid JFR.dump maxage=60s filename=path'. This creates smaller files but introduces unnecessary overhead and disruption to the application, for example, JVM safepoints. The dumped files must also have some overlap to guarantee that no data is lost.
Solution
Add the option -XX:FlightRecordingOption:preserve-repository=true/false to instruct the JVM to keep the files in the repository after it exits. When the option is specified, users are responsible to clean up the files themselves, similar to specifying the file option with -Xlog.
The location of the files can specified using the existing option -XX:FlightRecorderOption:repository=path.
The preserve-repository option can also be set when using jcmd, for example:
$ jcmd $pid JFR.configure preserve-repository=true
Specification
src/hotspot/share/jfr/dcmd/jfrDcmds.cpp
+ out->print_cr("");
+ out->print_cr(" preserve-repository (Optional) Preserve files stored in the disk repository after the");
+ out->print_cr(" Java Virtual Machine has exited. (BOOLEAN, false)");
- csr of
-
JDK-8303229 JFR: Preserve disk repository after exit
-
- Resolved
-