jdk.jfr.RecordingState Java Examples

The following examples show how to use jdk.jfr.RecordingState. 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: TestStateDuration.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Throwable {
    Duration duration = Duration.ofSeconds(2);
    Recording r = new Recording();
    r.setDuration(duration);
    CommonHelper.verifyRecordingState(r, RecordingState.NEW);
    Instant start = Instant.now();
    System.out.println("Recording with duration " + duration + " started at " + start);
    r.start();

    // Wait for recording to stop automatically
    System.out.println("Waiting for recording to reach STOPPED state");
    CommonHelper.waitForRecordingState(r, RecordingState.STOPPED);
    Instant stop = Instant.now();
    Duration measuredDuration = Duration.between(start, stop);
    System.out.println("Recording stopped at " + stop + ". Measured duration " + measuredDuration);
    // Timer task uses System.currentMillis, and java.time uses other source.
    Duration deltaDueToClockNotInSync = Duration.ofMillis(100);
    Asserts.assertGreaterThan(measuredDuration.plus(deltaDueToClockNotInSync), duration);
    verifyIllegalState(() -> r.start(), "start() after stop()");
    r.close();
    CommonHelper.verifyRecordingState(r, RecordingState.CLOSED);
}
 
Example #2
Source File: TestCopyToRunning.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    FlightRecorderMXBean bean = JmxHelper.getFlighteRecorderMXBean();

    long recId = bean.newRecording();
    bean.startRecording(recId);
    SimpleEventHelper.createEvent(1);

    Path path = Paths.get(".", "my.jfr");
    bean.copyTo(recId, path.toString());

    List<RecordedEvent> events = RecordingFile.readAllEvents(path);
    Asserts.assertTrue(events.iterator().hasNext(), "No events found");
    for (RecordedEvent event : events) {
        System.out.println("Event:" + event);
    }

    Recording recording = getRecording(recId);
    Asserts.assertEquals(recording.getState(), RecordingState.RUNNING, "Recording not in state running");
    bean.stopRecording(recId);
    Asserts.assertEquals(recording.getState(), RecordingState.STOPPED, "Recording not in state stopped");
    bean.closeRecording(recId);
    Asserts.assertEquals(recording.getState(), RecordingState.CLOSED, "Recording not in state closed");
}
 
Example #3
Source File: TestStateInvalid.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Throwable {
    Recording r = new Recording();
    CommonHelper.verifyRecordingState(r, RecordingState.NEW);
    verifyIllegalState(() -> r.stop(), "stop() when not started");
    CommonHelper.verifyRecordingState(r, RecordingState.NEW);

    r.start();
    CommonHelper.verifyRecordingState(r, RecordingState.RUNNING);
    verifyIllegalState(() -> r.start(), "double start()");
    CommonHelper.verifyRecordingState(r, RecordingState.RUNNING);

    r.stop();
    CommonHelper.verifyRecordingState(r, RecordingState.STOPPED);
    verifyIllegalState(() -> r.stop(), "double stop()");
    verifyIllegalState(() -> r.start(), "start() after stop()");
    CommonHelper.verifyRecordingState(r, RecordingState.STOPPED);

    r.close();
    CommonHelper.verifyRecordingState(r, RecordingState.CLOSED);
    verifyIllegalState(() -> r.stop(), "stop() after close()");
    verifyIllegalState(() -> r.start(), "start() after close()");
    CommonHelper.verifyRecordingState(r, RecordingState.CLOSED);
}
 
Example #4
Source File: OldObjectSample.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void emit(List<PlatformRecording> recordings, Boolean pathToGcRoots) {
    boolean enabled = false;
    long cutoffNanos = Boolean.TRUE.equals(pathToGcRoots) ? Long.MAX_VALUE : 0L;
    for (PlatformRecording r : recordings) {
        if (r.getState() == RecordingState.RUNNING) {
            if (isEnabled(r)) {
                enabled = true;
                long c = CutoffSetting.parseValueSafe(r.getSettings().get(OLD_OBJECT_CUTOFF));
                cutoffNanos = Math.max(c, cutoffNanos);
            }
        }
    }
    if (enabled) {
        long ticks = Utils.nanosToTicks(cutoffNanos);
        JVM.getJVM().emitOldObjectSamples(ticks, WhiteBox.getWriteAllObjectSamples());
    }
}
 
