how to make java JFR to include the timestamp in the file on dump StartFlightRecording filename with timestamp

Viewed 157

I am starting the flight recording in this way :

java -XX:StartFlightRecording=dumponexit=true,filename=/path/to/recorders/myrecording.jfr

I would like to have the file named with the timestamp of the moment of the dump, lets say I dump next day using jcmd, I would like the name something like /path/to/recorders/2021_09_14_myrecording.jfr

I have tried reading documentation I have not found anything useful. I might create a separate script that renames the file appending the timestamp using bash, but before wanted to ask here if there is any built-in feature in java to achieve this.

1 Answers

If you are running JDK 11-17, you can specify only the directory, and a filename with timestamp and pid will be generated, for example "hotspot-pid-7066-id-1-2021_09_15_15_56_03.jfr"

java -XX:StartFlightRecording:filename=/path/to/recorders/ ...

There is no need to specify dumponexit=true if you set a filename.

The timestamp will be generated when the dump happens.

Related