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

JFR Event Streaming



    • Subcomponent:
    • Compatibility Risk:
    • Compatibility Risk Description:
      Changes are compatible with the current file format. The major file version will be kept, but the minor will be incremented to 2.1. This will not disrupt earlier releases of the JDK or JDK Mission Control to read recording files.
    • Interface Kind:
      Java API, System or security property, add/remove/modify command line option, File or wire format
    • Scope:



      Expose JDK Flight Recorder data for continuous monitoring.


      The HotSpot VM emits more than 500 data points using JFR, most of them not available through other means besides parsing log files.

      To consume the data today, a user must start a recording, stop it, dump the contents to disk and then parse the recording file. This works well for application profiling, where typically at least a minute of data is being recorded at a time, but not for monitoring purposes.


      Add an API to the jdk.jfr.consumer package that allow users to read recording data directly (stream) from the disk repository without dumping a recording file. There will be an interface, jdk.jfr.consumer.EventStream that will provide read capabilities for in process, out of process and ordinary recording files.

      public interface EventStream extends AutoCloseable {
        public static EventStream openRepository();
        public static EventStream openRepository(Path directory);
        public static EventStream openFile(Path file);
        void setStartTime(Instant startTime);
        void setEndTime(Instant endTime);
        void setOrdered(boolean ordered);
        void setReuse(boolean reuse);
        void onEvent(Consumer<RecordedEvent> action);
        void onEvent(String eventName, Consumer<RecordedEvent action);
        void onFlush(Runnable action);
        void onClose(Runnable action);
        void onError(Runnable action);
        void remove(Object action);
        void start();
        void startAsync();
        void awaitTermination();
        void awaitTermination(Duration duration);
        void close();

      There will be a class, jdk.jfr.consumer.RecordingStream, that implement the EventStream interface to provide control capabilties and retention policy.

      public final class RecordingStream implements EventStream (
        public RecordingStream();
        public RecordingStream(Configuration configuration);
        public EventSettings enable(String eventName);
        public EventSettings enable(Class<? extends Event> eventClass);
        public EventSettings disable(String eventname);
        public EventSettings disable(Class<? extends Event> eventClass);
        public void setSetting(Map<String, String> settings);
        public void setMaxAge(Duration maxAge);
        public void setMaxSize(long maxSize);
        public void setFlushInterval(Duration interval);
        // Implementation of EventStream interface

      Two methods will also be added to the jdk.jfr.Recording class that allow users to control how often data should be flushed.

      void setFlushInterval(Duration interval)
      Duration getFlushInterval();

      The -XX:StartFlightRecording will get a new option called flush-interval that specifies how often data should be flushed. The diagnostic command JFR.start will also get an option with the same name for setting the interval during runtime.

      To allow access to the disk repository from other processes, a system property ("jdk.jfr.repository"), will be added so a client can discover the file path using the attach API.


      Command line:


      Diagnostic command:

      JFR.start flush-interval=<NANOTIME>

      See attached diff for changes to EventStream, RecordingStream and Recording.


          Issue Links



              egahlin Erik Gahlin
              egahlin Erik Gahlin
              Reviewed By:
              Markus Grönlund
              0 Vote for this issue
              3 Start watching this issue