Java Code Examples for jdk.jfr.RecordingState#RUNNING

The following examples show how to use jdk.jfr.RecordingState#RUNNING . 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 TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private void setSettings(Map<String, String> settings, boolean update) {
    if (LogTag.JFR_SETTING.shouldLog(LogLevel.INFO.level) && update) {
        TreeMap<String, String> ordered = new TreeMap<>(settings);
        Logger.log(LogTag.JFR_SETTING, LogLevel.INFO, "New settings for recording \"" + getName() + "\" (" + getId() + ")");
        for (Map.Entry<String, String> entry : ordered.entrySet()) {
            String text = entry.getKey() + "=\"" + entry.getValue() + "\"";
            Logger.log(LogTag.JFR_SETTING, LogLevel.INFO, text);
        }
    }
    synchronized (recorder) {
        this.settings = new LinkedHashMap<>(settings);
        if (getState() == RecordingState.RUNNING && update) {
            recorder.updateSettings();
        }
    }
}
 
Example 2
Source File: TestJcmdStartWithOptions.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
static void testRecordingNotStartedTooEarly() throws Exception {
    String name = "testRecordingNotStartedTooEarly";
    long delay = 2 * 1000;
    OutputAnalyzer output = JcmdHelper.jcmd("JFR.start",
            "name=" + name,
            "delay=" + delay + "ms");
    JcmdAsserts.assertRecordingIsScheduled(output, "1", "2 s");
    for (Recording r : FlightRecorder.getFlightRecorder().getRecordings()) {
        if (name.equals(r.getName())) {
            while(r.getState() != RecordingState.RUNNING) {
                Thread.sleep(10);
            }
            long currentTime = System.currentTimeMillis();
            long afterActualStart = currentTime + delay;
            JcmdAsserts.assertStartTimeGreaterOrEqualThanMBeanValue(name, afterActualStart);
            JcmdHelper.stopAndCheck(name);
            return;
        }
    }
    throw new Exception("Could not find recording with name " + name);
}
 
Example 3
Source File: TestJcmdStartWithOptions.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
static void testRecordingNotStartedTooEarly() throws Exception {
    String name = "testRecordingNotStartedTooEarly";
    long delay = 2 * 1000;
    OutputAnalyzer output = JcmdHelper.jcmd("JFR.start",
            "name=" + name,
            "delay=" + delay + "ms");
    JcmdAsserts.assertRecordingIsScheduled(output, "1", "2 s");
    for (Recording r : FlightRecorder.getFlightRecorder().getRecordings()) {
        if (name.equals(r.getName())) {
            while(r.getState() != RecordingState.RUNNING) {
                Thread.sleep(10);
            }
            long currentTime = System.currentTimeMillis();
            long afterActualStart = currentTime + delay;
            JcmdAsserts.assertStartTimeGreaterOrEqualThanMBeanValue(name, afterActualStart);
            JcmdHelper.stopAndCheck(name);
            return;
        }
    }
    throw new Exception("Could not find recording with name " + name);
}
 
Example 4
Source File: PlatformRecording.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private void setSettings(Map<String, String> settings, boolean update) {
    if (Logger.shouldLog(LogTag.JFR_SETTING, LogLevel.INFO) && update) {
        TreeMap<String, String> ordered = new TreeMap<>(settings);
        Logger.log(LogTag.JFR_SETTING, LogLevel.INFO, "New settings for recording \"" + getName() + "\" (" + getId() + ")");
        for (Map.Entry<String, String> entry : ordered.entrySet()) {
            String text = entry.getKey() + "=\"" + entry.getValue() + "\"";
            Logger.log(LogTag.JFR_SETTING, LogLevel.INFO, text);
        }
    }
    synchronized (recorder) {
        this.settings = new LinkedHashMap<>(settings);
        if (getState() == RecordingState.RUNNING && update) {
            recorder.updateSettings();
        }
    }
}
 
Example 5
Source File: TestJcmdStartWithOptions.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
static void testRecordingNotStartedTooEarly() throws Exception {
    String name = "testRecordingNotStartedTooEarly";
    long delay = 2 * 1000;
    OutputAnalyzer output = JcmdHelper.jcmd("JFR.start",
            "name=" + name,
            "delay=" + delay + "ms");
    JcmdAsserts.assertRecordingIsScheduled(output, "1", "2 s");
    for (Recording r : FlightRecorder.getFlightRecorder().getRecordings()) {
        if (name.equals(r.getName())) {
            while(r.getState() != RecordingState.RUNNING) {
                Thread.sleep(10);
            }
            long currentTime = System.currentTimeMillis();
            long afterActualStart = currentTime + delay;
            JcmdAsserts.assertStartTimeGreaterOrEqualThanMBeanValue(name, afterActualStart);
            JcmdHelper.stopAndCheck(name);
            return;
        }
    }
    throw new Exception("Could not find recording with name " + name);
}
 
Example 6
Source File: PlatformRecorder.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public synchronized void fillWithRecordedData(PlatformRecording target, Boolean pathToGcRoots) {
    boolean running = false;
    boolean toDisk = false;

    for (PlatformRecording r : recordings) {
        if (r.getState() == RecordingState.RUNNING) {
            running = true;
            if (r.isToDisk()) {
                toDisk = true;
            }
        }
    }
    // If needed, flush data from memory
    if (running) {
        if (toDisk) {
            OldObjectSample.emit(recordings, pathToGcRoots);
            rotateDisk();
        } else {
            try (PlatformRecording snapshot = newTemporaryRecording()) {
                snapshot.setToDisk(true);
                snapshot.setShouldWriteActiveRecordingEvent(false);
                snapshot.start();
                OldObjectSample.emit(recordings, pathToGcRoots);
                snapshot.stop("Snapshot dump");
                fillWithDiskChunks(target);
            }
            return;
        }
    }
    fillWithDiskChunks(target);
}
 
