jdk.jfr.internal.PlatformRecorder Java Examples

The following examples show how to use jdk.jfr.internal.PlatformRecorder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DCmdDump.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public void dump(PlatformRecorder recorder, Recording recording, String name, String filename, Long maxSize, Boolean pathToGcRoots, Instant beginTime, Instant endTime) throws DCmdException {
    try (PlatformRecording r = newSnapShot(recorder, recording, pathToGcRoots)) {
        r.filter(beginTime, endTime, maxSize);
        if (r.getChunks().isEmpty()) {
            throw new DCmdException("Dump failed. No data found in the specified interval.");
        }
        SafePath dumpFile = resolvePath(recording, filename);

        // Needed for JVM
        Utils.touch(dumpFile.toPath());
        r.dumpStopped(new WriteableUserPath(dumpFile.toPath()));
        reportOperationComplete("Dumped", name, dumpFile);
    } catch (IOException | InvalidPathException e) {
        throw new DCmdException("Dump failed. Could not copy recording data. %s", e.getMessage());
    }
}
 
Example #2
Source File: DCmdDump.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public void dump(PlatformRecorder recorder, Recording recording, String name, String filename, Long maxSize, Boolean pathToGcRoots, Instant beginTime, Instant endTime) throws DCmdException {
    try (PlatformRecording r = newSnapShot(recorder, recording, pathToGcRoots)) {
        r.filter(beginTime, endTime, maxSize);
        if (r.getChunks().isEmpty()) {
            throw new DCmdException("Dump failed. No data found in the specified interval.");
        }
        SafePath dumpFile = resolvePath(recording, filename);

        // Needed for JVM
        Utils.touch(dumpFile.toPath());
        r.dumpStopped(new WriteableUserPath(dumpFile.toPath()));
        reportOperationComplete("Dumped", name, dumpFile);
    } catch (IOException | InvalidPathException e) {
        throw new DCmdException("Dump failed. Could not copy recording data. %s", e.getMessage());
    }
}
 
Example #3
Source File: DCmdDump.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private PlatformRecording newSnapShot(PlatformRecorder recorder, Recording recording, Boolean pathToGcRoots) throws DCmdException, IOException {
    if (recording == null) {
        // Operate on all recordings
        PlatformRecording snapshot = recorder.newTemporaryRecording();
        recorder.fillWithRecordedData(snapshot, pathToGcRoots);
        return snapshot;
    }

    PlatformRecording pr = PrivateAccess.getInstance().getPlatformRecording(recording);
    return pr.newSnapshotClone("Dumped by user", pathToGcRoots);
}
 
Example #4
Source File: FlightRecorder.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the Flight Recorder for the platform.
 *
 * @return a Flight Recorder instance, not {@code null}
 *
 * @throws IllegalStateException if Flight Recorder can't be created (for
 *         example, if the Java Virtual Machine (JVM) lacks Flight Recorder
 *         support, or if the file repository can't be created or accessed)
 *
 * @throws SecurityException if a security manager exists and the caller does
 *         not have {@code FlightRecorderPermission("accessFlightRecorder")}
 */
public static FlightRecorder getFlightRecorder() throws IllegalStateException, SecurityException {
    synchronized (PlatformRecorder.class) {
        Utils.checkAccessFlightRecorder();
        JVMSupport.ensureWithIllegalStateException();
        if (platformRecorder == null) {
            try {
                platformRecorder = new FlightRecorder(new PlatformRecorder());
            } catch (IllegalStateException ise) {
                throw ise;
            } catch (Exception e) {
                throw new IllegalStateException("Can't create Flight Recorder. " + e.getMessage(), e);
            }
            // Must be in synchronized block to prevent instance leaking out
            // before initialization is done
            initialized = true;
            Logger.log(JFR, INFO, "Flight Recorder initialized");
            Logger.log(JFR, DEBUG, "maxchunksize: " + Options.getMaxChunkSize()+ " bytes");
            Logger.log(JFR, DEBUG, "memorysize: " + Options.getMemorySize()+ " bytes");
            Logger.log(JFR, DEBUG, "globalbuffersize: " + Options.getGlobalBufferSize()+ " bytes");
            Logger.log(JFR, DEBUG, "globalbuffercount: " + Options.getGlobalBufferCount());
            Logger.log(JFR, DEBUG, "dumppath: " + Options.getDumpPath());
            Logger.log(JFR, DEBUG, "samplethreads: " + Options.getSampleThreads());
            Logger.log(JFR, DEBUG, "stackdepth: " + Options.getStackDepth());
            Logger.log(JFR, DEBUG, "threadbuffersize: " + Options.getThreadBufferSize());
            Logger.log(JFR, LogLevel.INFO, "Created repository " + Repository.getRepository().getRepositoryPath().toString());
            PlatformRecorder.notifyRecorderInitialized(platformRecorder);
        }
    }
    return platformRecorder;
}
 