Example #5
Source File: TestListener.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Throwable {
    MyListener listener1 = new MyListener();
    MyListener listener2 = new MyListener();
    FlightRecorder.addListener(listener1);
    FlightRecorder.addListener(listener2);

    Recording r1 = new Recording();
    listener1.verifyState(0, RecordingState.NEW);
    listener2.verifyState(0, RecordingState.NEW);

    r1.start();
    listener1.verifyState(1, RecordingState.RUNNING);
    listener2.verifyState(1, RecordingState.RUNNING);

    FlightRecorder.removeListener(listener1); // listener1 should not get more callbacks.
    r1.stop();
    listener1.verifyState(1, RecordingState.RUNNING);
    listener2.verifyState(2, RecordingState.STOPPED);

    r1.close();
    listener1.verifyState(1, RecordingState.RUNNING);
    listener2.verifyState(3, RecordingState.CLOSED);
    FlightRecorder.removeListener(listener2);
}
 
Example #6
Source File: TestStateScheduleStart.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Throwable {
    Recording r = new Recording();
    CommonHelper.verifyRecordingState(r, RecordingState.NEW);

    Instant start = Instant.now();
    r.scheduleStart(Duration.ofMillis(2000));

    System.out.println("Wait for recording to start: " + start);
    CommonHelper.waitForRecordingState(r, RecordingState.RUNNING);

    // Duration should be about 2000 ms.
    // Test servers vary too much in performance to make an accurate check.
    // We only check that we don't time out after 20 seconds.
    Instant started = Instant.now();
    long millis = Duration.between(start, started).toMillis();
    System.out.println("Recording started at " + started + ". Delta millis=" + millis + ", expeced about 2000");

    verifyIllegalState(() -> r.start(), "double start()");
    r.stop();
    CommonHelper.verifyRecordingState(r, RecordingState.STOPPED);
    r.close();
    CommonHelper.verifyRecordingState(r, RecordingState.CLOSED);
}
 
Example #7
Source File: PlatformRecording.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void close() {
    RecordingState oldState;
    RecordingState newState;

    synchronized (recorder) {
        oldState = getState();
        if (RecordingState.CLOSED != getState()) {
            if (startTask != null) {
                startTask.cancel();
                startTask = null;
            }
            recorder.finish(this);
            for (RepositoryChunk c : chunks) {
                removed(c);
            }
            chunks.clear();
            setState(RecordingState.CLOSED);
            Logger.log(LogTag.JFR, LogLevel.INFO, "Closed recording \"" + getName() + "\" (" + getId() + ")");
        }
        newState = getState();
    }
    notifyIfStateChanged(newState, oldState);
}
 
Example #8
Source File: PlatformRecording.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public InputStream open(Instant start, Instant end) throws IOException {
    synchronized (recorder) {
        if (getState() != RecordingState.STOPPED) {
            throw new IOException("Recording must be stopped before it can be read.");
        }
        List<RepositoryChunk> chunksToUse = new ArrayList<RepositoryChunk>();
        for (RepositoryChunk chunk : chunks) {
            if (chunk.isFinished()) {
                Instant chunkStart = chunk.getStartTime();
                Instant chunkEnd = chunk.getEndTime();
                if (start == null || !chunkEnd.isBefore(start)) {
                    if (end == null || !chunkStart.isAfter(end)) {
                        chunksToUse.add(chunk);
                    }
                }
            }
        }
        if (chunksToUse.isEmpty()) {
            return null;
        }
        return new ChunkInputStream(chunksToUse);
    }
}
 
Example #9
Source File: TestListener.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Throwable {
    MyListener listener1 = new MyListener();
    MyListener listener2 = new MyListener();
    FlightRecorder.addListener(listener1);
    FlightRecorder.addListener(listener2);

    Recording r1 = new Recording();
    listener1.verifyState(0, RecordingState.NEW);
    listener2.verifyState(0, RecordingState.NEW);

    r1.start();
    listener1.verifyState(1, RecordingState.RUNNING);
    listener2.verifyState(1, RecordingState.RUNNING);

    FlightRecorder.removeListener(listener1); // listener1 should not get more callbacks.
    r1.stop();
    listener1.verifyState(1, RecordingState.RUNNING);
    listener2.verifyState(2, RecordingState.STOPPED);

    r1.close();
    listener1.verifyState(1, RecordingState.RUNNING);
    listener2.verifyState(3, RecordingState.CLOSED);
    FlightRecorder.removeListener(listener2);
}
 
