jshell flightrecorder Exception-Not a valid Flight Recorder file

Ashish Choudhary aashish.choudhary1 at gmail.com
Sat Feb 6 07:13:46 UTC 2021


Hi,

I am trying to run the JDK flight (OpenJDK 11) recorder with jshell by
passing the below arguments.

jshell -J-XX:StartFlightRecording:filename=myrecording.jfr,duration=240s


Everything seems to work apart from consuming the event.


Started recording 1. The result will be written to:


/Users/ashish/Downloads/jfr/myrecording.jfr

|  Welcome to JShell -- Version 11.0.10

|  For an introduction type: /help intro


jshell> import jdk.jfr.*;

   ...> import java.nio.file.*;

   ...> import jdk.jfr.consumer.*;

   ...> @Label("Hello Foojay")

   ...> @Description("Foojay is a place for friends of OpenJDK")

   ...> class SimpleEvent extends Event {

   ...>    @Label("Message")

   ...>    String message;

   ...> }

   ...> SimpleEvent event = new SimpleEvent();

   ...> event.begin();

   ...> Thread.sleep(60);

   ...> event.message = "hello, foojay!";

   ...> event.commit();

   ...> Path p = Paths.get("/Users/ashish/Downloads/jfr/myrecording.jfr");

   ...> for (RecordedEvent e : RecordingFile.readAllEvents(p)) {

   ...>    System.out.println(e.getStartTime() + " : " +
e.getValue("message"));

   ...> }

|  created class SimpleEvent

event ==> SimpleEvent at 37883b97

$8 ==> "hello, foojay!"

p ==> /Users/ashish/Downloads/jfr/myrecording.jfr

|  Exception java.io.IOException: Not a valid Flight Recorder file. File
length is only 0 bytes.

|        at RecordingInput.<init> (RecordingInput.java:82)

|        at RecordingInput.<init> (RecordingInput.java:87)

|        at RecordingFile.<init> (RecordingFile.java:107)

|        at RecordingFile.readAllEvents (RecordingFile.java:240)

|        at (#11:1)

I get above IOException and it's not able to read the .jfr file for some
reason. However jfr print works but not the API. Am I doing something silly
over here?

jfr print myrecording.jfr

jdk.ActiveSetting {

  startTime = 10:45:30.746

  id = 1598

  name = "threshold"

  value = "0 ns"

  eventThread = "main" (javaThreadId = 1)

}


jdk.ActiveSetting {

  startTime = 10:45:30.746

  id = 1598

  name = "stackTrace"

  value = "false"

  eventThread = "main" (javaThreadId = 1)

}


With Best Regards,
Ashish


More information about the adoption-discuss mailing list