Example #5
Source File: Recording.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public Recording(Map<String, String> settings) {
    PlatformRecorder r = FlightRecorder.getFlightRecorder().getInternal();
    synchronized (r) {
        this.internal = r.newRecording(settings);
        this.internal.setRecording(this);
        if (internal.getRecording() != this) {
            throw new InternalError("Internal recording not properly setup");
        }
    }
}
 
Example #6
Source File: DCmdDump.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private PlatformRecording newSnapShot(PlatformRecorder recorder, Recording recording, Boolean pathToGcRoots) throws DCmdException, IOException {
    if (recording == null) {
        // Operate on all recordings
        PlatformRecording snapshot = recorder.newTemporaryRecording();
        recorder.fillWithRecordedData(snapshot, pathToGcRoots);
        return snapshot;
    }

    PlatformRecording pr = PrivateAccess.getInstance().getPlatformRecording(recording);
    return pr.newSnapshotClone("Dumped by user", pathToGcRoots);
}
 
Example #7
Source File: FlightRecorder.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the Flight Recorder for the platform.
 *
 * @return a Flight Recorder instance, not {@code null}
 *
 * @throws IllegalStateException if the platform Flight Recorder couldn't be
 *         created (for example, if the file repository can't be created or
 *         accessed)
 *
 * @throws SecurityException if a security manager exists and the caller does
 *         not have {@code FlightRecorderPermission("accessFlightRecorder")}
 */
public static FlightRecorder getFlightRecorder() throws IllegalStateException, SecurityException {
    synchronized (PlatformRecorder.class) {
        Utils.checkAccessFlightRecorder();
        JVMSupport.ensureWithIllegalStateException();
        if (platformRecorder == null) {
            try {
                platformRecorder = new FlightRecorder(new PlatformRecorder());
            } catch (IllegalStateException ise) {
                throw ise;
            } catch (Exception e) {
                throw new IllegalStateException("Can't create Flight Recorder. " + e.getMessage(), e);
            }
            // Must be in synchronized block to prevent instance leaking out
            // before initialization is done
            initialized = true;
            Logger.log(JFR, INFO, "Flight Recorder initialized");
            Logger.log(JFR, DEBUG, "maxchunksize: " + Options.getMaxChunkSize()+ " bytes");
            Logger.log(JFR, DEBUG, "memorysize: " + Options.getMemorySize()+ " bytes");
            Logger.log(JFR, DEBUG, "globalbuffersize: " + Options.getGlobalBufferSize()+ " bytes");
            Logger.log(JFR, DEBUG, "globalbuffercount: " + Options.getGlobalBufferCount());
            Logger.log(JFR, DEBUG, "dumppath: " + Options.getDumpPath());
            Logger.log(JFR, DEBUG, "samplethreads: " + Options.getSampleThreads());
            Logger.log(JFR, DEBUG, "stackdepth: " + Options.getStackDepth());
            Logger.log(JFR, DEBUG, "threadbuffersize: " + Options.getThreadBufferSize());
            Logger.log(JFR, LogLevel.INFO, "Created repository " + Repository.getRepository().getRepositoryPath().toString());
            PlatformRecorder.notifyRecorderInitialized(platformRecorder);
        }
    }
    return platformRecorder;
}
 
Example #8
Source File: FlightRecorder.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the Flight Recorder for the platform.
 *
 * @return a Flight Recorder instance, not {@code null}
 *
 * @throws IllegalStateException if Flight Recorder can't be created (for
 *         example, if the Java Virtual Machine (JVM) lacks Flight Recorder
 *         support, or if the file repository can't be created or accessed)
 *
 * @throws SecurityException if a security manager exists and the caller does
 *         not have {@code FlightRecorderPermission("accessFlightRecorder")}
 */