Example #10
Source File: TestCopyToRunning.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    FlightRecorderMXBean bean = JmxHelper.getFlighteRecorderMXBean();

    long recId = bean.newRecording();
    bean.startRecording(recId);
    SimpleEventHelper.createEvent(1);

    Path path = Paths.get(".", "my.jfr");
    bean.copyTo(recId, path.toString());

    List<RecordedEvent> events = RecordingFile.readAllEvents(path);
    Asserts.assertTrue(events.iterator().hasNext(), "No events found");
    for (RecordedEvent event : events) {
        System.out.println("Event:" + event);
    }

    Recording recording = getRecording(recId);
    Asserts.assertEquals(recording.getState(), RecordingState.RUNNING, "Recording not in state running");
    bean.stopRecording(recId);
    Asserts.assertEquals(recording.getState(), RecordingState.STOPPED, "Recording not in state stopped");
    bean.closeRecording(recId);
    Asserts.assertEquals(recording.getState(), RecordingState.CLOSED, "Recording not in state closed");
}
 
Example #11
Source File: TestStateScheduleStart.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Throwable {
    Recording r = new Recording();
    CommonHelper.verifyRecordingState(r, RecordingState.NEW);

    Instant start = Instant.now();
    r.scheduleStart(Duration.ofMillis(2000));

    System.out.println("Wait for recording to start: " + start);
    CommonHelper.waitForRecordingState(r, RecordingState.RUNNING);

    // Duration should be about 2000 ms.
    // Test servers vary too much in performance to make an accurate check.
    // We only check that we don't time out after 20 seconds.
    Instant started = Instant.now();
    long millis = Duration.between(start, started).toMillis();
    System.out.println("Recording started at " + started + ". Delta millis=" + millis + ", expeced about 2000");

    verifyIllegalState(() -> r.start(), "double start()");
    r.stop();
    CommonHelper.verifyRecordingState(r, RecordingState.STOPPED);
    r.close();
    CommonHelper.verifyRecordingState(r, RecordingState.CLOSED);
}
 
Example #12
Source File: TestRecordingState.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Throwable {
    FlightRecorderMXBean bean = JmxHelper.getFlighteRecorderMXBean();

    List<RecordingInfo> preCreateRecordings = bean.getRecordings();
    long recId = bean.newRecording();
    JmxHelper.verifyNotExists(recId, preCreateRecordings);
    JmxHelper.verifyState(recId, RecordingState.NEW, bean);

    bean.startRecording(recId);
    JmxHelper.verifyState(recId, RecordingState.RUNNING, bean);

    bean.stopRecording(recId);
    JmxHelper.verifyState(recId, RecordingState.STOPPED, bean);

    bean.closeRecording(recId);
    JmxHelper.verifyNotExists(recId, bean.getRecordings());
}
 
Example #13
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 #14
Source File: OldObjectSample.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void emit(List<PlatformRecording> recordings, Boolean pathToGcRoots) {
    boolean enabled = false;
    long cutoffNanos = Boolean.TRUE.equals(pathToGcRoots) ? Long.MAX_VALUE : 0L;
    for (PlatformRecording r : recordings) {
        if (r.getState() == RecordingState.RUNNING) {
            if (isEnabled(r)) {
                enabled = true;
                long c = CutoffSetting.parseValueSafe(r.getSettings().get(OLD_OBJECT_CUTOFF));
                cutoffNanos = Math.max(c, cutoffNanos);
            }
        }
    }
    if (enabled) {
        long ticks = Utils.nanosToTicks(cutoffNanos);
        JVM.getJVM().emitOldObjectSamples(ticks, WhiteBox.getWriteAllObjectSamples());
    }
}
 
