Created
November 21, 2020 19:48
-
-
Save jbachorik/688c8872889da0d1d8a985535be54801 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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