Search code examples
jfr

Explicitly setting the duration of a JFR event


I'm working on a Micrometer registry that sends metrics to JFR. I'm making good progress so far using EventFactory and Event#set(int, Object). However one thing I'm struggling with at the moment is that Micrometer explicitly wants to set the duration of events, for example using io.micrometer.core.instrument.Timer#record(long, TimeUnit). Is there a way to set the duration of a JFR event other than by using #start() and #end()? Or do I have to introduce a new custom attribute for the duration that I can set?


Solution

  • You need to create a custom attribute.

    You can use @jdk.jfr.Timespan(Timespan.NANOSECOONDS) to indicate that it should be displayed as a duration.