8195818: JFR.start should increase autogenerated name by one

Reviewed-by: mgronlun
This commit is contained in:
Erik Gahlin 2018-05-21 18:19:11 +02:00
parent 48fb34d596
commit 28b07240e6
2 changed files with 14 additions and 11 deletions

View File

@ -108,7 +108,11 @@ public final class PlatformRecorder {
} }
public synchronized PlatformRecording newRecording(Map<String, String> settings) { public synchronized PlatformRecording newRecording(Map<String, String> settings) {
PlatformRecording recording = new PlatformRecording(this, ++recordingCounter); return newRecording(settings, ++recordingCounter);
}
public synchronized PlatformRecording newRecording(Map<String, String> settings, long id) {
PlatformRecording recording = new PlatformRecording(this, id);
if (!settings.isEmpty()) { if (!settings.isEmpty()) {
recording.setSettings(settings); recording.setSettings(settings);
} }

View File

@ -101,7 +101,7 @@ public final class PlatformRecording implements AutoCloseable {
RecordingState oldState; RecordingState oldState;
RecordingState newState; RecordingState newState;
synchronized (recorder) { synchronized (recorder) {
oldState = recording.getState(); oldState = getState();
if (!Utils.isBefore(state, RecordingState.RUNNING)) { if (!Utils.isBefore(state, RecordingState.RUNNING)) {
throw new IllegalStateException("Recording can only be started once."); throw new IllegalStateException("Recording can only be started once.");
} }
@ -139,7 +139,7 @@ public final class PlatformRecording implements AutoCloseable {
} }
return "Started recording \"" + getName() + "\" (" + getId() + ") " + optionText; return "Started recording \"" + getName() + "\" (" + getId() + ") " + optionText;
}); });
newState = recording.getState(); newState = getState();
} }
notifyIfStateChanged(oldState, newState); notifyIfStateChanged(oldState, newState);
} }
@ -156,16 +156,16 @@ public final class PlatformRecording implements AutoCloseable {
RecordingState oldState; RecordingState oldState;
RecordingState newState; RecordingState newState;
synchronized (recorder) { synchronized (recorder) {
oldState = recording.getState(); oldState = getState();
if (stopTask != null) { if (stopTask != null) {
stopTask.cancel(); stopTask.cancel();
stopTask = null; stopTask = null;
} }
recorder.stop(this, alternativePath); recorder.stop(this, alternativePath);
String endTExt = reason == null ? "" : ". Reason \"" + reason + "\"."; String endText = reason == null ? "" : ". Reason \"" + reason + "\".";
Logger.log(LogTag.JFR, LogLevel.INFO, "Stopped recording \"" + recording.getName() + "\" (" + recording.getId()+ ")" + endTExt); Logger.log(LogTag.JFR, LogLevel.INFO, "Stopped recording \"" + getName() + "\" (" + getId()+ ")" + endText);
this.stopTime = Instant.now(); this.stopTime = Instant.now();
newState = recording.getState(); newState = getState();
} }
WriteableUserPath dest = getDestination(); WriteableUserPath dest = getDestination();
if (dest == null && alternativePath != null) { if (dest == null && alternativePath != null) {
@ -174,7 +174,7 @@ public final class PlatformRecording implements AutoCloseable {
if (dest != null) { if (dest != null) {
try { try {
copyTo(dest, reason, overlaySettings); copyTo(dest, reason, overlaySettings);
Logger.log(LogTag.JFR, LogLevel.INFO, "Wrote recording \"" + recording.getName() + "\" (" + recording.getId()+ ") to " + dest.getText()); Logger.log(LogTag.JFR, LogLevel.INFO, "Wrote recording \"" + getName() + "\" (" + getId()+ ") to " + dest.getText());
notifyIfStateChanged(newState, oldState); notifyIfStateChanged(newState, oldState);
close(); // remove if copied out close(); // remove if copied out
} catch (IOException e) { } catch (IOException e) {
@ -195,7 +195,7 @@ public final class PlatformRecording implements AutoCloseable {
setState(RecordingState.DELAYED); setState(RecordingState.DELAYED);
startTask = createStartTask(); startTask = createStartTask();
recorder.getTimer().schedule(startTask, delay.toMillis()); recorder.getTimer().schedule(startTask, delay.toMillis());
Logger.log(LogTag.JFR, LogLevel.INFO, "Scheduled recording \"" + recording.getName() + "\" (" + recording.getId()+ ") to start at " + now); Logger.log(LogTag.JFR, LogLevel.INFO, "Scheduled recording \"" + getName() + "\" (" + getId()+ ") to start at " + now);
} }
} }
@ -319,8 +319,7 @@ public final class PlatformRecording implements AutoCloseable {
} }
// Recording is RUNNING, create a clone // Recording is RUNNING, create a clone
try(Recording r = new Recording()) { try(PlatformRecording clone = recorder.newRecording(Collections.emptyMap(), 0)) {
PlatformRecording clone = PrivateAccess.getInstance().getPlatformRecording(r);
clone.setShouldWriteActiveRecordingEvent(false); clone.setShouldWriteActiveRecordingEvent(false);
clone.setName(getName()); clone.setName(getName());
clone.setDestination(path); clone.setDestination(path);