Example 7
Source File: PlatformRecorder.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private void finishChunk(RepositoryChunk chunk, Instant time, PlatformRecording ignoreMe) {
    chunk.finish(time);
    for (PlatformRecording r : getRecordings()) {
        if (r != ignoreMe && r.getState() == RecordingState.RUNNING) {
            r.appendChunk(chunk);
        }
    }
}
 
Example 8
Source File: PlatformRecorder.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private List<PlatformRecording> getRunningRecordings() {
    List<PlatformRecording> runningRecordings = new ArrayList<>();
    for (PlatformRecording recording : getRecordings()) {
        if (recording.getState() == RecordingState.RUNNING) {
            runningRecordings.add(recording);
        }
    }
    return runningRecordings;
}
 
Example 9
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 10
Source File: ShutdownHook.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void run() {
    // this allocation is done in order to fetch a new TLAB before
    // starting any "real" operations. In low memory situations,
    // we would like to take an OOM as early as possible.
    tlabDummyObject = new Object();

    for (PlatformRecording recording : recorder.getRecordings()) {
        if (recording.getDumpOnExit() && recording.getState() == RecordingState.RUNNING) {
            dump(recording);
        }
    }
    recorder.destroy();
}
 
Example 11
Source File: ShutdownHook.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void run() {
    // this allocation is done in order to fetch a new TLAB before
    // starting any "real" operations. In low memory situations,
    // we would like to take an OOM as early as possible.
    tlabDummyObject = new Object();

    for (PlatformRecording recording : recorder.getRecordings()) {
        if (recording.getDumpOnExit() && recording.getState() == RecordingState.RUNNING) {
            dump(recording);
        }
    }
    recorder.destroy();
}
 
Example 12
Source File: ShutdownHook.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void run() {
    // this allocation is done in order to fetch a new TLAB before
    // starting any "real" operations. In low memory situations,
    // we would like to take an OOM as early as possible.
    tlabDummyObject = new Object();

    for (PlatformRecording recording : recorder.getRecordings()) {
        if (recording.getDumpOnExit() && recording.getState() == RecordingState.RUNNING) {
            dump(recording);
        }
    }
    recorder.destroy();
}
 
Example 13
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 14
Source File: PlatformRecorder.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private void writeMetaEvents() {

        if (activeRecordingEvent.isEnabled()) {
            for (PlatformRecording r : getRecordings()) {
                if (r.getState() == RecordingState.RUNNING && r.shouldWriteMetadataEvent()) {
                    ActiveRecordingEvent event = new ActiveRecordingEvent();
                    event.id = r.getId();
                    event.name = r.getName();
                    WriteableUserPath p = r.getDestination();
                    event.destination = p == null ? null : p.getText();
                    Duration d = r.getDuration();
                    event.recordingDuration = d == null ? Long.MAX_VALUE : d.toMillis();
                    Duration age = r.getMaxAge();
                    event.maxAge = age == null ? Long.MAX_VALUE : age.toMillis();
                    Long size = r.getMaxSize();
                    event.maxSize = size == null ? Long.MAX_VALUE : size;
                    Instant start = r.getStartTime();
                    event.recordingStart = start == null ? Long.MAX_VALUE : start.toEpochMilli();
                    event.commit();
                }
            }
        }
        if (activeSettingEvent.isEnabled()) {
            for (EventControl ec : MetadataRepository.getInstance().getEventControls()) {
                ec.writeActiveSettingEvent();
            }
        }
    }
 
Example 15
Source File: PlatformRecorder.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private List<PlatformRecording> getRunningRecordings() {
    List<PlatformRecording> runningRecordings = new ArrayList<>();
    for (PlatformRecording recording : getRecordings()) {
        if (recording.getState() == RecordingState.RUNNING) {
            runningRecordings.add(recording);
        }
    }
    return runningRecordings;
}
 
Example 16
Source File: PlatformRecording.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void setSetting(String id, String value) {
    synchronized (recorder) {
        this.settings.put(id, value);
        if (getState() == RecordingState.RUNNING) {
            recorder.updateSettings();
        }
    }
}
 
Example 17
Source File: PlatformRecorder.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private void finishChunk(RepositoryChunk chunk, Instant time, PlatformRecording ignoreMe) {
    chunk.finish(time);
    for (PlatformRecording r : getRecordings()) {
        if (r != ignoreMe && r.getState() == RecordingState.RUNNING) {
            r.appendChunk(chunk);
        }
    }
}
 
Example 18
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 19
Source File: PlatformRecorder.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
synchronized void finish(PlatformRecording recording) {
    if (recording.getState() == RecordingState.RUNNING) {
        recording.stop("Recording closed");
    }
    recordings.remove(recording);
}
 
Example 20
Source File: PlatformRecorder.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
synchronized void finish(PlatformRecording recording) {
    if (recording.getState() == RecordingState.RUNNING) {
        recording.stop("Recording closed");
    }
    recordings.remove(recording);
}