Java Code Examples for jdk.jfr.Recording#setDuration()

The following examples show how to use jdk.jfr.Recording#setDuration() . 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: TestDestWithDuration.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 {
    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 3
Source File: TestStateDuration.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 {
    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 4
Source File: TestTimeDuration.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();
    final Duration duration = Duration.ofMillis(30000);

    r.setDuration(duration);
    Asserts.assertNull(r.getStartTime(), "getStartTime() not null before start");
    Asserts.assertNull(r.getStopTime(), "getStopTime() not null before start");

    final Instant beforeStart = Instant.now();
    r.start();
    final Instant afterStart = Instant.now();

    Asserts.assertNotNull(r.getStartTime(), "getStartTime() null after start()");
    Asserts.assertGreaterThanOrEqual(r.getStartTime(), beforeStart, "getStartTime() < beforeStart");
    Asserts.assertLessThanOrEqual(r.getStartTime(), afterStart, "getStartTime() > afterStart");

    Asserts.assertNotNull(r.getStopTime(), "getStopTime() null after start with duration");
    Asserts.assertGreaterThanOrEqual(r.getStopTime(), beforeStart.plus(duration), "getStopTime() < beforeStart + duration");
    Asserts.assertLessThanOrEqual(r.getStopTime(), afterStart.plus(duration), "getStopTime() > afterStart + duration");

    r.close();
}
 
Example 5
Source File: TestDuration.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 {
    final Duration duration = Duration.ofSeconds(1);
    Recording r = new Recording();
    r.setDuration(duration);
    Asserts.assertEquals(duration, r.getDuration(), "Wrong get/set duration");

    r.start();
    Instant afterStart = Instant.now();
    CommonHelper.waitForRecordingState(r, RecordingState.STOPPED);

    Instant afterStop = Instant.now();
    Asserts.assertLessThanOrEqual(r.getStopTime(), afterStop, "getStopTime() > afterStop");
    long durationMillis = Duration.between(afterStart, r.getStopTime()).toMillis();

    // Performance of test servers varies too much to make a strict check of actual duration.
    // We only check that recording stops before timeout of 20 seconds.
    System.out.printf("Recording stopped after %d ms, expected above 1000 ms%n", durationMillis);
    r.close();
}
 
Example 6
Source File: TestRecordingInfo.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 recording = new Recording(Configuration.getConfiguration("profile"));
    recording.setDestination(Paths.get(".", "my.jfr"));
    recording.setDumpOnExit(true);
    recording.setDuration(Duration.ofSeconds(60));
    recording.setMaxAge(Duration.ofHours(1));
    recording.setMaxSize(123456789);
    recording.setName("myName");
    recording.enable("java.exception_throw").with("threashold", "2 s");
    recording.setToDisk(true);

    recording.start();
    CommonHelper.verifyRecordingState(recording, RecordingState.RUNNING); // Wait until running

    FlightRecorderMXBean bean = JmxHelper.getFlighteRecorderMXBean();
    RecordingInfo info = JmxHelper.verifyExists(recording.getId(), bean.getRecordings());

    System.out.println(JmxHelper.asString(recording));
    System.out.println(JmxHelper.asString(info));
    JmxHelper.verifyEquals(info, recording);

    recording.stop();
    recording.close();
}
 
Example 7
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 8
Source File: TestRecordingInfo.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 {
    Recording recording = new Recording(Configuration.getConfiguration("profile"));
    recording.setDestination(Paths.get(".", "my.jfr"));
    recording.setDumpOnExit(true);
    recording.setDuration(Duration.ofSeconds(60));
    recording.setMaxAge(Duration.ofHours(1));
    recording.setMaxSize(123456789);
    recording.setName("myName");
    recording.enable("java.exception_throw").with("threashold", "2 s");
    recording.setToDisk(true);

    recording.start();
    CommonHelper.verifyRecordingState(recording, RecordingState.RUNNING); // Wait until running

    FlightRecorderMXBean bean = JmxHelper.getFlighteRecorderMXBean();
    RecordingInfo info = JmxHelper.verifyExists(recording.getId(), bean.getRecordings());

    System.out.println(JmxHelper.asString(recording));
    System.out.println(JmxHelper.asString(info));
    JmxHelper.verifyEquals(info, recording);

    recording.stop();
    recording.close();
}
 
Example 9
Source File: TestTimeDuration.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();
    final Duration duration = Duration.ofMillis(30000);

    r.setDuration(duration);
    Asserts.assertNull(r.getStartTime(), "getStartTime() not null before start");
    Asserts.assertNull(r.getStopTime(), "getStopTime() not null before start");

    final Instant beforeStart = Instant.now();
    r.start();
    final Instant afterStart = Instant.now();

    Asserts.assertNotNull(r.getStartTime(), "getStartTime() null after start()");
    Asserts.assertGreaterThanOrEqual(r.getStartTime(), beforeStart, "getStartTime() < beforeStart");
    Asserts.assertLessThanOrEqual(r.getStartTime(), afterStart, "getStartTime() > afterStart");

    Asserts.assertNotNull(r.getStopTime(), "getStopTime() null after start with duration");
    Asserts.assertGreaterThanOrEqual(r.getStopTime(), beforeStart.plus(duration), "getStopTime() < beforeStart + duration");
    Asserts.assertLessThanOrEqual(r.getStopTime(), afterStart.plus(duration), "getStopTime() > afterStart + duration");

    r.close();
}
 
