JFR Scrub - Sip of JavaBilly Korando on October 3, 2022
JDK Flight Recorder (JFR) is a powerful tool for performing diagnostic and profiling of a JVM and Java application. While recording, JFR might capture sensitive information or more information than is needed. When sharing a recording file, it would be good to be able to remove such sensitive or superfluous data. To address this need, the JFR team added the
jfr scrub utility allowing easy filtering out data from a recording file. Let’s take a look.
JFR Scrub Utility
The JFR scrub utility is a function of the
jfr command line tool packaged as a part of the JDK. From a terminal run:
jfr scrub [filters] [recording-file] [output-file]
To filter data from the specified recording file. Note that
output-file is an optional argument. If no
output-file is provided, then the output file will be the name of the
recording-file with “-scrubbed” appended to the end.
There are three ways to filter events in a recording file; event name, category, or thread name. Additionally, filters can be either inclusive or exclusive. Examples include the following:
Filters include or exclude events based on the criteria provided to them. Multiple criteria can be provided to the same filter, and wildcards can also be used on criteria. Note that criteria are applied as OR.
This filter is only including file read and write events:
While this filter is removing all GC events:
Multiple Filters can be applied to the same file as well; which work as AND; in the below example, first, only GC events are included, then all GC Pause events are removed:
--include-categories GC* --exclude-events jdk.GCPhasePause
JFR: Scrub recording data - https://bugs.openjdk.org/browse/JDK-8271585