--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/dcmd/DCmdStop.java Sun Jun 24 16:25:47 2018 +0100
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/dcmd/DCmdStop.java Mon Jun 25 02:07:42 2018 +0200
@@ -29,13 +29,16 @@
import java.nio.file.Paths;
import jdk.jfr.Recording;
+import jdk.jfr.internal.LogLevel;
+import jdk.jfr.internal.LogTag;
+import jdk.jfr.internal.Logger;
import jdk.jfr.internal.SecuritySupport.SafePath;
/**
* JFR.stop
*
*/
-//Instantiated by native
+// Instantiated by native
final class DCmdStop extends AbstractDCmd {
/**
@@ -43,35 +46,42 @@
*
* Requires that either <code>name or <code>id</code> is set.
*
- * @param recordingText name or id of the recording to stop.
+ * @param name name or id of the recording to stop.
*
- * @param textPath file path where data should be written after recording
- * has been stopped, or <code>null</code> if recording shouldn't be
- * written to disk.
+ * @param filename file path where data should be written after recording has
+ * been stopped, or <code>null</code> if recording shouldn't be written
+ * to disk.
* @return result text
*
* @throws DCmdException if recording could not be stopped
*/
- public String execute(String recordingText, String textPath) throws DCmdException {
+ public String execute(String name, String filename) throws DCmdException {
+ if (LogTag.JFR_DCMD.shouldLog(LogLevel.DEBUG)) {
+ Logger.log(LogTag.JFR_DCMD, LogLevel.DEBUG, "Executing DCmdStart: name=" + name + ", filename=" + filename);
+ }
+
try {
- SafePath path = resolvePath(textPath, "Failed to stop %s");
- Recording recording = findRecording(recordingText);
- if (textPath != null) {
+ SafePath safePath = null;
+ Recording recording = findRecording(name);
+ if (filename != null) {
try {
- recording.setDestination(Paths.get(textPath));
- } catch (IOException e) {
- throw new DCmdException("Failed to stop %s. Could not set destination for \"%s\" to file %s", recording.getName(), textPath, e.getMessage());
+ // Ensure path is valid. Don't generate safePath if filename == null, as a user may
+ // want to stop recording without a dump
+ safePath = resolvePath(null, filename);
+ recording.setDestination(Paths.get(filename));
+ } catch (IOException | InvalidPathException e) {
+ throw new DCmdException("Failed to stop %s. Could not set destination for \"%s\" to file %s", recording.getName(), filename, e.getMessage());
}
}
recording.stop();
- reportOperationComplete("Stopped", recording, path);
+ reportOperationComplete("Stopped", recording.getName(), safePath);
recording.close();
return getResult();
} catch (InvalidPathException | DCmdException e) {
- if (textPath != null) {
- throw new DCmdException("Could not write recording \"%s\" to file. %s", recordingText, e.getMessage());
+ if (filename != null) {
+ throw new DCmdException("Could not write recording \"%s\" to file. %s", name, e.getMessage());
}
- throw new DCmdException(e, "Could not stop recording \"%s\".", recordingText, e.getMessage());
+ throw new DCmdException(e, "Could not stop recording \"%s\".", name, e.getMessage());
}
}
}