8224217: RecordingInfo should use textual representation of path
Reviewed-by: mgronlun
This commit is contained in:
parent
f4dfa02438
commit
77b1472e9b
@ -315,7 +315,7 @@ public final class PlatformRecorder {
|
|||||||
private void dumpMemoryToDestination(PlatformRecording recording) {
|
private void dumpMemoryToDestination(PlatformRecording recording) {
|
||||||
WriteableUserPath dest = recording.getDestination();
|
WriteableUserPath dest = recording.getDestination();
|
||||||
if (dest != null) {
|
if (dest != null) {
|
||||||
MetadataRepository.getInstance().setOutput(dest.getText());
|
MetadataRepository.getInstance().setOutput(dest.getRealPathText());
|
||||||
recording.clearDestination();
|
recording.clearDestination();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -406,7 +406,7 @@ public final class PlatformRecorder {
|
|||||||
event.id = r.getId();
|
event.id = r.getId();
|
||||||
event.name = r.getName();
|
event.name = r.getName();
|
||||||
WriteableUserPath p = r.getDestination();
|
WriteableUserPath p = r.getDestination();
|
||||||
event.destination = p == null ? null : p.getText();
|
event.destination = p == null ? null : p.getRealPathText();
|
||||||
Duration d = r.getDuration();
|
Duration d = r.getDuration();
|
||||||
event.recordingDuration = d == null ? Long.MAX_VALUE : d.toMillis();
|
event.recordingDuration = d == null ? Long.MAX_VALUE : d.toMillis();
|
||||||
Duration age = r.getMaxAge();
|
Duration age = r.getMaxAge();
|
||||||
|
@ -132,7 +132,7 @@ public final class PlatformRecording implements AutoCloseable {
|
|||||||
options.add("duration=" + Utils.formatTimespan(duration, ""));
|
options.add("duration=" + Utils.formatTimespan(duration, ""));
|
||||||
}
|
}
|
||||||
if (destination != null) {
|
if (destination != null) {
|
||||||
options.add("filename=" + destination.getText());
|
options.add("filename=" + destination.getRealPathText());
|
||||||
}
|
}
|
||||||
String optionText = options.toString();
|
String optionText = options.toString();
|
||||||
if (optionText.length() != 0) {
|
if (optionText.length() != 0) {
|
||||||
@ -165,7 +165,7 @@ public final class PlatformRecording implements AutoCloseable {
|
|||||||
if (dest != null) {
|
if (dest != null) {
|
||||||
try {
|
try {
|
||||||
dumpStopped(dest);
|
dumpStopped(dest);
|
||||||
Logger.log(LogTag.JFR, LogLevel.INFO, "Wrote recording \"" + getName() + "\" (" + getId() + ") to " + dest.getText());
|
Logger.log(LogTag.JFR, LogLevel.INFO, "Wrote recording \"" + getName() + "\" (" + getId() + ") to " + dest.getRealPathText());
|
||||||
notifyIfStateChanged(newState, oldState);
|
notifyIfStateChanged(newState, oldState);
|
||||||
close(); // remove if copied out
|
close(); // remove if copied out
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
|
@ -50,7 +50,8 @@ public final class WriteableUserPath {
|
|||||||
private final AccessControlContext controlContext;
|
private final AccessControlContext controlContext;
|
||||||
private final Path original;
|
private final Path original;
|
||||||
private final Path real;
|
private final Path real;
|
||||||
private final String text;
|
private final String realPathText;
|
||||||
|
private final String originalText;
|
||||||
|
|
||||||
// Not to ensure security, but to help
|
// Not to ensure security, but to help
|
||||||
// against programming errors
|
// against programming errors
|
||||||
@ -68,8 +69,9 @@ public final class WriteableUserPath {
|
|||||||
BufferedWriter fw = Files.newBufferedWriter(path);
|
BufferedWriter fw = Files.newBufferedWriter(path);
|
||||||
fw.close();
|
fw.close();
|
||||||
this.original = path;
|
this.original = path;
|
||||||
|
this.originalText = path.toString();
|
||||||
this.real = path.toRealPath();
|
this.real = path.toRealPath();
|
||||||
this.text = real.toString();
|
this.realPathText = real.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -85,14 +87,24 @@ public final class WriteableUserPath {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a string representation of the path.
|
* Returns a string representation of the real path.
|
||||||
*
|
*
|
||||||
* @return path as text
|
* @return path as text
|
||||||
*/
|
*/
|
||||||
public String getText() {
|
public String getRealPathText() {
|
||||||
return text;
|
return realPathText;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a string representation of the original path.
|
||||||
|
*
|
||||||
|
* @return path as text
|
||||||
|
*/
|
||||||
|
public String getOriginalText() {
|
||||||
|
return originalText;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a potentially malicious path where the user may have implemented
|
* Returns a potentially malicious path where the user may have implemented
|
||||||
* their own version of Path. This method should never be called in an
|
* their own version of Path. This method should never be called in an
|
||||||
|
@ -31,12 +31,16 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import jdk.jfr.EventType;
|
import jdk.jfr.EventType;
|
||||||
|
import jdk.jfr.Recording;
|
||||||
import jdk.jfr.internal.JVMSupport;
|
import jdk.jfr.internal.JVMSupport;
|
||||||
import jdk.jfr.internal.LogLevel;
|
import jdk.jfr.internal.LogLevel;
|
||||||
import jdk.jfr.internal.LogTag;
|
import jdk.jfr.internal.LogTag;
|
||||||
import jdk.jfr.internal.Logger;
|
import jdk.jfr.internal.Logger;
|
||||||
import jdk.jfr.internal.MetadataRepository;
|
import jdk.jfr.internal.MetadataRepository;
|
||||||
|
import jdk.jfr.internal.PlatformRecording;
|
||||||
|
import jdk.jfr.internal.PrivateAccess;
|
||||||
import jdk.jfr.internal.Utils;
|
import jdk.jfr.internal.Utils;
|
||||||
|
import jdk.jfr.internal.WriteableUserPath;
|
||||||
import jdk.jfr.internal.instrument.JDKEvents;
|
import jdk.jfr.internal.instrument.JDKEvents;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -86,4 +90,12 @@ public final class ManagementSupport {
|
|||||||
public static void logError(String message) {
|
public static void logError(String message) {
|
||||||
Logger.log(LogTag.JFR, LogLevel.ERROR, message);
|
Logger.log(LogTag.JFR, LogLevel.ERROR, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the textual representation when the destination was set, which
|
||||||
|
// requires access to jdk.jfr.internal.PlatformRecording
|
||||||
|
public static String getDestinationOriginalText(Recording recording) {
|
||||||
|
PlatformRecording pr = PrivateAccess.getInstance().getPlatformRecording(recording);
|
||||||
|
WriteableUserPath wup = pr.getDestination();
|
||||||
|
return wup == null ? null : wup.getOriginalText();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,6 @@
|
|||||||
|
|
||||||
package jdk.management.jfr;
|
package jdk.management.jfr;
|
||||||
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
@ -37,6 +36,7 @@ import javax.management.openmbean.TabularData;
|
|||||||
|
|
||||||
import jdk.jfr.Recording;
|
import jdk.jfr.Recording;
|
||||||
import jdk.jfr.RecordingState;
|
import jdk.jfr.RecordingState;
|
||||||
|
import jdk.jfr.internal.management.ManagementSupport;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Management representation of a {@code Recording}.
|
* Management representation of a {@code Recording}.
|
||||||
@ -80,8 +80,7 @@ public final class RecordingInfo {
|
|||||||
startTime = s == null ? 0L : s.toEpochMilli();
|
startTime = s == null ? 0L : s.toEpochMilli();
|
||||||
Instant st = recording.getStopTime();
|
Instant st = recording.getStopTime();
|
||||||
stopTime = st == null ? 0L : st.toEpochMilli();
|
stopTime = st == null ? 0L : st.toEpochMilli();
|
||||||
Path p = recording.getDestination();
|
destination = ManagementSupport.getDestinationOriginalText(recording);
|
||||||
destination = p == null ? null : p.toString();
|
|
||||||
Duration duration = recording.getDuration();
|
Duration duration = recording.getDuration();
|
||||||
durationInSeconds = duration == null ? 0 : duration.getSeconds();
|
durationInSeconds = duration == null ? 0 : duration.getSeconds();
|
||||||
settings = recording.getSettings();
|
settings = recording.getSettings();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user