Example #15
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 #16
Source File: TestDestWithDuration.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Throwable {
    Path dest = Paths.get(".", "my.jfr");
    Recording r = new Recording();
    SimpleEventHelper.enable(r, true);
    r.setDestination(dest);
    r.start();
    SimpleEventHelper.createEvent(1);

    // Waiting for recording to auto close after duration
    r.setDuration(Duration.ofSeconds(1));
    System.out.println("Waiting for recording to auto close after duration");
    CommonHelper.waitForRecordingState(r, RecordingState.CLOSED);
    System.out.println("recording state = " + r.getState());
    Asserts.assertEquals(r.getState(), RecordingState.CLOSED, "Recording not closed");

    Asserts.assertTrue(Files.exists(dest), "No recording file: " + dest);
    System.out.printf("Recording file size=%d%n", Files.size(dest));
    Asserts.assertNotEquals(Files.size(dest), 0L, "File length 0. Should at least be some bytes");

    List<RecordedEvent> events = RecordingFile.readAllEvents(dest);
    Asserts.assertFalse(events.isEmpty(), "No event found");
    System.out.printf("Found event %s%n", events.get(0).getEventType().getName());
}
 
Example #17
Source File: TestStartDelayRunning.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 {
    System.out.println("Test started at " + Instant.now());
    Recording r = StartupHelper.getRecording("TestStartDelay");
    CommonHelper.waitForRecordingState(r, RecordingState.RUNNING);
    System.out.println("Recording startTime = " + r.getStartTime());
    Asserts.assertNotNull(r.getStartTime(), "StartTime was null after delay");
    Asserts.assertGreaterThan(Instant.now(), r.getStartTime(), "Current time should exceed start time");
    r.stop();
    r.close();
}
 
Example #18
Source File: TestRecorderListener.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void recordingStateChanged(Recording recording) {
    System.out.println("Listener: recording=" + recording.getName() + " state=" + recording.getState());
    RecordingState rs = recording.getState();
    if (rs == waitFor) {
        latch.countDown();
    }
}
 
Example #19
Source File: PlatformRecording.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
void scheduleStart(Instant startTime) {
    synchronized (recorder) {
        ensureOkForSchedule();
        this.startTime = startTime;
        setState(RecordingState.DELAYED);
        startTask = createStartTask();
        recorder.getTimer().schedule(startTask, startTime.toEpochMilli());
    }
}
 
Example #20
Source File: PlatformRecording.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void setDestination(WriteableUserPath userSuppliedPath) throws IOException {
    synchronized (recorder) {
        if (Utils.isState(getState(), RecordingState.STOPPED, RecordingState.CLOSED)) {
            throw new IllegalStateException("Destination can't be set on a recording that has been stopped/closed");
        }
        this.destination = userSuppliedPath;
    }
}
 
Example #21
Source File: TestRecordingCopy.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 {

        Recording original = new Recording();
        original.enable(SimpleEvent.class);

        Recording newCopy = original.copy(false);
        Asserts.assertEquals(newCopy.getState(), RecordingState.NEW);

        Recording newStoppedCopy = original.copy(true);
        Asserts.assertEquals(newStoppedCopy.getState(), RecordingState.NEW);

        original.start();

        SimpleEvent ev = new SimpleEvent();
        ev.id = EVENT_ID;
        ev.commit();

        // Verify a stopped copy
        Recording stoppedCopy = original.copy(true);
        Asserts.assertEquals(stoppedCopy.getState(), RecordingState.STOPPED);
        assertCopy(stoppedCopy, original);

        // Verify a running copy
        Recording runningCopy = original.copy(false);
        Asserts.assertEquals(runningCopy.getState(), RecordingState.RUNNING);
        assertCopy(runningCopy, original);

        original.stop();

        // Verify a stopped copy of a stopped
        stoppedCopy = original.copy(true);
        Asserts.assertEquals(stoppedCopy.getState(), RecordingState.STOPPED);
        assertCopy(stoppedCopy, original);

        // Clean-up
        original.close();
        runningCopy.stop();
        runningCopy.close();
        stoppedCopy.close();
    }
 
Example #22
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 #23
Source File: PlatformRecording.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private void notifyIfStateChanged(RecordingState newState, RecordingState oldState) {
    if (oldState == newState) {
        return;
    }
    for (FlightRecorderListener cl : PlatformRecorder.getListeners()) {
        try {
            cl.recordingStateChanged(getRecording());
        } catch (RuntimeException re) {
            Logger.log(JFR, WARN, "Error notifying recorder listener:" + re.getMessage());
        }
    }
}
 
