JFR Scrub - Sip of Java

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.

Filtering Data

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:

  • --include-events [criteria]
  • --exclude-categories [criteria]
  • --exclude-threads [criteria]

Supplying Criteria

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:

--include-events jdk.FileRead,jdk.FileWrite

While this filter is removing all GC events:

--exclude-categories GC*

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

Additional Reading

JFR: Scrub recording data - https://bugs.openjdk.org/browse/JDK-8271585

Happy coding!