|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
|
|
package jdk.jfr.internal.management; |
|
|
|
import java.time.Duration; |
|
import java.util.ArrayList; |
|
import java.util.Collections; |
|
import java.util.List; |
|
|
|
import jdk.jfr.EventType; |
|
import jdk.jfr.Recording; |
|
import jdk.jfr.internal.JVMSupport; |
|
import jdk.jfr.internal.LogLevel; |
|
import jdk.jfr.internal.LogTag; |
|
import jdk.jfr.internal.Logger; |
|
import jdk.jfr.internal.MetadataRepository; |
|
import jdk.jfr.internal.PlatformRecording; |
|
import jdk.jfr.internal.PrivateAccess; |
|
import jdk.jfr.internal.Utils; |
|
import jdk.jfr.internal.WriteableUserPath; |
|
import jdk.jfr.internal.instrument.JDKEvents; |
|
|
|
|
|
|
|
|
|
|
|
|
|
*/ |
|
public final class ManagementSupport { |
|
|
|
// Purpose of this method is to expose the event types to the |
|
// FlightRecorderMXBean without instantiating Flight Recorder. |
|
// |
|
// This allows: |
|
// |
|
// 1) discoverability, so event settings can be exposed without the need to |
|
// create a new Recording in FlightrecorderMXBean. |
|
// |
|
// 2) a graphical JMX client to list all attributes to the user, without |
|
// loading JFR memory buffers. This is especially important when there is |
|
// no intent to use Flight Recorder. |
|
// |
|
// An alternative design would be to make FlightRecorder#getEventTypes |
|
// static, but it would the make the API look strange |
|
|
|
public static List<EventType> getEventTypes() { |
|
|
|
Utils.checkAccessFlightRecorder(); |
|
if (JVMSupport.isNotAvailable()) { |
|
return new ArrayList<>(); |
|
} |
|
JDKEvents.initialize(); |
|
return Collections.unmodifiableList(MetadataRepository.getInstance().getRegisteredEventTypes()); |
|
} |
|
|
|
|
|
public static long parseTimespan(String s) { |
|
return Utils.parseTimespan(s); |
|
} |
|
|
|
|
|
public static final String formatTimespan(Duration dValue, String separation) { |
|
return Utils.formatTimespan(dValue, separation); |
|
} |
|
|
|
|
|
public static void logError(String message) { |
|
Logger.log(LogTag.JFR, LogLevel.ERROR, message); |
|
} |
|
|
|
// Get the textual representation when the destination was set, which |
|
|
|
public static String getDestinationOriginalText(Recording recording) { |
|
PlatformRecording pr = PrivateAccess.getInstance().getPlatformRecording(recording); |
|
WriteableUserPath wup = pr.getDestination(); |
|
return wup == null ? null : wup.getOriginalText(); |
|
} |
|
} |