public static FlightRecorder getFlightRecorder() throws IllegalStateException, SecurityException {
    synchronized (PlatformRecorder.class) {
        Utils.checkAccessFlightRecorder();
        JVMSupport.ensureWithIllegalStateException();
        if (platformRecorder == null) {
            try {
                platformRecorder = new FlightRecorder(new PlatformRecorder());
            } catch (IllegalStateException ise) {
                throw ise;
            } catch (Exception e) {
                throw new IllegalStateException("Can't create Flight Recorder. " + e.getMessage(), e);
            }
            // Must be in synchronized block to prevent instance leaking out
            // before initialization is done
            initialized = true;
            Logger.log(JFR, INFO, "Flight Recorder initialized");
            Logger.log(JFR, DEBUG, "maxchunksize: " + Options.getMaxChunkSize()+ " bytes");
            Logger.log(JFR, DEBUG, "memorysize: " + Options.getMemorySize()+ " bytes");
            Logger.log(JFR, DEBUG, "globalbuffersize: " + Options.getGlobalBufferSize()+ " bytes");
            Logger.log(JFR, DEBUG, "globalbuffercount: " + Options.getGlobalBufferCount());
            Logger.log(JFR, DEBUG, "dumppath: " + Options.getDumpPath());
            Logger.log(JFR, DEBUG, "samplethreads: " + Options.getSampleThreads());
            Logger.log(JFR, DEBUG, "stackdepth: " + Options.getStackDepth());
            Logger.log(JFR, DEBUG, "threadbuffersize: " + Options.getThreadBufferSize());
            Logger.log(JFR, LogLevel.INFO, "Created repository " + Repository.getRepository().getRepositoryPath().toString());
            PlatformRecorder.notifyRecorderInitialized(platformRecorder);
        }
    }
    return platformRecorder;
}
 
Example #9
Source File: Recording.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public Recording(Map<String, String> settings) {
    PlatformRecorder r = FlightRecorder.getFlightRecorder().getInternal();
    synchronized (r) {
        this.internal = r.newRecording(settings);
        this.internal.setRecording(this);
        if (internal.getRecording() != this) {
            throw new InternalError("Internal recording not properly setup");
        }
    }
}
 
Example #10
Source File: FlightRecorder.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private FlightRecorder(PlatformRecorder internal) {
    this.internal = internal;
}
 
Example #11
Source File: FlightRecorder.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
private FlightRecorder(PlatformRecorder internal) {
    this.internal = internal;
}
 
Example #12
Source File: DCmdDump.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Execute JFR.dump.
 *
 * @param name name or id of the recording to dump, or <code>null</code> to dump everything
 *
 * @param filename file path where recording should be written, not null
 * @param maxAge how far back in time to dump, may be null
 * @param maxSize how far back in size to dump data from, may be null
 * @param begin point in time to dump data from, may be null
 * @param end point in time to dump data to, may be null
 * @param pathToGcRoots if Java heap should be swept for reference chains
 *
 * @return result output
 *
 * @throws DCmdException if the dump could not be completed
 */
public String execute(String name, String filename, Long maxAge, Long maxSize, String begin, String end, Boolean pathToGcRoots) throws DCmdException {
    if (Logger.shouldLog(LogTag.JFR_DCMD, LogLevel.DEBUG)) {
        Logger.log(LogTag.JFR_DCMD, LogLevel.DEBUG,
                "Executing DCmdDump: name=" + name +
                ", filename=" + filename +
                ", maxage=" + maxAge +
                ", maxsize=" + maxSize +
                ", begin=" + begin +
                ", end" + end +
                ", path-to-gc-roots=" + pathToGcRoots);
    }

    if (FlightRecorder.getFlightRecorder().getRecordings().isEmpty()) {
        throw new DCmdException("No recordings to dump from. Use JFR.start to start a recording.");
    }

    if (maxAge != null) {
        if (end != null || begin != null) {
            throw new DCmdException("Dump failed, maxage can't be combined with begin or end.");
        }

        if (maxAge < 0) {
            throw new DCmdException("Dump failed, maxage can't be negative.");
        }
        if (maxAge == 0) {
            maxAge = Long.MAX_VALUE / 2; // a high value that won't overflow
        }
    }

    if (maxSize!= null) {
        if (maxSize < 0) {
            throw new DCmdException("Dump failed, maxsize can't be negative.");
        }
        if (maxSize == 0) {
            maxSize = Long.MAX_VALUE / 2; // a high value that won't overflow
        }
    }

    Instant beginTime = parseTime(begin, "begin");
    Instant endTime = parseTime(end, "end");

    if (beginTime != null && endTime != null) {
        if (endTime.isBefore(beginTime)) {
            throw new DCmdException("Dump failed, begin must preceed end.");
        }
    }

    Duration duration = null;
    if (maxAge != null) {
        duration = Duration.ofNanos(maxAge);
        beginTime = Instant.now().minus(duration);
    }
    Recording recording = null;
    if (name != null) {
        recording = findRecording(name);
    }
    PlatformRecorder recorder = PrivateAccess.getInstance().getPlatformRecorder();
    synchronized (recorder) {
        dump(recorder, recording, name, filename, maxSize, pathToGcRoots, beginTime, endTime);
    }
    return getResult();
}
 
