Skip to content

Instantly share code, notes, and snippets.

@parttimenerd
Created December 11, 2025 10:57
Show Gist options
  • Select an option

  • Save parttimenerd/c85ad3f964675586df40c042889de40f to your computer and use it in GitHub Desktop.

Select an option

Save parttimenerd/c85ad3f964675586df40c042889de40f to your computer and use it in GitHub Desktop.
Testing whether custom events in JFR can contain arrays
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