Record only a single thread in JDK Flight Recorder

67 views Asked by At

I'm looking for a way to record only a single thread in a JDK Flight Recording. I'm using the jdk.jfr.Recording API to create a flight recording but do not find a way to limit the events only to a single thread.

I know I can restrict to a single thread afterwards in JMC but I would like to configure this before hand to keep the file size to a minimum and make analysis easier.

The use case I have for this is:

I'm dealing with a multi threaded system where multiple jobs run in parallel. For certain long running jobs I would like to create a flight recording on demand. To make analysis easier and keep the file size to a minimum I would like only one single thread to be recorded.

1

There are 1 answers

0
Kire Haglin On BEST ANSWER

It's not possible to prefilter JDK/JVM events per thread. The best you can do is filter it afterwards, for example:

$ jfr scrub --include-threads main recording.jfr

That way you can keep down the file size, but it won't reduce the overhead. You can also do it programmatically using the RecordingFile.write method.

Filtering can be done on recordings from JDK 11, or later, even though the API and scrub command only exist in JDK 19+.