Example 10
Source File: TestDuration.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 {
    final Duration duration = Duration.ofSeconds(1);
    Recording r = new Recording();
    r.setDuration(duration);
    Asserts.assertEquals(duration, r.getDuration(), "Wrong get/set duration");

    r.start();
    Instant afterStart = Instant.now();
    CommonHelper.waitForRecordingState(r, RecordingState.STOPPED);

    Instant afterStop = Instant.now();
    Asserts.assertLessThanOrEqual(r.getStopTime(), afterStop, "getStopTime() > afterStop");
    long durationMillis = Duration.between(afterStart, r.getStopTime()).toMillis();

    // Performance of test servers varies too much to make a strict check of actual duration.
    // We only check that recording stops before timeout of 20 seconds.
    System.out.printf("Recording stopped after %d ms, expected above 1000 ms%n", durationMillis);
    r.close();
}
 
Example 11
Source File: TestRecordingInfo.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 recording = new Recording(Configuration.getConfiguration("profile"));
    recording.setDestination(Paths.get(".", "my.jfr"));
    recording.setDumpOnExit(true);
    recording.setDuration(Duration.ofSeconds(60));
    recording.setMaxAge(Duration.ofHours(1));
    recording.setMaxSize(123456789);
    recording.setName("myName");
    recording.enable("java.exception_throw").with("threashold", "2 s");
    recording.setToDisk(true);

    recording.start();
    CommonHelper.verifyRecordingState(recording, RecordingState.RUNNING); // Wait until running

    FlightRecorderMXBean bean = JmxHelper.getFlighteRecorderMXBean();
    RecordingInfo info = JmxHelper.verifyExists(recording.getId(), bean.getRecordings());

    System.out.println(JmxHelper.asString(recording));
    System.out.println(JmxHelper.asString(info));
    JmxHelper.verifyEquals(info, recording);

    recording.stop();
    recording.close();
}
 
