# HG changeset patch # User egahlin # Date 1568639530 -7200 # Node ID ed7e71dd188b19abf89021ec70039a3e9738285a # Parent 7fd5766202ab6368e079c6bccc1269381e4baa18 Add example code for EventStream diff -r 7fd5766202ab -r ed7e71dd188b src/jdk.jfr/share/classes/jdk/jfr/consumer/EventStream.java --- a/src/jdk.jfr/share/classes/jdk/jfr/consumer/EventStream.java Mon Sep 16 15:10:34 2019 +0200 +++ b/src/jdk.jfr/share/classes/jdk/jfr/consumer/EventStream.java Mon Sep 16 15:12:10 2019 +0200 @@ -86,13 +86,35 @@ * default behavior is to print the exception and its backtrace to the standard * error stream. *

- * The following example demonstrates how an {@code EventStream} can be used to - * listen to garbage collection and CPU Load events + * The following example shows how an {@code EventStream} can be used to + * listen to events on a JVM running Flight Recorder + *

+ * 
+ * try (EventStream es = EventStream.openRepository()) {
+ *   es.onEvent("jdk.CPULoad", event -> {
+ *     System.out.println("CPU Load " + event.getEndTime());
+ *     System.out.println(" Machine total: " + 100 * event.getFloat("machineTotal") + "%");
+ *     System.out.println(" JVM User: " + 100 * event.getFloat("jvmUser") + "%");
+ *     System.out.println(" JVM System: " + 100 * event.getFloat("jvmSystem") + "%");
+ *     System.out.println();
+ *     System.gc();
+ *   });
+ *   es.onEvent("jdk.GarbageCollection", event -> {
+ *     System.out.println("Garbage collection: " + event.getLong("gcId"));
+ *     System.out.println(" Cause: " + event.getString("cause"));
+ *     System.out.println(" Total pause: " + event.getDuration("sumOfPauses"));
+ *     System.out.println(" Longest pause: " + event.getDuration("longestPause"));
+ *     System.out.println();
+ *   });
+ *   es.start();
+ * }
+ * 
+ * 
*

+ * To start recording together with the stream, see {@link RecordingStream}. * */ public interface EventStream extends AutoCloseable { - /** * Creates a stream from the repository of the current Java Virtual Machine * (JVM).