src/jdk.jfr/share/classes/jdk/jfr/consumer/RecordingStream.java
branchJEP-349-branch
changeset 58129 7b751fe181a5
parent 58020 f082177c5023
child 58145 bc54ed8d908a
equal deleted inserted replaced
58121:6f8f18ac1d54 58129:7b751fe181a5
    45 
    45 
    46 /**
    46 /**
    47  * A recording stream produces events from the current JVM (Java Virtual
    47  * A recording stream produces events from the current JVM (Java Virtual
    48  * Machine).
    48  * Machine).
    49  * <p>
    49  * <p>
    50  * The following example, shows how to record events using the default
    50  * The following example shows how to record events using the default
    51  * configuration and print the Garbage Collection, CPU Load and JVM Information
    51  * configuration and print the Garbage Collection, CPU Load and JVM Information
    52  * event to standard out.
    52  * event to standard out.
    53  *
    53  *
    54  * <pre>
    54  * <pre>
    55  * <code>
    55  * <code>
   108      *   rs.start();
   108      *   rs.start();
   109      * }
   109      * }
   110      * </code>
   110      * </code>
   111      * </pre>
   111      * </pre>
   112      *
   112      *
   113      * @param configuration configuration that contains the settings to be use,
   113      * @param configuration configuration that contains the settings to use,
   114      *        not {@code null}
   114      *        not {@code null}
   115      *
   115      *
   116      * @throws IllegalStateException if Flight Recorder can't be created (for
   116      * @throws IllegalStateException if Flight Recorder can't be created (for
   117      *         example, if the Java Virtual Machine (JVM) lacks Flight Recorder
   117      *         example, if the Java Virtual Machine (JVM) lacks Flight Recorder
   118      *         support, or if the file repository can't be created or accessed)
   118      *         support, or if the file repository can't be created or accessed)
   144     public EventSettings enable(String name) {
   144     public EventSettings enable(String name) {
   145         return recording.enable(name);
   145         return recording.enable(name);
   146     }
   146     }
   147 
   147 
   148     /**
   148     /**
   149      * Replaces all settings for this recording stream
   149      * Replaces all settings for this recording stream.
   150      * <p>
   150      * <p>
   151      * The following example records 20 second using the "default" configuration
   151      * The following example records 20 seconds using the "default" configuration
   152      * and then changes to settings for the "profile" configuration.
   152      * and then changes settings to the "profile" configuration.
   153      *
   153      *
   154      * <pre>
   154      * <pre>
   155      * <code>
   155      * <code>
   156      *     var defaultConfiguration = Configuration.getConfiguration("default");
   156      *     Configuration defaultConfiguration = Configuration.getConfiguration("default");
   157      *     var profileConfiguration = Configuration.getConfiguration("profile");
   157      *     Configuration profileConfiguration = Configuration.getConfiguration("profile");
   158      *     try (var rs = new RecordingStream(defaultConfiguration) {
   158      *     try (RecordingStream rs = new RecordingStream(defaultConfiguration) {
       
   159      *        rs.onEvent(System.out::println);
   159      *        rs.startAsync();
   160      *        rs.startAsync();
   160      *        Thread.sleep(20_000);
   161      *        Thread.sleep(20_000);
   161      *        rs.setSettings(profileConfiguration.getSettings());
   162      *        rs.setSettings(profileConfiguration.getSettings());
   162      *        Thread.sleep(20_000);
   163      *        Thread.sleep(20_000);
   163      *     }
   164      *     }
   164      * </code>
   165      * </code>
   165      * </pre>
   166      * </pre>
   166      *
   167      *
   167      * @param settings the settings to set, not {@code null}
   168      * @param settings the settings to set, not {@code null}
       
   169      *
       
   170      * @see Recording#setSettings(Map)
   168      */
   171      */
   169     public void setSettings(Map<String, String> settings) {
   172     public void setSettings(Map<String, String> settings) {
   170         recording.setSettings(settings);
   173         recording.setSettings(settings);
   171     };
   174     };
   172 
   175 
   215     public EventSettings disable(Class<? extends Event> eventClass) {
   218     public EventSettings disable(Class<? extends Event> eventClass) {
   216         return recording.disable(eventClass);
   219         return recording.disable(eventClass);
   217     }
   220     }
   218 
   221 
   219     /**
   222     /**
   220      * Determines how far back data is kept for the stream, if the stream can't
   223      * Determines how far back data is kept for the stream.
   221      * keep up.
       
   222      * <p>
   224      * <p>
   223      * To control the amount of recording data stored on disk, the maximum
   225      * To control the amount of recording data stored on disk, the maximum
   224      * length of time to retain the data can be specified. Data stored on disk
   226      * length of time to retain the data can be specified. Data stored on disk
   225      * that is older than the specified length of time is removed by the Java
   227      * that is older than the specified length of time is removed by the Java
   226      * Virtual Machine (JVM).
   228      * Virtual Machine (JVM).
   239     public void setMaxAge(Duration maxAge) {
   241     public void setMaxAge(Duration maxAge) {
   240         recording.setMaxAge(maxAge);
   242         recording.setMaxAge(maxAge);
   241     }
   243     }
   242 
   244 
   243     /**
   245     /**
   244      * Determines how much data is kept in the disk repository if the stream
   246      * Determines how much data is kept for the stream.
   245      * can't keep up.
       
   246      * <p>
   247      * <p>
   247      * To control the amount of recording data that is stored on disk, the
   248      * To control the amount of recording data that is stored on disk, the
   248      * maximum amount of data to retain can be specified. When the maximum limit
   249      * maximum amount of data to retain can be specified. When the maximum limit
   249      * is exceeded, the Java Virtual Machine (JVM) removes the oldest chunk to
   250      * is exceeded, the Java Virtual Machine (JVM) removes the oldest chunk to
   250      * make room for a more recent chunk.
   251      * make room for a more recent chunk.