Example #13
Source File: FlightRecorderPermission.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Override
public PlatformRecorder getPlatformRecorder() {
    return FlightRecorder.getFlightRecorder().getInternal();
}
 
Example #14
Source File: FlightRecorder.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
PlatformRecorder getInternal() {
    return internal;
}
 
Example #15
Source File: FlightRecorder.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private FlightRecorder(PlatformRecorder internal) {
    this.internal = internal;
}
 
Example #16
Source File: DCmdDump.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Execute JFR.dump.
 *
 * @param name name or id of the recording to dump, or <code>null</code> to dump everything
 *
 * @param filename file path where recording should be written, not null
 * @param maxAge how far back in time to dump, may be null
 * @param maxSize how far back in size to dump data from, may be null
 * @param begin point in time to dump data from, may be null
 * @param end point in time to dump data to, may be null
 * @param pathToGcRoots if Java heap should be swept for reference chains
 *
 * @return result output
 *
 * @throws DCmdException if the dump could not be completed
 */
public String execute(String name, String filename, Long maxAge, Long maxSize, String begin, String end, Boolean pathToGcRoots) throws DCmdException {
    if (LogTag.JFR_DCMD.shouldLog(LogLevel.DEBUG)) {
        Logger.log(LogTag.JFR_DCMD, LogLevel.DEBUG,
                "Executing DCmdDump: name=" + name +
                ", filename=" + filename +
                ", maxage=" + maxAge +
                ", maxsize=" + maxSize +
                ", begin=" + begin +
                ", end" + end +
                ", path-to-gc-roots=" + pathToGcRoots);
    }

    if (FlightRecorder.getFlightRecorder().getRecordings().isEmpty()) {
        throw new DCmdException("No recordings to dump from. Use JFR.start to start a recording.");
    }

    if (maxAge != null) {
        if (end != null || begin != null) {
            throw new DCmdException("Dump failed, maxage can't be combined with begin or end.");
        }

        if (maxAge < 0) {
            throw new DCmdException("Dump failed, maxage can't be negative.");
        }
        if (maxAge == 0) {
            maxAge = Long.MAX_VALUE / 2; // a high value that won't overflow
        }
    }

    if (maxSize!= null) {
        if (maxSize < 0) {
            throw new DCmdException("Dump failed, maxsize can't be negative.");
        }
        if (maxSize == 0) {
            maxSize = Long.MAX_VALUE / 2; // a high value that won't overflow
        }
    }

    Instant beginTime = parseTime(begin, "begin");
    Instant endTime = parseTime(end, "end");

    if (beginTime != null && endTime != null) {
        if (endTime.isBefore(beginTime)) {
            throw new DCmdException("Dump failed, begin must preceed end.");
        }
    }

    Duration duration = null;
    if (maxAge != null) {
        duration = Duration.ofNanos(maxAge);
        beginTime = Instant.now().minus(duration);
    }
    Recording recording = null;
    if (name != null) {
        recording = findRecording(name);
    }
    PlatformRecorder recorder = PrivateAccess.getInstance().getPlatformRecorder();
    synchronized (recorder) {
        dump(recorder, recording, name, filename, maxSize, pathToGcRoots, beginTime, endTime);
    }
    return getResult();
}
 
Example #17
Source File: FlightRecorderPermission.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public PlatformRecorder getPlatformRecorder() {
    return FlightRecorder.getFlightRecorder().getInternal();
}
 
Example #18
Source File: FlightRecorder.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
PlatformRecorder getInternal() {
    return internal;
}
 
Example #19
Source File: FlightRecorder.java    From dragonwell8_jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Removes a recorder listener.
 * <p>
 * If the same listener is added multiple times, only one instance is
 * removed.
 *
 * @param changeListener listener to remove, not {@code null}
 *
 * @throws SecurityException if a security manager exists and the caller
 *         does not have
 *         {@code FlightRecorderPermission("accessFlightRecorder")}
 *
 * @return {@code true}, if the listener could be removed, {@code false}
 *         otherwise
 */
