Java Code Examples for jdk.jfr.RecordingState#NEW

The following examples show how to use jdk.jfr.RecordingState#NEW . 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: PlatformRecording.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void setDuration(Duration duration) {
    synchronized (recorder) {
        if (Utils.isState(getState(), RecordingState.STOPPED, RecordingState.CLOSED)) {
            throw new IllegalStateException("Duration can't be set after a recording has been stopped/closed");
        }
        setInternalDuration(duration);
        if (getState() != RecordingState.NEW) {
            updateTimer();
        }
    }
}
 
Example 2
Source File: PlatformRecorder.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
synchronized Recording newCopy(PlatformRecording r, boolean stop) {
    Recording newRec = new Recording();
    PlatformRecording copy = PrivateAccess.getInstance().getPlatformRecording(newRec);
    copy.setSettings(r.getSettings());
    copy.setMaxAge(r.getMaxAge());
    copy.setMaxSize(r.getMaxSize());
    copy.setDumpOnExit(r.getDumpOnExit());
    copy.setName("Clone of " + r.getName());
    copy.setToDisk(r.isToDisk());
    copy.setInternalDuration(r.getDuration());
    copy.setStartTime(r.getStartTime());
    copy.setStopTime(r.getStopTime());

    if (r.getState() == RecordingState.NEW) {
        return newRec;
    }
    if (r.getState() == RecordingState.DELAYED) {
        copy.scheduleStart(r.getStartTime());
        return newRec;
    }
    copy.setState(r.getState());
    // recording has started, copy chunks
    for (RepositoryChunk c : r.getChunks()) {
        copy.add(c);
    }
    if (r.getState() == RecordingState.RUNNING) {
        if (stop) {
            copy.stop("Stopped when cloning recording '" + r.getName() + "'");
        } else {
            if (r.getStopTime() != null) {
                TimerTask stopTask = copy.createStopTask();
                copy.setStopTask(copy.createStopTask());
                getTimer().schedule(stopTask, r.getStopTime().toEpochMilli());
            }
        }
    }
    return newRec;
}
 
Example 3
Source File: TestRecorderListener.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String... args) throws Exception {
    Listener recordingListener = new Listener(RecordingState.RUNNING);
    FlightRecorder.addListener(recordingListener);

    Listener stoppedListener = new Listener(RecordingState.STOPPED);
    FlightRecorder.addListener(stoppedListener);

    Listener finishedListener = new Listener(RecordingState.CLOSED);
    FlightRecorder.addListener(finishedListener);

    Recording recording = new Recording();
    if (recording.getState() != RecordingState.NEW) {
        recording.close();
        throw new Exception("New recording should be in NEW state");
    }

    recording.start();
    recordingListener.waitFor();

    recording.stop();
    stoppedListener.waitFor();

    recording.close();
    finishedListener.waitFor();

    testDefaultrecordingStateChangedListener();

}
 
Example 4
Source File: PlatformRecording.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void setDuration(Duration duration) {
    synchronized (recorder) {
        if (Utils.isState(getState(), RecordingState.STOPPED, RecordingState.CLOSED)) {
            throw new IllegalStateException("Duration can't be set after a recording has been stopped/closed");
        }
        setInternalDuration(duration);
        if (getState() != RecordingState.NEW) {
            updateTimer();
        }
    }
}
 
Example 5
Source File: PlatformRecorder.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
synchronized Recording newCopy(PlatformRecording r, boolean stop) {
    Recording newRec = new Recording();
    PlatformRecording copy = PrivateAccess.getInstance().getPlatformRecording(newRec);
    copy.setSettings(r.getSettings());
    copy.setMaxAge(r.getMaxAge());
    copy.setMaxSize(r.getMaxSize());
    copy.setDumpOnExit(r.getDumpOnExit());
    copy.setName("Clone of " + r.getName());
    copy.setToDisk(r.isToDisk());
    copy.setInternalDuration(r.getDuration());
    copy.setStartTime(r.getStartTime());
    copy.setStopTime(r.getStopTime());

    if (r.getState() == RecordingState.NEW) {
        return newRec;
    }
    if (r.getState() == RecordingState.DELAYED) {
        copy.scheduleStart(r.getStartTime());
        return newRec;
    }
    copy.setState(r.getState());
    // recording has started, copy chunks
    for (RepositoryChunk c : r.getChunks()) {
        copy.add(c);
    }
    if (r.getState() == RecordingState.RUNNING) {
        if (stop) {
            copy.stop("Stopped when cloning recording '" + r.getName() + "'");
        } else {
            if (r.getStopTime() != null) {
                TimerTask stopTask = copy.createStopTask();
                copy.setStopTask(copy.createStopTask());
                getTimer().schedule(stopTask, r.getStopTime().toEpochMilli());
            }
        }
    }
    return newRec;
}
 
Example 6
Source File: TestRecorderListener.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String... args) throws Exception {
    Listener recordingListener = new Listener(RecordingState.RUNNING);
    FlightRecorder.addListener(recordingListener);

    Listener stoppedListener = new Listener(RecordingState.STOPPED);
    FlightRecorder.addListener(stoppedListener);

    Listener finishedListener = new Listener(RecordingState.CLOSED);
    FlightRecorder.addListener(finishedListener);

    Recording recording = new Recording();
    if (recording.getState() != RecordingState.NEW) {
        recording.close();
        throw new Exception("New recording should be in NEW state");
    }

    recording.start();
    recordingListener.waitFor();

    recording.stop();
    stoppedListener.waitFor();

    recording.close();
    finishedListener.waitFor();

    testDefaultrecordingStateChangedListener();

}
 
