I'm starting Java Flight Recorder with the following command.
jcmd $PID JFR.start duration=2h filename=my_record.jfr dumponexit=true settings=profile
It's recording the first 2 hours after started.
For example, if it started at 1:00, it records from 1:00 to 3:00, even if I dump at 9:00.
I need to get the recordings from the last 2 hours, not from the first ones.
For example, if it started at 1:00 and dumped at 9:00, I need to get the recordings from 7:00 to 9:00.
What should I do?
You can control how far back to keep data, in time or in bytes, with the parameters maxage and maxsize. For example,
jcmd <pid> JFR.start maxage=2h filename=my_recording.jfr dumponexit=true settings=profile
or from command line
java -XX:+UnlockCommercialFeatures
-XX:StartFlightRecording=maxage=2h,filename=my_recording.jfr,
dumponexit=true,settings=profile …
The dumponexit parameter, I think, only work with jcmd if you have JDK 8u40 or later