Summary
-------
Expose JDK Flight Recorder data for continuous monitoring.
Problem
-------
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.
Solution
--------
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.
Specification
-------------
Command line:
-XX:StartFlightRecording:flush-interval=<NANOTIME>
Diagnostic command:
JFR.start flush-interval=<NANOTIME>
See attached diff for changes to EventStream, RecordingStream and Recording.