Created
December 11, 2025 10:57
-
-
Save parttimenerd/c85ad3f964675586df40c042889de40f to your computer and use it in GitHub Desktop.
Testing whether custom events in JFR can contain arrays
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 jdk.jfr.*; | |
| import jdk.jfr.consumer.*; | |
| import java.nio.file.*; | |
| class ArrayEvent extends Event { | |
| @Label("String Array") | |
| String[] stringArray; | |
| @Label("Int Array") | |
| int[] intArray; | |
| @Label("Long Array") | |
| long[] longArray; | |
| @Label("Non array field") | |
| String nonArrayField = "default"; | |
| } | |
| public class JFRArrayTest { | |
| public static void main(String[] args) throws Exception { | |
| Path recording = Path.of("test_array.jfr"); | |
| try (Recording r = new Recording()) { | |
| r.enable("test.ArrayEvent"); | |
| r.start(); | |
| ArrayEvent event = new ArrayEvent(); | |
| event.stringArray = new String[]{"one", "two", "three"}; | |
| event.intArray = new int[]{1, 2, 3, 4, 5}; | |
| event.longArray = new long[]{100L, 200L, 300L}; | |
| event.commit(); | |
| r.stop(); | |
| r.dump(recording); | |
| } | |
| // Now read it back | |
| try (RecordingFile rf = new RecordingFile(recording)) { | |
| while (rf.hasMoreEvents()) { | |
| RecordedEvent e = rf.readEvent(); | |
| System.out.println("Event type: " + e.getEventType().getName()); | |
| for (var field : e.getEventType().getFields()) { | |
| System.out.println(" Field: " + field.getName() + " type=" + field.getTypeName()); | |
| } | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment