How to delete Java flight records
I
have a Java flight record that I would like to share. Unfortunately, Java flight records contain user names and passwords in system properties and environment variables (JMC correctly warns of this). Is there a way to remove all system properties and environment variables from the Java flight record so I can share it?
Solution
Delete an existing recording
Recordings can be deleted using the jfr tool included with JDK 19 or later:
$ jfr scrub --exclude-events
jdk. InitialSystemProperty,jdk. InitialEnvironmentVariable
recording.jfr
The tool should also work for logging earlier JDK versions, perhaps back to JDK 11.
Verify
You can verify that it has been deleted using the print command:
Before:
$ jfr print --events
jdk. InitialSystemProperty,jdk. InitialEnvironmentVariable
recording.jfr
jdk. InitialSystemProperty {
startTime = 11:03:27.197 (2022-10-19)
key = "java.vm.compressedOopsMode"
value = "Zero based"
}
jdk. InitialEnvironmentVariable {
startTime = 11:03:27.197 (2022-10-19)
key = "TERM_PROGRAM"
value = "Apple_Terminal"
}
...
After :
$ jfr print --events
jdk. InitialSystemProperty,jdk. InitialEnvironmentVariable
scrubbed-recording.jfr
Disable events
In JDK 17, you can also close events from the command line:
$ java
-XX:StartFlightRecording:
jdk. InitialEnvironmentVariable#enabled=false,
jdk. InitialSystemProperty#enabled=false
...
For versions earlier than JDK 17, you can disable event jdk in JMC. InitialEnvironmentVariable and jdk. InitialSystemProperty。 Record in the GUI Wizard, or by creating a custom .jfc file. Go to Windows -> Template Manager and provide the custom .jfc on the command line as follows:
$ java -XX:StartFlightRecording=settings=/path/custom.jfc