# HG changeset patch # User egahlin # Date 1564670906 -7200 # Node ID b49f5c13baa713f5fa200a73b847c78b64da9701 # Parent 55cdeeb220e0d802d0c1a452087630d80db47baf Cleaning up diff -r 55cdeeb220e0 -r b49f5c13baa7 src/jdk.jfr/share/classes/jdk/jfr/consumer/AbstractEventStream.java --- a/src/jdk.jfr/share/classes/jdk/jfr/consumer/AbstractEventStream.java Thu Aug 01 16:47:17 2019 +0200 +++ b/src/jdk.jfr/share/classes/jdk/jfr/consumer/AbstractEventStream.java Thu Aug 01 16:48:26 2019 +0200 @@ -40,6 +40,7 @@ import java.util.function.Consumer; import jdk.jfr.EventType; +import jdk.jfr.internal.JVM; import jdk.jfr.internal.LogLevel; import jdk.jfr.internal.LogTag; import jdk.jfr.internal.Logger; @@ -311,7 +312,7 @@ public AbstractEventStream(AccessControlContext acc) throws IOException { this.accessControlContext = acc; - // Create thread object in constructor to ensure caller has permission + // Create thread object in constructor to ensure caller has // permission before constructing object thread = new Thread(this); thread.setDaemon(true); @@ -329,7 +330,7 @@ } private void execute() { - // JVM.getJVM().exclude(Thread.currentThread()); + JVM.getJVM().exclude(Thread.currentThread()); try { updateStartNanos(); process(); diff -r 55cdeeb220e0 -r b49f5c13baa7 src/jdk.jfr/share/classes/jdk/jfr/consumer/ObjectContext.java --- a/src/jdk.jfr/share/classes/jdk/jfr/consumer/ObjectContext.java Thu Aug 01 16:47:17 2019 +0200 +++ b/src/jdk.jfr/share/classes/jdk/jfr/consumer/ObjectContext.java Thu Aug 01 16:48:26 2019 +0200 @@ -1,3 +1,27 @@ +/* + * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ package jdk.jfr.consumer; import java.util.HashMap; @@ -21,10 +45,10 @@ this.timeConverter = timeConverter; } - private ObjectContext(ObjectContext root, ValueDescriptor desc) { - this.eventType = root.eventType; - this.contextLookup = root.contextLookup; - this.timeConverter = root.timeConverter; + private ObjectContext(ObjectContext parent, ValueDescriptor desc) { + this.eventType = parent.eventType; + this.contextLookup = parent.contextLookup; + this.timeConverter = parent.timeConverter; this.fields = desc.getFields(); } diff -r 55cdeeb220e0 -r b49f5c13baa7 src/jdk.jfr/share/classes/jdk/jfr/consumer/RecordingFile.java --- a/src/jdk.jfr/share/classes/jdk/jfr/consumer/RecordingFile.java Thu Aug 01 16:47:17 2019 +0200 +++ b/src/jdk.jfr/share/classes/jdk/jfr/consumer/RecordingFile.java Thu Aug 01 16:48:26 2019 +0200 @@ -253,6 +253,4 @@ throw new IOException("Stream Closed"); } } - - } diff -r 55cdeeb220e0 -r b49f5c13baa7 src/jdk.jfr/share/classes/jdk/jfr/consumer/RecordingStream.java --- a/src/jdk.jfr/share/classes/jdk/jfr/consumer/RecordingStream.java Thu Aug 01 16:47:17 2019 +0200 +++ b/src/jdk.jfr/share/classes/jdk/jfr/consumer/RecordingStream.java Thu Aug 01 16:48:26 2019 +0200 @@ -43,27 +43,44 @@ import jdk.jfr.internal.Utils; /** - * An recording stream produces events from a running JVM (Java Virtual + * A recording stream produces events from the current JVM (Java Virtual * Machine). + *

+ * The following example records events using the default configuration and + * prints the Garbage Collection, CPU Load and JVM Information event. + * + *

+ * 
+ * var c = Configuration.getConfiguration("default");
+ * try (var rs = new RecordingStream(c)) {
+ *     rs.onEvent("jdk.GarbageCollection", System.out::println);
+ *     rs.onEvent("jdk.CPULoad", System.out::println);
+ *     rs.onEvent("jdk.JVMInformation", System.out::println);
+ *     rs.start();
+ *   }
+ * }
+ * 
+ * 
+ * */ -public class RecordingStream implements AutoCloseable, EventStream { +public final class RecordingStream implements AutoCloseable, EventStream { private final Recording recording; private final EventDirectoryStream stream; /** - * Creates an event stream for this JVM (Java Virtual Machine). + * Creates an event stream for the current JVM (Java Virtual Machine). *

* The following example shows how to create a recording stream that prints * CPU usage and information about garbage collections. * *

      * 
-     * try (RecordingStream  r = new RecordingStream()) {
-     *   r.enable("jdk.GarbageCollection");
-     *   r.enable("jdk.CPULoad").withPeriod(Duration.ofSeconds(1));
-     *   r.onEvent(System.out::println);
-     *   r.start();
+     * try (var rs = new RecordingStream()) {
+     *   rs.enable("jdk.GarbageCollection");
+     *   rs.enable("jdk.CPULoad").withPeriod(Duration.ofSeconds(1));
+     *   rs.onEvent(System.out::println);
+     *   rs.start();
      * }
      * 
      * 
@@ -96,10 +113,10 @@ * *
      * 
-     * Configuration c = Configuration.getConfiguration("default");
-     * try (RecordingStream  r = new RecordingStream(c)) {
-     *   r.onEvent(System.out::println);
-     *   r.start();
+     * var c = Configuration.getConfiguration("default");
+     * try (RecordingStream rs = new RecordingStream(c)) {
+     *   rs.onEvent(System.out::println);
+     *   rs.start();
      * }
      * 
      * 
@@ -142,29 +159,22 @@ /** * Replaces all settings for this recording stream *

- * The following example shows how to set event settings for a recording. + * The following example records 20 second using the "default" configuration + * and then changes to settings for the "profile" configuration. * *

      * 
-     *     Map{@literal <}String, String{@literal >} settings = new HashMap{@literal <}{@literal >}();
-     *     settings.putAll(EventSettings.enabled("jdk.CPUSample").withPeriod(Duration.ofSeconds(2)).toMap());
-     *     settings.putAll(EventSettings.enabled(MyEvent.class).withThreshold(Duration.ofSeconds(2)).withoutStackTrace().toMap());
-     *     settings.put("jdk.ExecutionSample#period", "10 ms");
-     *     recordingStream.setSettings(settings);
+     *     var defaultConfiguration = Configuration.getConfiguration("default");
+     *     var profileConfiguration = Configuration.getConfiguration("profile");
+     *     try (var rs = new RecordingStream(defaultConfiguration) {
+     *        rs.startAsync();
+     *        Thread.sleep(20_000);
+     *        rs.setSettings(profileConfiguration.getSettings());
+     *        Thread.sleep(20_000);
+     *     }
      * 
      * 
* - * The following example shows how to merge settings. - * - *
-     * {
-     *     @code
-     *     Map settings = recording.getSettings();
-     *     settings.putAll(additionalSettings);
-     *     recordingStream.setSettings(settings);
-     * }
-     * 
- * * @param settings the settings to set, not {@code null} */ public void setSettings(Map settings) {