< prev index next >

src/jdk.jfr/share/classes/jdk/jfr/internal/PlatformRecording.java

Print this page




 115             Logger.log(LogTag.JFR, LogLevel.INFO, () -> {
 116                 // Only print non-default values so it easy to see
 117                 // which options were added
 118                 StringJoiner options = new StringJoiner(", ");
 119                 if (!toDisk) {
 120                     options.add("disk=false");
 121                 }
 122                 if (maxAge != null) {
 123                     options.add("maxage=" + Utils.formatTimespan(maxAge, ""));
 124                 }
 125                 if (maxSize != 0) {
 126                     options.add("maxsize=" + Utils.formatBytesCompact(maxSize));
 127                 }
 128                 if (dumpOnExit) {
 129                     options.add("dumponexit=true");
 130                 }
 131                 if (duration != null) {
 132                     options.add("duration=" + Utils.formatTimespan(duration, ""));
 133                 }
 134                 if (destination != null) {
 135                     options.add("filename=" + destination.getRealPathText());
 136                 }
 137                 String optionText = options.toString();
 138                 if (optionText.length() != 0) {
 139                     optionText = "{" + optionText + "}";
 140                 }
 141                 return "Started recording \"" + getName() + "\" (" + getId() + ") " + optionText;
 142             });
 143             newState = getState();
 144         }
 145         notifyIfStateChanged(oldState, newState);
 146     }
 147 
 148     public boolean stop(String reason) {
 149         RecordingState oldState;
 150         RecordingState newState;
 151         synchronized (recorder) {
 152             oldState = getState();
 153             if (stopTask != null) {
 154                 stopTask.cancel();
 155                 stopTask = null;
 156             }
 157             recorder.stop(this);
 158             String endText = reason == null ? "" : ". Reason \"" + reason + "\".";
 159             Logger.log(LogTag.JFR, LogLevel.INFO, "Stopped recording \"" + getName() + "\" (" + getId() + ")" + endText);
 160             this.stopTime = Instant.now();
 161             newState = getState();
 162         }
 163         WriteableUserPath dest = getDestination();
 164 
 165         if (dest != null) {
 166             try {
 167                 dumpStopped(dest);
 168                 Logger.log(LogTag.JFR, LogLevel.INFO, "Wrote recording \"" + getName() + "\" (" + getId() + ") to " + dest.getRealPathText());
 169                 notifyIfStateChanged(newState, oldState);
 170                 close(); // remove if copied out
 171             } catch(IOException e) {
 172                 // throw e; // BUG8925030
 173             }
 174         } else {
 175             notifyIfStateChanged(newState, oldState);
 176         }
 177         return true;
 178     }
 179 
 180     public void scheduleStart(Duration delay) {
 181         synchronized (recorder) {
 182             ensureOkForSchedule();
 183 
 184             startTime = Instant.now().plus(delay);
 185             LocalDateTime now = LocalDateTime.now().plus(delay);
 186             setState(RecordingState.DELAYED);
 187             startTask = createStartTask();
 188             recorder.getTimer().schedule(startTask, delay.toMillis());


 301         }
 302         RecordingState state = getState();
 303         if (state == RecordingState.CLOSED) {
 304             throw new IOException("Recording \"" + name + "\" (id=" + id + ") has been closed, no contents to write");
 305         }
 306         if (state == RecordingState.DELAYED || state == RecordingState.NEW) {
 307             throw new IOException("Recording \"" + name + "\" (id=" + id + ") has not started, no contents to write");
 308         }
 309         if (state == RecordingState.STOPPED) {
 310             PlatformRecording clone = recorder.newTemporaryRecording();
 311             for (RepositoryChunk r : chunks) {
 312                 clone.add(r);
 313             }
 314             return clone;
 315         }
 316 
 317         // Recording is RUNNING, create a clone
 318         PlatformRecording clone = recorder.newTemporaryRecording();
 319         clone.setShouldWriteActiveRecordingEvent(false);
 320         clone.setName(getName());

 321         clone.setToDisk(true);
 322         // We purposely don't clone settings here, since
 323         // a union a == a
 324         if (!isToDisk()) {
 325             // force memory contents to disk
 326             clone.start();
 327         } else {
 328             // using existing chunks on disk
 329             for (RepositoryChunk c : chunks) {
 330                 clone.add(c);
 331             }
 332             clone.setState(RecordingState.RUNNING);
 333             clone.setStartTime(getStartTime());
 334         }
 335         if (pathToGcRoots == null) {
 336             clone.setSettings(getSettings()); // needed for old object sample
 337             clone.stop(reason); // dumps to destination path here
 338         } else {
 339             // Risk of violating lock order here, since
 340             // clone.stop() will take recorder lock inside




 115             Logger.log(LogTag.JFR, LogLevel.INFO, () -> {
 116                 // Only print non-default values so it easy to see
 117                 // which options were added
 118                 StringJoiner options = new StringJoiner(", ");
 119                 if (!toDisk) {
 120                     options.add("disk=false");
 121                 }
 122                 if (maxAge != null) {
 123                     options.add("maxage=" + Utils.formatTimespan(maxAge, ""));
 124                 }
 125                 if (maxSize != 0) {
 126                     options.add("maxsize=" + Utils.formatBytesCompact(maxSize));
 127                 }
 128                 if (dumpOnExit) {
 129                     options.add("dumponexit=true");
 130                 }
 131                 if (duration != null) {
 132                     options.add("duration=" + Utils.formatTimespan(duration, ""));
 133                 }
 134                 if (destination != null) {
 135                     options.add("filename=" + destination.getText());
 136                 }
 137                 String optionText = options.toString();
 138                 if (optionText.length() != 0) {
 139                     optionText = "{" + optionText + "}";
 140                 }
 141                 return "Started recording \"" + getName() + "\" (" + getId() + ") " + optionText;
 142             });
 143             newState = getState();
 144         }
 145         notifyIfStateChanged(oldState, newState);
 146     }
 147 
 148     public boolean stop(String reason) {
 149         RecordingState oldState;
 150         RecordingState newState;
 151         synchronized (recorder) {
 152             oldState = getState();
 153             if (stopTask != null) {
 154                 stopTask.cancel();
 155                 stopTask = null;
 156             }
 157             recorder.stop(this);
 158             String endText = reason == null ? "" : ". Reason \"" + reason + "\".";
 159             Logger.log(LogTag.JFR, LogLevel.INFO, "Stopped recording \"" + getName() + "\" (" + getId() + ")" + endText);
 160             this.stopTime = Instant.now();
 161             newState = getState();
 162         }
 163         WriteableUserPath dest = getDestination();
 164 
 165         if (dest != null) {
 166             try {
 167                 dumpStopped(dest);
 168                 Logger.log(LogTag.JFR, LogLevel.INFO, "Wrote recording \"" + getName() + "\" (" + getId() + ") to " + dest.getText());
 169                 notifyIfStateChanged(newState, oldState);
 170                 close(); // remove if copied out
 171             } catch(IOException e) {
 172                 // throw e; // BUG8925030
 173             }
 174         } else {
 175             notifyIfStateChanged(newState, oldState);
 176         }
 177         return true;
 178     }
 179 
 180     public void scheduleStart(Duration delay) {
 181         synchronized (recorder) {
 182             ensureOkForSchedule();
 183 
 184             startTime = Instant.now().plus(delay);
 185             LocalDateTime now = LocalDateTime.now().plus(delay);
 186             setState(RecordingState.DELAYED);
 187             startTask = createStartTask();
 188             recorder.getTimer().schedule(startTask, delay.toMillis());


 301         }
 302         RecordingState state = getState();
 303         if (state == RecordingState.CLOSED) {
 304             throw new IOException("Recording \"" + name + "\" (id=" + id + ") has been closed, no contents to write");
 305         }
 306         if (state == RecordingState.DELAYED || state == RecordingState.NEW) {
 307             throw new IOException("Recording \"" + name + "\" (id=" + id + ") has not started, no contents to write");
 308         }
 309         if (state == RecordingState.STOPPED) {
 310             PlatformRecording clone = recorder.newTemporaryRecording();
 311             for (RepositoryChunk r : chunks) {
 312                 clone.add(r);
 313             }
 314             return clone;
 315         }
 316 
 317         // Recording is RUNNING, create a clone
 318         PlatformRecording clone = recorder.newTemporaryRecording();
 319         clone.setShouldWriteActiveRecordingEvent(false);
 320         clone.setName(getName());
 321         clone.setDestination(this.destination);
 322         clone.setToDisk(true);
 323         // We purposely don't clone settings here, since
 324         // a union a == a
 325         if (!isToDisk()) {
 326             // force memory contents to disk
 327             clone.start();
 328         } else {
 329             // using existing chunks on disk
 330             for (RepositoryChunk c : chunks) {
 331                 clone.add(c);
 332             }
 333             clone.setState(RecordingState.RUNNING);
 334             clone.setStartTime(getStartTime());
 335         }
 336         if (pathToGcRoots == null) {
 337             clone.setSettings(getSettings()); // needed for old object sample
 338             clone.stop(reason); // dumps to destination path here
 339         } else {
 340             // Risk of violating lock order here, since
 341             // clone.stop() will take recorder lock inside


< prev index next >