Example #24
Source File: TestRecorderListener.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void recordingStateChanged(Recording recording) {
    System.out.println("Listener: recording=" + recording.getName() + " state=" + recording.getState());
    RecordingState rs = recording.getState();
    if (rs == waitFor) {
        latch.countDown();
    }
}
 
Example #25
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 #26
Source File: TestStartDelayRunning.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 {
    System.out.println("Test started at " + Instant.now());
    Recording r = StartupHelper.getRecording("TestStartDelay");
    CommonHelper.waitForRecordingState(r, RecordingState.RUNNING);
    System.out.println("Recording startTime = " + r.getStartTime());
    Asserts.assertNotNull(r.getStartTime(), "StartTime was null after delay");
    Asserts.assertGreaterThan(Instant.now(), r.getStartTime(), "Current time should exceed start time");
    r.stop();
    r.close();
}
 
Example #27
Source File: TestSnapshot.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void assertStaticOptions(Recording snapshot) {
    Asserts.assertTrue(snapshot.getName().startsWith("Snapshot"), "Recording name should begin with 'Snapshot'");
    Asserts.assertEquals(snapshot.getMaxAge(), null);
    Asserts.assertEquals(snapshot.getMaxSize(), 0L);
    Asserts.assertTrue(snapshot.getSettings().isEmpty());
    Asserts.assertEquals(snapshot.getState(), RecordingState.STOPPED);
    Asserts.assertEquals(snapshot.getDumpOnExit(), false);
    Asserts.assertEquals(snapshot.getDestination(), null);
}
 
Example #28
Source File: TestStartMaxAgeSize.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 {
    Recording r = StartupHelper.getRecording("TestStartMaxAgeSize");
    CommonHelper.verifyRecordingState(r, RecordingState.RUNNING);
    Asserts.assertEquals(r.getMaxAge(), Duration.ofSeconds(10), "Wrong maxAge");
    Asserts.assertEquals(r.getMaxSize(), 1000000L, "Wrong maxSize");
    r.stop();
    r.close();
}
 
Example #29
Source File: TestClone.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 {
    FlightRecorderMXBean bean = JmxHelper.getFlighteRecorderMXBean();

    long orgId = bean.newRecording();
    bean.startRecording(orgId);
    SimpleEventHelper.createEvent(1); // Should be in both org and clone

    long cloneId = bean.cloneRecording(orgId, false);
    Asserts.assertNotEquals(orgId, cloneId, "clone id should not be same as org id");

    List<RecordingInfo> recordings = bean.getRecordings();
    JmxHelper.verifyState(orgId, RecordingState.RUNNING, recordings);
    JmxHelper.verifyState(cloneId, RecordingState.RUNNING, recordings);

    bean.stopRecording(orgId);
    recordings = bean.getRecordings();
    JmxHelper.verifyState(orgId, RecordingState.STOPPED, recordings);
    JmxHelper.verifyState(cloneId, RecordingState.RUNNING, recordings);

    SimpleEventHelper.createEvent(2);  // Should only be in clone

    bean.stopRecording(cloneId);
    recordings = bean.getRecordings();
    JmxHelper.verifyState(orgId, RecordingState.STOPPED, recordings);
    JmxHelper.verifyState(cloneId, RecordingState.STOPPED, recordings);

    Path orgPath = Paths.get(".", "org.jfr");
    Path clonePath = Paths.get(".", "clone.jfr");
    bean.copyTo(orgId, orgPath.toString());
    bean.copyTo(cloneId, clonePath.toString());

    verifyEvents(orgPath, 1);
    verifyEvents(clonePath, 1, 2);

    bean.closeRecording(orgId);
    bean.closeRecording(cloneId);
}
 
Example #30
Source File: TestMultipleRecordings.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static long createRecording(FlightRecorderMXBean bean) throws Exception {
    List<RecordingInfo> preCreateRecordings = bean.getRecordings();
    long recId = bean.newRecording();
    JmxHelper.verifyNotExists(recId, preCreateRecordings);
    JmxHelper.verifyState(recId, RecordingState.NEW, bean);
    return recId;
}