Example 12
Source File: TestDestWithDuration.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 {
    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 13
Source File: TestStateDuration.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 {
    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 14
Source File: TestTimeDuration.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 {
    Recording r = new Recording();
    final Duration duration = Duration.ofMillis(30000);

    r.setDuration(duration);
    Asserts.assertNull(r.getStartTime(), "getStartTime() not null before start");
    Asserts.assertNull(r.getStopTime(), "getStopTime() not null before start");

    final Instant beforeStart = Instant.now();
    r.start();
    final Instant afterStart = Instant.now();

    Asserts.assertNotNull(r.getStartTime(), "getStartTime() null after start()");
    Asserts.assertGreaterThanOrEqual(r.getStartTime(), beforeStart, "getStartTime() < beforeStart");
    Asserts.assertLessThanOrEqual(r.getStartTime(), afterStart, "getStartTime() > afterStart");

    Asserts.assertNotNull(r.getStopTime(), "getStopTime() null after start with duration");
    Asserts.assertGreaterThanOrEqual(r.getStopTime(), beforeStart.plus(duration), "getStopTime() < beforeStart + duration");
    Asserts.assertLessThanOrEqual(r.getStopTime(), afterStart.plus(duration), "getStopTime() > afterStart + duration");

    r.close();
}
 
Example 15
Source File: TestDuration.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 {
    final Duration duration = Duration.ofSeconds(1);
    Recording r = new Recording();
    r.setDuration(duration);
    Asserts.assertEquals(duration, r.getDuration(), "Wrong get/set duration");

    r.start();
    Instant afterStart = Instant.now();
    CommonHelper.waitForRecordingState(r, RecordingState.STOPPED);

    Instant afterStop = Instant.now();
    Asserts.assertLessThanOrEqual(r.getStopTime(), afterStop, "getStopTime() > afterStop");
    long durationMillis = Duration.between(afterStart, r.getStopTime()).toMillis();

    // Performance of test servers varies too much to make a strict check of actual duration.
    // We only check that recording stops before timeout of 20 seconds.
    System.out.printf("Recording stopped after %d ms, expected above 1000 ms%n", durationMillis);
    r.close();
}
 
Example 16
Source File: TestRecordingBase.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void testSetGetDuration() throws Throwable {
    Recording r = new Recording();
    final Duration duration = Duration.ofSeconds(60).plusMillis(50);
    r.setDuration(duration);
    assertEquals(duration, r.getDuration(), "Wrong set/get duration");
    r.close();
}
 
Example 17
Source File: TestRecordingBase.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void testSetGetDuration() throws Throwable {
    Recording r = new Recording();
    final Duration duration = Duration.ofSeconds(60).plusMillis(50);
    r.setDuration(duration);
    assertEquals(duration, r.getDuration(), "Wrong set/get duration");
    r.close();
}
 
Example 18
Source File: TestRecordingBase.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void testSetGetDuration() throws Throwable {
    Recording r = new Recording();
    final Duration duration = Duration.ofSeconds(60).plusMillis(50);
    r.setDuration(duration);
    assertEquals(duration, r.getDuration(), "Wrong set/get duration");
    r.close();
}
 
Example 19
Source File: TestActiveRecordingEvent.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private static void testWithPath(Path path) throws Throwable {
    Recording recording = new Recording();
    recording.enable(ACTIVE_RECORDING_EVENT_NAME);

    recording.setDuration(REC_DURATION);
    recording.setMaxSize(MAX_SIZE);
    recording.setMaxAge(MAX_AGE);
    recording.setName(REC_NAME);
    if (path != null) {
        recording.setToDisk(true);
        recording.setDestination(path);
    }

    long tsBeforeStart = Instant.now().toEpochMilli();
    recording.start();
    recording.stop();
    long tsAfterStop = Instant.now().toEpochMilli();

    List<RecordedEvent> events = Events.fromRecording(recording);

    Events.hasEvents(events);
    RecordedEvent ev = events.get(0);

    // Duration must be kept in milliseconds
    assertEquals(REC_DURATION.toMillis(), ev.getValue("recordingDuration"));

    assertEquals(MAX_SIZE, ev.getValue("maxSize"));

    // maxAge must be kept in milliseconds
    assertEquals(MAX_AGE.toMillis(), ev.getValue("maxAge"));

    EventType evType = ev.getEventType();
    ValueDescriptor durationField = evType.getField("recordingDuration");
    assertEquals(durationField.getAnnotation(Timespan.class).value(), Timespan.MILLISECONDS);

    if (path == null) {
        assertNull(ev.getValue("destination"));
    } else {
        assertEquals(path.toAbsolutePath().toString(), ev.getValue("destination").toString());
    }

    ValueDescriptor recordingStartField = evType.getField("recordingStart");
    assertEquals(recordingStartField.getAnnotation(Timestamp.class).value(), Timestamp.MILLISECONDS_SINCE_EPOCH);

    long tsRecordingStart = ev.getValue("recordingStart");
    assertTrue(tsBeforeStart <= tsRecordingStart);
    assertTrue(tsAfterStop >= tsRecordingStart);

    assertEquals(recording.getId(), ev.getValue("id"));

    ValueDescriptor maxAgeField = evType.getField("maxAge");
    assertEquals(maxAgeField.getAnnotation(Timespan.class).value(), Timespan.MILLISECONDS);
}
 
Example 20
Source File: TestActiveRecordingEvent.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private static void testWithPath(Path path) throws Throwable {
    Recording recording = new Recording();
    recording.enable(ACTIVE_RECORDING_EVENT_NAME);

    recording.setDuration(REC_DURATION);
    recording.setMaxSize(MAX_SIZE);
    recording.setMaxAge(MAX_AGE);
    recording.setName(REC_NAME);
    if (path != null) {
        recording.setToDisk(true);
        recording.setDestination(path);
    }

    long tsBeforeStart = Instant.now().toEpochMilli();
    recording.start();
    recording.stop();
    long tsAfterStop = Instant.now().toEpochMilli();

    List<RecordedEvent> events = Events.fromRecording(recording);

    Events.hasEvents(events);
    RecordedEvent ev = events.get(0);

    // Duration must be kept in milliseconds
    assertEquals(REC_DURATION.toMillis(), ev.getValue("recordingDuration"));

    assertEquals(MAX_SIZE, ev.getValue("maxSize"));

    // maxAge must be kept in milliseconds
    assertEquals(MAX_AGE.toMillis(), ev.getValue("maxAge"));

    EventType evType = ev.getEventType();
    ValueDescriptor durationField = evType.getField("recordingDuration");
    assertEquals(durationField.getAnnotation(Timespan.class).value(), Timespan.MILLISECONDS);

    if (path == null) {
        assertNull(ev.getValue("destination"));
    } else {
        assertEquals(path.toAbsolutePath().toString(), ev.getValue("destination").toString());
    }

    ValueDescriptor recordingStartField = evType.getField("recordingStart");
    assertEquals(recordingStartField.getAnnotation(Timestamp.class).value(), Timestamp.MILLISECONDS_SINCE_EPOCH);

    long tsRecordingStart = ev.getValue("recordingStart");
    assertTrue(tsBeforeStart <= tsRecordingStart);
    assertTrue(tsAfterStop >= tsRecordingStart);

    assertEquals(recording.getId(), ev.getValue("id"));

    ValueDescriptor maxAgeField = evType.getField("maxAge");
    assertEquals(maxAgeField.getAnnotation(Timespan.class).value(), Timespan.MILLISECONDS);
}