Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8362387

JFR: Simplify Recording to RecordedEvent

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • 26
    • hotspot
    • None
    • jfr

      It's not uncommon use case to get a RecordedEvent from a Recording. Before JEP 349: JFR Event Streaming, users had to do:

          try (Recording r = new Recording()) {
             r.start();
             Thread.sleep(10_000);
             Path p = Path.of("temp.jfr");
             r.dump(p);
             List<RecordedEvent> events = RecordingFile.readAllEvents(p);
             Files.delete(p);
          }

      With streaming, the temporary file can be avoided, but you need to use startAsync() and synchronization if you want it to terminate due to some external factor, like a clock, JVM shutdown, or a test that ends executing.

              var events = Collections.synchronizedList(new ArrayList<RecordedEvent>());
              try (RecordingStream r = new RecordingStream()) {
                r.onEvent(events::add);
                r.startAsync();
                Thread.sleep(10_000);
                r.stop();
              }

      Can we improve this situation, perhaps by adding a method to Recording or RecordingStream/RemoteRecordingStream?

      Should the new API method(s) only work on stopped recordings, or should it handle ongoing recordings as well? What about releasing the resources?

            egahlin Erik Gahlin
            egahlin Erik Gahlin
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: