Java Code Examples for jdk.management.jfr.FlightRecorderMXBean#startRecording()

The following examples show how to use jdk.management.jfr.FlightRecorderMXBean#startRecording() . 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: TestCopyToRunning.java    From TencentKona-8 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 2
Source File: TestEnoughPermission.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static long testRecording(FlightRecorderMXBean bean) throws Exception {
    System.out.println("A");
    long recId = bean.newRecording();
    System.out.println("B");
    bean.setPredefinedConfiguration(recId, "profile");
    System.out.println("C");
    bean.startRecording(recId);
    System.out.println("D");
    Asserts.assertTrue(bean.getRecordings().stream().anyMatch(r -> { return r.getId() == recId; }), "recId not found");
    System.out.println("E");
    bean.stopRecording(recId);

    final Path path = Paths.get(".", "rec" + recId + ".jfr");
    bean.copyTo(recId, path.toString());
    //EventSet events = EventSet.fromFile(path);
    return recId;
}
 
Example 3
Source File: TestCopyToInvalidPath.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 {
    FlightRecorderMXBean bean = JmxHelper.getFlighteRecorderMXBean();

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

    CommonHelper.verifyException(()->{bean.copyTo(recId, null);}, "copyTo(null)", NullPointerException.class);
    CommonHelper.verifyException(()->{bean.copyTo(recId, "");}, "copyTo('')", IOException.class);

    String p = Paths.get(".", "thisdir", "doesnot", "exists").toString();
    CommonHelper.verifyException(()->{bean.copyTo(recId, p);}, "copyTo(dirNotExist)", IOException.class);

    bean.closeRecording(recId);
}
 
Example 4
Source File: TestCopyToInvalidPath.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();

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

    CommonHelper.verifyException(()->{bean.copyTo(recId, null);}, "copyTo(null)", NullPointerException.class);
    CommonHelper.verifyException(()->{bean.copyTo(recId, "");}, "copyTo('')", IOException.class);

    String p = Paths.get(".", "thisdir", "doesnot", "exists").toString();
    CommonHelper.verifyException(()->{bean.copyTo(recId, p);}, "copyTo(dirNotExist)", IOException.class);

    bean.closeRecording(recId);
}
 
