The following example shows how to configure, start, stop and dump recording data to disk.
Configuration c = Configuration.getConfiguration("default"); try (Recording r = new Recording(c)) { r.start(); System.gc(); Thread.sleep(5000); r.stop(); r.dump(Files.createTempFile("my-recording", ".jfr")); }
| Modifier and Type | Class and Description |
|---|---|
| private static class |
| Modifier and Type | Field and Description |
|---|---|
| private final PlatformRecording |
| Access | Constructor and Description |
|---|---|
| public | |
| pack-priv | |
| public | |
| public | Recording(Configuration
configuration that contains the settings to be used, not
configuration)nullCreates a recording with settings from a configuration. |
| Modifier and Type | Method and Description |
|---|---|
| public void | close()
Implements java. Releases all data that is associated with this recording. |
| public Recording | Returns: the recording copy, notnulltrue if the newly created copy should be stopped
immediately, false otherwiseReturns a clone of this recording, with a new recording ID and name. |
| public EventSettings | |
| public EventSettings | |
| public void | |
| public EventSettings | |
| public EventSettings | |
| public Path | Returns: the destination file, ornull if not set.Returns the destination file, where recording data is written when the
recording stops, or |
| public boolean | Returns: true if the recording is dumped on exit, false
otherwise.Returns whether this recording is dumped to disk when the JVM exits. |
| public Duration | Returns: the desired duration of the recording, ornull if no duration
has been set.Returns the specified duration for this recording, or |
| pack-priv Duration | Returns: the flush interval, ornull if no interval has been setReturns how often events are made available for streaming purposes. |
| public long | |
| pack-priv PlatformRecording | |
| public Duration | Returns: maximum length of time, ornull if no maximum length of time
has been setReturns the length of time that the data is kept in the disk repository before it is removed. |
| public long | Returns: maximum size in bytes, or0 if no maximum size is setReturns the maximum size, measured in bytes, at which data is no longer kept in the disk repository. |
| public String | |
| public Map | |
| public long | Returns: amount of recorded data, measured in bytes, or0 if the
recording is not written to the disk repositoryReturns the current size of this recording in the disk repository, measured in bytes. |
| public Instant | Returns: the time, ornull if this recording is not startedReturns the time when this recording was started. |
| public RecordingState | Returns: the recording state, notnullReturns the recording state that this recording is currently in. |
| public Instant | Returns: the time, ornull if this recording is not stoppedReturns the time when this recording was stopped. |
| public InputStream | Returns: an input stream, ornull if no data is available in the
interval, or the recording was not recorded to diskthe start time for the stream, or start, Instant null to get data from
start time of the recordingthe end time for the stream, or end)null to get data until the
present time.Creates a data stream for a specified interval. |
| public boolean | Returns: true if the recording uses the disk repository, false
otherwiseReturns |
| public void | scheduleStart(Duration
the time to wait before starting this recording, not
delay)nullStarts this recording after a delay. |
| public void | setDestination(Path
the destination path, or destination)null if recording should
not be dumped at stopSets a location where data is written on recording stop, or
|
| public void | setDumpOnExit(boolean
if this recording should be dumped when the JVM exits dumpOnExit)Sets whether this recording is dumped to disk when the JVM exits. |
| public void | setDuration(Duration
the duration, or duration)null if no duration is setSets a duration for how long a recording runs before it stops. |
| public void | |
| public void | setMaxSize(long
the amount of data to retain, maxSize)0 if infiniteDetermines how much data is kept in the disk repository. |
| public void | |
| private void | |
| public void | setSettings(Map<String, String>
the settings to set, not settings)nullReplaces all settings for this recording. |
| public void | setToDisk(boolean
true if this recording is written to disk,
false if in-memoryDetermines whether this recording is continuously flushed to the disk repository or data is constrained to what is available in memory buffers. |
| public void | |
| public boolean |
| internal | back to summary |
|---|---|
| private final PlatformRecording internal | |
| Recording | back to summary |
|---|---|
| public Recording(Map<String, String> settings) Creates a recording with settings from a map of name-value pairs.
A newly created recording is in the
| |
| Recording | back to summary |
|---|---|
| pack-priv Recording(Boolean register, Map<String, String> settings) | |
| Recording | back to summary |
|---|---|
| public Recording() Creates a recording without any settings.
A newly created recording is in the
| |
| Recording | back to summary |
|---|---|
| public Recording(Configuration configuration) Creates a recording with settings from a configuration. The following example shows how create a recording that uses a predefined configuration. Recording r = new Recording(Configuration.getConfiguration("default"));
RecordingState#NEW state. To
start the recording, invoke the Recording#start() method.
| |
| close | back to summary |
|---|---|
| public void close() Implements java. Releases all data that is associated with this recording.
After a successful invocation of this method, this recording is in the
| |
| copy | back to summary |
|---|---|
| public Recording copy(boolean stop) Returns a clone of this recording, with a new recording ID and name.
Clones are useful for dumping data without stopping the recording. After
a clone is created, the amount of data to copy is constrained
with the
| |
| disable | back to summary |
|---|---|
| public EventSettings disable(String name) Disables event with the specified name.
If multiple events with the same name (for example, the same class is loaded
in different class loaders), then all events that match the
name are disabled. To disable a specific class, use the
| |
| disable | back to summary |
|---|---|
| public EventSettings disable(Class<? extends Event> eventClass) Disables event.
| |
| dump | back to summary |
|---|---|
| public void dump(Path destination) throws IOException Writes recording data to a file.
For a dump to succeed, the recording must either be 1) running, or 2) stopped
and to disk. If the recording is in any other state, an
| |
| enable | back to summary |
|---|---|
| public EventSettings enable(String name) Enables the event with the specified name.
If multiple events have the same name (for example, the same class is loaded
in different class loaders), then all events that match the name are enabled. To
enable a specific class, use the
| |
| enable | back to summary |
|---|---|
| public EventSettings enable(Class<? extends Event> eventClass) Enables event.
| |
| getDestination | back to summary |
|---|---|
| public Path getDestination() Returns the destination file, where recording data is written when the
recording stops, or
| |
| getDumpOnExit | back to summary |
|---|---|
| public boolean getDumpOnExit() Returns whether this recording is dumped to disk when the JVM exits.
If dump on exit is not set,
| |
| getDuration | back to summary |
|---|---|
| public Duration getDuration() Returns the specified duration for this recording, or
The duration can be set only when the recording is in the
| |
| getFlushInterval | back to summary |
|---|---|
| pack-priv Duration getFlushInterval() Returns how often events are made available for streaming purposes.
| |
| getId | back to summary |
|---|---|
| public long getId() Returns a unique ID for this recording.
| |
| getInternal | back to summary |
|---|---|
| pack-priv PlatformRecording getInternal() | |
| getMaxAge | back to summary |
|---|---|
| public Duration getMaxAge() Returns the length of time that the data is kept in the disk repository before it is removed.
| |
| getMaxSize | back to summary |
|---|---|
| public long getMaxSize() Returns the maximum size, measured in bytes, at which data is no longer kept in the disk repository.
| |
| getName | back to summary |
|---|---|
| public String getName() Returns the name of this recording. By default, the name is the same as the recording ID.
| |
| getSettings | back to summary |
|---|---|
| public Map Returns settings used by this recording.
Modifying the returned
If no settings are set for this recording, an empty | |
| getSize | back to summary |
|---|---|
| public long getSize() Returns the current size of this recording in the disk repository, measured in bytes.
The size is updated when recording buffers are flushed. If the recording is
not written to the disk repository the returned size is always
| |
| getStartTime | back to summary |
|---|---|
| public Instant getStartTime() Returns the time when this recording was started.
| |
| getState | back to summary |
|---|---|
| public RecordingState getState() Returns the recording state that this recording is currently in.
| |
| getStopTime | back to summary |
|---|---|
| public Instant getStopTime() Returns the time when this recording was stopped.
| |
| getStream | back to summary |
|---|---|
| public InputStream getStream(Instant start, Instant end) throws IOException Creates a data stream for a specified interval. The stream may contain some data outside the specified range.
If the recording is not to disk, a stream can't be created
and
| |
| isToDisk | back to summary |
|---|---|
| public boolean isToDisk() Returns
If no value is set,
| |
| scheduleStart | back to summary |
|---|---|
| public void scheduleStart(Duration delay) Starts this recording after a delay.
After a successful invocation of this method, this recording is in the
| |
| setDestination | back to summary |
|---|---|
| public void setDestination(Path destination) throws IOException Sets a location where data is written on recording stop, or
If a destination is set, this recording is automatically closed after data is successfully copied to the destination path.
If a destination is not set, Flight Recorder retains the
recording data until this recording is closed. Use the
| |
| setDumpOnExit | back to summary |
|---|---|
| public void setDumpOnExit(boolean dumpOnExit) Sets whether this recording is dumped to disk when the JVM exits.
| |
| setDuration | back to summary |
|---|---|
| public void setDuration(Duration duration) Sets a duration for how long a recording runs before it stops.
By default, a recording has no duration (
| |
| setMaxAge | back to summary |
|---|---|
| public void setMaxAge(Duration maxAge) Determines how far back data is kept in the disk repository. To control the amount of recording data stored on disk, the maximum length of time to retain the data can be specified. Data stored on disk that is older than the specified length of time is removed by the Java Virtual Machine (JVM). If neither maximum limit or the maximum age is set, the size of the recording may grow indefinitely.
| |
| setMaxSize | back to summary |
|---|---|
| public void setMaxSize(long maxSize) Determines how much data is kept in the disk repository. To control the amount of recording data that is stored on disk, the maximum amount of data to retain can be specified. When the maximum limit is exceeded, the Java Virtual Machine (JVM) removes the oldest chunk to make room for a more recent chunk. If neither maximum limit or the maximum age is set, the size of the recording may grow indefinitely.
| |
| setName | back to summary |
|---|---|
| public void setName(String name) Sets a human-readable name (for example,
| |
| setSetting | back to summary |
|---|---|
| private void setSetting(String id, String value) | |
| setSettings | back to summary |
|---|---|
| public void setSettings(Map<String, String> settings) Replaces all settings for this recording. The following example shows how to set event settings for a recording. Map<String, String> settings = new HashMap<>();
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");
recording.setSettings(settings);
Map<String, String> settings = recording.getSettings();
settings.putAll(additionalSettings);
recording.setSettings(settings);
| |
| setToDisk | back to summary |
|---|---|
| public void setToDisk(boolean disk) Determines whether this recording is continuously flushed to the disk repository or data is constrained to what is available in memory buffers.
| |
| start | back to summary |
|---|---|
| public void start() Starts this recording. It's recommended that the recording options and event settings are configured before calling this method. The benefits of doing so are a more consistent state when analyzing the recorded data, and improved performance because the configuration can be applied atomically.
After a successful invocation of this method, this recording is in the
| |
| stop | back to summary |
|---|---|
| public boolean stop() Stops this recording. When a recording is stopped it can't be restarted. If this recording has a destination, data is written to that destination and the recording is closed. After a recording is closed, the data is no longer available.
After a successful invocation of this method, this recording will be
in the
| |
| Access | Constructor and Description |
|---|---|
| pack-priv | |
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public Map | toMap()
Implements abstract jdk. Creates a settings |
| public EventSettings | with(String name, String value)
Implements abstract jdk. Sets a setting value for the event that is associated with this event setting. |
| identifier | back to summary |
|---|---|
| private final String identifier | |
| recording | back to summary |
|---|---|
| private final Recording recording | |
| RecordingSettings | back to summary |
|---|---|
| pack-priv RecordingSettings(Recording r, String identifier) | |
| RecordingSettings | back to summary |
|---|---|
| pack-priv RecordingSettings(Recording r, Class<? extends Event> eventClass) | |
| toMap | back to summary |
|---|---|
| public Map Implements abstract jdk. Doc from jdk. Creates a settings
| |
| with | back to summary |
|---|---|
| public EventSettings with(String name, String value) Implements abstract jdk. Doc from jdk. Sets a setting value for the event that is associated with this event setting.
| |