Example 7
Source File: PlatformRecording.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void setDuration(Duration duration) {
    synchronized (recorder) {
        if (Utils.isState(getState(), RecordingState.STOPPED, RecordingState.CLOSED)) {
            throw new IllegalStateException("Duration can't be set after a recording has been stopped/closed");
        }
        setInternalDuration(duration);
        if (getState() != RecordingState.NEW) {
            updateTimer();
        }
    }
}
 
Example 8
Source File: PlatformRecorder.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
synchronized Recording newCopy(PlatformRecording r, boolean stop) {
    Recording newRec = new Recording();
    PlatformRecording copy = PrivateAccess.getInstance().getPlatformRecording(newRec);
    copy.setSettings(r.getSettings());
    copy.setMaxAge(r.getMaxAge());
    copy.setMaxSize(r.getMaxSize());
    copy.setDumpOnExit(r.getDumpOnExit());
    copy.setName("Clone of " + r.getName());
    copy.setToDisk(r.isToDisk());
    copy.setInternalDuration(r.getDuration());
    copy.setStartTime(r.getStartTime());
    copy.setStopTime(r.getStopTime());

    if (r.getState() == RecordingState.NEW) {
        return newRec;
    }
    if (r.getState() == RecordingState.DELAYED) {
        copy.scheduleStart(r.getStartTime());
        return newRec;
    }
    copy.setState(r.getState());
    // recording has started, copy chunks
    for (RepositoryChunk c : r.getChunks()) {
        copy.add(c);
    }
    if (r.getState() == RecordingState.RUNNING) {
        if (stop) {
            copy.stop("Stopped when cloning recording '" + r.getName() + "'");
        } else {
            if (r.getStopTime() != null) {
                TimerTask stopTask = copy.createStopTask();
                copy.setStopTask(copy.createStopTask());
                getTimer().schedule(stopTask, r.getStopTime().toEpochMilli());
            }
        }
    }
    return newRec;
}
 
Example 9
Source File: TestRecorderListener.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String... args) throws Exception {
    Listener recordingListener = new Listener(RecordingState.RUNNING);
    FlightRecorder.addListener(recordingListener);

    Listener stoppedListener = new Listener(RecordingState.STOPPED);
    FlightRecorder.addListener(stoppedListener);

    Listener finishedListener = new Listener(RecordingState.CLOSED);
    FlightRecorder.addListener(finishedListener);

    Recording recording = new Recording();
    if (recording.getState() != RecordingState.NEW) {
        recording.close();
        throw new Exception("New recording should be in NEW state");
    }

    recording.start();
    recordingListener.waitFor();

    recording.stop();
    stoppedListener.waitFor();

    recording.close();
    finishedListener.waitFor();

    testDefaultrecordingStateChangedListener();

}
 
Example 10
Source File: PlatformRecording.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
private void ensureOkForSchedule() {
    if (getState() != RecordingState.NEW) {
        throw new IllegalStateException("Only a new recoridng can be scheduled for start");
    }
}
 
Example 11
Source File: PlatformRecording.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public void copyTo(WriteableUserPath path, String reason, Map<String, String> dumpSettings) throws IOException {
    synchronized (recorder) {
        RecordingState state = getState();
        if (state == RecordingState.CLOSED) {
            throw new IOException("Recording \"" + name + "\" (id=" + id + ") has been closed, no contents to write");
        }
        if (state == RecordingState.DELAYED || state == RecordingState.NEW) {
            throw new IOException("Recording \"" + name + "\" (id=" + id + ") has not started, no contents to write");
        }
        if (state == RecordingState.STOPPED) {
            // have all we need, just write it
            dumpToFile(path, reason, getId());
            return;
        }

        // Recording is RUNNING, create a clone
        try(Recording r = new Recording()) {
            PlatformRecording clone = PrivateAccess.getInstance().getPlatformRecording(r);
            clone.setShouldWriteActiveRecordingEvent(false);
            clone.setName(getName());
            clone.setDestination(path);
            clone.setToDisk(true);
            // We purposely don't clone settings, since
            // a union a == a
            if (!isToDisk()) {
                // force memory contents to disk
                clone.start();
            } else {
                // using existing chunks on disk
                for (RepositoryChunk c : chunks) {
                    clone.add(c);
                }
                clone.setState(RecordingState.RUNNING);
                clone.setStartTime(getStartTime());
            }
            if (dumpSettings.isEmpty()) {
                clone.setSettings(getSettings());
                clone.stop(reason); // dumps to destination path here
            } else {
                // Risk of violating lock order here, since
                // clone.stop() will take recorder lock inside
                // metadata lock, but OK if we already
                // have recorder lock when we entered metadata lock
                Thread.holdsLock(recorder);
                synchronized(MetadataRepository.getInstance()) {
                    Thread.holdsLock(recorder);
                    Map<String, String> oldSettings = getSettings();
                    Map<String, String> newSettings = new HashMap<>(oldSettings);
                    // replace with dump settings
                    newSettings.putAll(dumpSettings);
                    clone.setSettings(newSettings);
                    clone.stop(reason);
                }
            }
        }
        return;
    }
}
 
Example 12
Source File: PlatformRecording.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private void ensureOkForSchedule() {
    if (getState() != RecordingState.NEW) {
        throw new IllegalStateException("Only a new recoridng can be scheduled for start");
    }
}
 
Example 13
Source File: PlatformRecording.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private void ensureOkForSchedule() {
    if (getState() != RecordingState.NEW) {
        throw new IllegalStateException("Only a new recoridng can be scheduled for start");
    }
}