Example 5
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 6
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 7
Source File: TestRecordingState.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 {
    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 8
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 9
Source File: TestCopyToReadOnlyDir.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Throwable {
    FlightRecorderMXBean bean = JmxHelper.getFlighteRecorderMXBean();

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

    Path readOnlyDir = FileHelper.createReadOnlyDir(Paths.get(".", "readOnlyDir"));
    System.out.println("readOnlyDir=" + readOnlyDir.toString());
    Asserts.assertTrue(readOnlyDir.toFile().isDirectory(), "Could not create directory. Test error");
    if (!FileHelper.isReadOnlyPath(readOnlyDir)) {
        System.out.println("Failed to create read-only dir. Maybe running as root? Skipping test");
        return;
    }

    Path file = Paths.get(readOnlyDir.toString(), "my.jfr");
    System.out.println("file=" + file.toString());
    try {
        bean.copyTo(recId, file.toString());
        Asserts.fail("Should be able to dump to read only file");
    } catch (AccessDeniedException e) {
        // ok as expected
    }

    bean.closeRecording(recId);
}
 
Example 10
Source File: TestRecordingSettings.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 {
    Map<String, String> settings = new HashMap<>();
    settings.put("java.exception_throw#enabled", "false");
    settings.put("java.exception_throw#threshold", "2 s");
    settings.put("java.exception_throw#thread", "true");
    settings.put("java.exception_throw#stackTrace", "false");
    settings.put("os.information#enabled", "true");
    settings.put("os.information#period", "400 ms");

    FlightRecorderMXBean bean = JmxHelper.getFlighteRecorderMXBean();
    long recId = bean.newRecording();
    bean.setRecordingSettings(recId, settings);

    // Verify that JMX input and output settings are equal.
    JmxHelper.verifyMapEquals(settings, JmxHelper.getFlighteRecorderMXBean().getRecordingSettings(recId));

    // Verify that settings from Java API is correct.
    Recording recording = null;
    for (Recording r :  FlightRecorder.getFlightRecorder().getRecordings()) {
        if (r.getId() == recId) {
            recording = r;
            break;
        }
    }
    Asserts.assertNotNull(recording, "No Recording with id " + recId);
    JmxHelper.verifyMapEquals(settings, recording.getSettings());

    bean.startRecording(recId);
    bean.stopRecording(recId);
    bean.closeRecording(recId);
}
 
Example 11
Source File: TestRecordingSettings.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 {
    Map<String, String> settings = new HashMap<>();
    settings.put("java.exception_throw#enabled", "false");
    settings.put("java.exception_throw#threshold", "2 s");
    settings.put("java.exception_throw#thread", "true");
    settings.put("java.exception_throw#stackTrace", "false");
    settings.put("os.information#enabled", "true");
    settings.put("os.information#period", "400 ms");

    FlightRecorderMXBean bean = JmxHelper.getFlighteRecorderMXBean();
    long recId = bean.newRecording();
    bean.setRecordingSettings(recId, settings);

    // Verify that JMX input and output settings are equal.
    JmxHelper.verifyMapEquals(settings, JmxHelper.getFlighteRecorderMXBean().getRecordingSettings(recId));

    // Verify that settings from Java API is correct.
    Recording recording = null;
    for (Recording r :  FlightRecorder.getFlightRecorder().getRecordings()) {
        if (r.getId() == recId) {
            recording = r;
            break;
        }
    }
    Asserts.assertNotNull(recording, "No Recording with id " + recId);
    JmxHelper.verifyMapEquals(settings, recording.getSettings());

    bean.startRecording(recId);
    bean.stopRecording(recId);
    bean.closeRecording(recId);
}
 
Example 12
Source File: TestStreamMultiple.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 {
    FlightRecorderMXBean bean = JmxHelper.getFlighteRecorderMXBean();

    SimpleEventHelper.createEvent(0); // No recordings

    long recIdA = bean.newRecording();

    bean.startRecording(recIdA);
    SimpleEventHelper.createEvent(1); // recA

    long recIdB = bean.newRecording();
    Asserts.assertNotEquals(recIdA, recIdB, "Recording Ids should be unique");
    bean.startRecording(recIdB);
    SimpleEventHelper.createEvent(2); // recA and recB

    bean.stopRecording(recIdA);
    SimpleEventHelper.createEvent(3); // recB

    bean.stopRecording(recIdB);
    SimpleEventHelper.createEvent(4); // No recordings

    // Check recA
    long streamIdA = bean.openStream(recIdA, null);
    List<RecordedEvent> events = JmxHelper.parseStream(streamIdA, bean);
    SimpleEventHelper.verifyContains(events, 1, 2);
    SimpleEventHelper.verifyNotContains(events, 0, 3, 4);
    bean.closeStream(streamIdA);
    // check recB
    long streamIdB = bean.openStream(recIdB, null);
    events = JmxHelper.parseStream(streamIdB, bean);
    SimpleEventHelper.verifyContains(events, 2, 3);
    SimpleEventHelper.verifyNotContains(events, 0, 1, 4);
    bean.closeStream(streamIdB);

    bean.closeRecording(recIdA);
    bean.closeRecording(recIdB);
}
 
Example 13
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 14
Source File: TestCopyToReadOnlyDir.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Throwable {
    FlightRecorderMXBean bean = JmxHelper.getFlighteRecorderMXBean();

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

    Path readOnlyDir = FileHelper.createReadOnlyDir(Paths.get(".", "readOnlyDir"));
    System.out.println("readOnlyDir=" + readOnlyDir.toString());
    Asserts.assertTrue(readOnlyDir.toFile().isDirectory(), "Could not create directory. Test error");
    if (!FileHelper.isReadOnlyPath(readOnlyDir)) {
        System.out.println("Failed to create read-only dir. Maybe running as root? Skipping test");
        return;
    }

    Path file = Paths.get(readOnlyDir.toString(), "my.jfr");
    System.out.println("file=" + file.toString());
    try {
        bean.copyTo(recId, file.toString());
        Asserts.fail("Should be able to dump to read only file");
    } catch (AccessDeniedException e) {
        // ok as expected
    }

    bean.closeRecording(recId);
}
 
Example 15
Source File: TestNotificationListener.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Throwable {
    ObjectName objectName = new ObjectName(FlightRecorderMXBean.MXBEAN_NAME);
    ManagementFactory.getPlatformMBeanServer().addNotificationListener(objectName, listener, null, null);
    FlightRecorderMXBean bean = ManagementFactory.getPlatformMXBean(FlightRecorderMXBean.class);

    long recId = bean.newRecording();
    bean.startRecording(recId);

    latch.await();
    System.out.println("Completed successfully");
}
 
Example 16
Source File: TestNotificationListener.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Throwable {
    ObjectName objectName = new ObjectName(FlightRecorderMXBean.MXBEAN_NAME);
    ManagementFactory.getPlatformMBeanServer().addNotificationListener(objectName, listener, null, null);
    FlightRecorderMXBean bean = ManagementFactory.getPlatformMXBean(FlightRecorderMXBean.class);

    long recId = bean.newRecording();
    bean.startRecording(recId);

    latch.await();
    System.out.println("Completed successfully");
}
 
Example 17
Source File: TestMultipleRecordings.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
private static void startRecording(long recId, FlightRecorderMXBean bean) throws Exception {
    JmxHelper.verifyState(recId, RecordingState.NEW, bean);
    bean.startRecording(recId);
    JmxHelper.verifyState(recId, RecordingState.RUNNING, bean);
}
 
Example 18
Source File: TestRecordingSettingsMultiple.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    Map<String, String> settingsA = new HashMap<>();
    settingsA.put("java.exception_throw#enabled", "false");
    settingsA.put("java.exception_throw#threshold", "2 s");
    settingsA.put("java.exception_throw#thread", "true");
    settingsA.put("java.exception_throw#stackTrace", "false");
    settingsA.put("os.information#enabled", "true");
    settingsA.put("os.information#period", "400 ms");

    Map<String, String> settingsB = new HashMap<>();
    settingsB.put("vm/code_sweeper/config#enabled", "true");
    settingsB.put("vm/code_sweeper/config#period", "everyChunk");
    settingsA.put("java.exception_throw#enabled", "true");
    settingsA.put("java.exception_throw#threshold", "6 m");
    settingsB.put("os.information#enabled", "true");
    settingsB.put("os.information#period", "0 ms");

    FlightRecorderMXBean bean = JmxHelper.getFlighteRecorderMXBean();
    long recIdA = bean.newRecording();
    long recIdB = bean.newRecording();
    bean.setRecordingSettings(recIdA, settingsA);
    bean.setRecordingSettings(recIdB, settingsB);

    JmxHelper.verifyMapEquals(settingsA, bean.getRecordingSettings(recIdA));
    JmxHelper.verifyMapEquals(settingsB, bean.getRecordingSettings(recIdB));
    JmxHelper.verifyMapEquals(settingsA, JmxHelper.getJavaRecording(recIdA).getSettings());
    JmxHelper.verifyMapEquals(settingsB, JmxHelper.getJavaRecording(recIdB).getSettings());

    bean.startRecording(recIdA);
    bean.startRecording(recIdB);
    JmxHelper.verifyMapEquals(settingsA, bean.getRecordingSettings(recIdA));
    JmxHelper.verifyMapEquals(settingsB, bean.getRecordingSettings(recIdB));
    JmxHelper.verifyMapEquals(settingsA, JmxHelper.getJavaRecording(recIdA).getSettings());
    JmxHelper.verifyMapEquals(settingsB, JmxHelper.getJavaRecording(recIdB).getSettings());

    bean.stopRecording(recIdA);
    bean.stopRecording(recIdB);
    JmxHelper.verifyMapEquals(settingsA, bean.getRecordingSettings(recIdA));
    JmxHelper.verifyMapEquals(settingsB, bean.getRecordingSettings(recIdB));
    JmxHelper.verifyMapEquals(settingsA, JmxHelper.getJavaRecording(recIdA).getSettings());
    JmxHelper.verifyMapEquals(settingsB, JmxHelper.getJavaRecording(recIdB).getSettings());

    bean.closeRecording(recIdA);
    bean.closeRecording(recIdB);
}
 
Example 19
Source File: TestRecordingStateInvalid.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
private static void startRecording(long recId, FlightRecorderMXBean bean) throws Exception {
    JmxHelper.verifyState(recId, RecordingState.NEW, bean);
    bean.startRecording(recId);
    JmxHelper.verifyState(recId, RecordingState.RUNNING, bean);
}
 
Example 20
Source File: TestRecordingStateInvalid.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private static void startRecording(long recId, FlightRecorderMXBean bean) throws Exception {
    JmxHelper.verifyState(recId, RecordingState.NEW, bean);
    bean.startRecording(recId);
    JmxHelper.verifyState(recId, RecordingState.RUNNING, bean);
}