public static boolean removeListener(FlightRecorderListener changeListener) {
    Objects.requireNonNull(changeListener);
    Utils.checkAccessFlightRecorder();
    if (JVMSupport.isNotAvailable()) {
        return false;
    }

    return PlatformRecorder.removeListener(changeListener);
}
 
Example #20
Source File: FlightRecorder.java    From dragonwell8_jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Adds a recorder listener and captures the {@code AccessControlContext} to
 * use when invoking the listener.
 * <p>
 * If Flight Recorder is already initialized when the listener is added, the the method
 * {@link FlightRecorderListener#recorderInitialized(FlightRecorder)} method is
 * invoked before returning from this method.
 *
 * @param changeListener the listener to add, not {@code null}
 *
 * @throws SecurityException if a security manager exists and the caller
 *         does not have
 *         {@code FlightRecorderPermission("accessFlightRecorder")}
 */
public static void addListener(FlightRecorderListener changeListener) {
    Objects.requireNonNull(changeListener);
    Utils.checkAccessFlightRecorder();
    if (JVMSupport.isNotAvailable()) {
        return;
    }
    PlatformRecorder.addListener(changeListener);
}
 
Example #21
Source File: FlightRecorder.java    From openjdk-jdk8u with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Adds a recorder listener and captures the {@code AccessControlContext} to
 * use when invoking the listener.
 * <p>
 * If Flight Recorder is already initialized when the listener is added, then the method
 * {@link FlightRecorderListener#recorderInitialized(FlightRecorder)} method is
 * invoked before returning from this method.
 *
 * @param changeListener the listener to add, not {@code null}
 *
 * @throws SecurityException if a security manager exists and the caller
 *         does not have
 *         {@code FlightRecorderPermission("accessFlightRecorder")}
 */
public static void addListener(FlightRecorderListener changeListener) {
    Objects.requireNonNull(changeListener);
    Utils.checkAccessFlightRecorder();
    if (JVMSupport.isNotAvailable()) {
        return;
    }
    PlatformRecorder.addListener(changeListener);
}
 
Example #22
Source File: FlightRecorder.java    From openjdk-jdk8u with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Removes a recorder listener.
 * <p>
 * If the same listener is added multiple times, only one instance is
 * removed.
 *
 * @param changeListener listener to remove, not {@code null}
 *
 * @throws SecurityException if a security manager exists and the caller
 *         does not have
 *         {@code FlightRecorderPermission("accessFlightRecorder")}
 *
 * @return {@code true}, if the listener could be removed, {@code false}
 *         otherwise
 */
public static boolean removeListener(FlightRecorderListener changeListener) {
    Objects.requireNonNull(changeListener);
    Utils.checkAccessFlightRecorder();
    if (JVMSupport.isNotAvailable()) {
        return false;
    }

    return PlatformRecorder.removeListener(changeListener);
}
 
Example #23
Source File: FlightRecorder.java    From TencentKona-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Removes a recorder listener.
 * <p>
 * If the same listener is added multiple times, only one instance is
 * removed.
 *
 * @param changeListener listener to remove, not {@code null}
 *
 * @throws SecurityException if a security manager exists and the caller
 *         does not have
 *         {@code FlightRecorderPermission("accessFlightRecorder")}
 *
 * @return {@code true}, if the listener could be removed, {@code false}
 *         otherwise
 */
public static boolean removeListener(FlightRecorderListener changeListener) {
    Objects.requireNonNull(changeListener);
    Utils.checkAccessFlightRecorder();
    if (JVMSupport.isNotAvailable()) {
        return false;
    }

    return PlatformRecorder.removeListener(changeListener);
}
 
Example #24
Source File: FlightRecorder.java    From TencentKona-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Adds a recorder listener and captures the {@code AccessControlContext} to
 * use when invoking the listener.
 * <p>
 * If Flight Recorder is already initialized when the listener is added, then the method
 * {@link FlightRecorderListener#recorderInitialized(FlightRecorder)} method is
 * invoked before returning from this method.
 *
 * @param changeListener the listener to add, not {@code null}
 *
 * @throws SecurityException if a security manager exists and the caller
 *         does not have
 *         {@code FlightRecorderPermission("accessFlightRecorder")}
 */
public static void addListener(FlightRecorderListener changeListener) {
    Objects.requireNonNull(changeListener);
    Utils.checkAccessFlightRecorder();
    if (JVMSupport.isNotAvailable()) {
        return;
    }
    PlatformRecorder.addListener(changeListener);
}