Skip to content

Instantly share code, notes, and snippets.

@jbachorik
Created November 21, 2020 19:48
Show Gist options
  • Select an option

  • Save jbachorik/688c8872889da0d1d8a985535be54801 to your computer and use it in GitHub Desktop.

Select an option

Save jbachorik/688c8872889da0d1d8a985535be54801 to your computer and use it in GitHub Desktop.
import org.openjdk.btrace.core.BTraceUtils;
import org.openjdk.btrace.core.annotations.*;
import org.openjdk.btrace.core.jfr.JfrEvent;
import static org.openjdk.btrace.core.BTraceUtils.*;
import static org.openjdk.btrace.core.BTraceUtils.Jfr.*;
@BTrace public class JfrEventsProbe {
@Event(
name = "CustomEvent",
label = "Custom Event",
fields = {
@Event.Field(type = Event.FieldType.INT, name = "a"),
@Event.Field(type = Event.FieldType.STRING, name = "b")
}
)
private static JfrEvent.Factory customEventFactory;
@OnMethod(clazz = "/.*/", method = "/.*/")
public static void onMethod() {
JfrEvent event = prepareEvent(customEventFactory);
setEventField(event, "a", 10);
setEventField(event, "b", "hello");
commit(event);
}
@PeriodicEvent(name = "PeriodicEvent", fields = @Event.Field(type = Event.FieldType.INT, name = "ts", kind = @Event.Field.Kind(name = Event.FieldKind.TIMESTAMP)), period = "1 s")
public static void onPeriod(JfrEvent event) {
if (shouldCommit(event)) {
setEventField(event, "ts", 1);
commit(event);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment