jdk.management.jfr.FlightRecorderMXBean Java Examples

The following examples show how to use jdk.management.jfr.FlightRecorderMXBean. 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: TestRecordingState.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 {
    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 #2
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 #3
Source File: TestPredefinedConfiguration.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();
    List<String> configNames = new ArrayList<>();
    for (Configuration config : Configuration.getConfigurations()) {
        System.out.println("name=" + config.getName());
        configNames.add(config.getName());
        bean.setPredefinedConfiguration(recId, config.getName());

        RecordingInfo jmxRecording = JmxHelper.getJmxRecording(recId);
        JmxHelper.verifyMapEquals(jmxRecording.getSettings(), config.getSettings());
        JmxHelper.verifyMapEquals(bean.getRecordingSettings(recId), config.getSettings());
    }
    Asserts.assertTrue(configNames.contains("default"), "Missing config 'default'");
    Asserts.assertTrue(configNames.contains("profile"), "Missing config 'profile'");
}
 
Example #4
Source File: TestPredefinedConfiguration.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();
    List<String> configNames = new ArrayList<>();
    for (Configuration config : Configuration.getConfigurations()) {
        System.out.println("name=" + config.getName());
        configNames.add(config.getName());
        bean.setPredefinedConfiguration(recId, config.getName());

        RecordingInfo jmxRecording = JmxHelper.getJmxRecording(recId);
        JmxHelper.verifyMapEquals(jmxRecording.getSettings(), config.getSettings());
        JmxHelper.verifyMapEquals(bean.getRecordingSettings(recId), config.getSettings());
    }
    Asserts.assertTrue(configNames.contains("default"), "Missing config 'default'");
    Asserts.assertTrue(configNames.contains("profile"), "Missing config 'profile'");
}
 
Example #5
Source File: TestCopyTo.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);
    bean.stopRecording(recId);

    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);
    }

    bean.closeRecording(recId);
}
 
Example #6
Source File: TestNoControlPermission.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 {
    try {
        FlightRecorderMXBean bean = JmxHelper.getFlighteRecorderMXBean();

        int dummyId = 1;
        java.util.Map<String, String> dummyMap = new java.util.HashMap<>();

        verifySecurityException(() -> bean.takeSnapshot(), "takeSnapshot()");
        verifySecurityException(() -> bean.newRecording(), "newRecording()");
        verifySecurityException(() -> bean.startRecording(dummyId), "startRecording()");
        verifySecurityException(() -> bean.stopRecording(dummyId), "stopRecording()");
        verifySecurityException(() -> bean.closeRecording(dummyId), "closeRecording()");
        verifySecurityException(() -> bean.openStream(dummyId, null), "openStream()");
        verifySecurityException(() -> bean.closeStream(dummyId), "closeStream()");
        verifySecurityException(() -> bean.setConfiguration(dummyId, "dummy"), "setConfiguration()");
        verifySecurityException(() -> bean.setPredefinedConfiguration(dummyId, "dummy"), "setPredefinedConfiguration()");
        verifySecurityException(() -> bean.setRecordingSettings(dummyId, dummyMap), "setRecordingSettings()");
        verifySecurityException(() -> bean.setRecordingOptions(dummyId, dummyMap), "setRecordingOptions()");
        verifySecurityException(() -> bean.copyTo(dummyId, "."), "dumpRecording()");
    } catch (Throwable t) {
        t.printStackTrace();
        throw t;
    }
}
 
Example #7
Source File: TestCloneRepeat.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 orgId = bean.newRecording();
    bean.startRecording(orgId);

    List<Integer> ids = new ArrayList<>();
    for (int i=0; i<5; i++) {
        long cloneId = bean.cloneRecording(orgId, false);
        SimpleEventHelper.createEvent(i);
        bean.stopRecording(cloneId);
        Path path = Paths.get(".", i + "-org.jfr");
        bean.copyTo(cloneId, path.toString());
        bean.closeRecording(cloneId);
        ids.add(i);
        verifyEvents(path, ids);
    }

    bean.closeRecording(orgId);
}
 
Example #8
Source File: TestEnoughPermission.java    From dragonwell8_jdk 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(".", String.format("rec%d.jfr", recId));
    bean.copyTo(recId, path.toString());
    //EventSet events = EventSet.fromFile(path);
    return recId;
}
 
Example #9
Source File: TestCloneRepeat.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 orgId = bean.newRecording();
    bean.startRecording(orgId);

    List<Integer> ids = new ArrayList<>();
    for (int i=0; i<5; i++) {
        long cloneId = bean.cloneRecording(orgId, false);
        SimpleEventHelper.createEvent(i);
        bean.stopRecording(cloneId);
        Path path = Paths.get(".", i + "-org.jfr");
        bean.copyTo(cloneId, path.toString());
        bean.closeRecording(cloneId);
        ids.add(i);
        verifyEvents(path, ids);
    }

    bean.closeRecording(orgId);
}
 
Example #10
Source File: TestSnapshot.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void testStopped() throws IOException {
    try (Recording r = new Recording()) {
        r.enable(SimpleEvent.class);
        r.start();
        SimpleEvent se = new SimpleEvent();
        se.commit();
        r.stop();

        try (Recording snapshot = FlightRecorder.getFlightRecorder().takeSnapshot()) {
            r.close();
            FlightRecorderMXBean mxBean = JmxHelper.getFlighteRecorderMXBean();
            List<RecordingInfo> recs = mxBean.getRecordings();
            JmxHelper.verifyEquals(recs.get(0), snapshot);
        }
    }
}
 
Example #11
Source File: TestMultipleRecordings.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();
    System.out.println("bean.class=" + bean.getClass().getName());

    // Start recA
    long recIdA = createRecording(bean);
    startRecording(recIdA, bean);

    // Start recB
    long recIdB = createRecording(bean);
    startRecording(recIdB, bean);

    // Stop and destroy recA
    stopRecording(recIdA, bean);
    destroyRecording(recIdA, bean);

    // Start, stop and destroy recC
    long recIdC = createRecording(bean);
    startRecording(recIdC, bean);
    stopRecording(recIdC, bean);
    destroyRecording(recIdC, bean);

    // Stop and destroy recB
    stopRecording(recIdB, bean);
    destroyRecording(recIdB, bean);
}
 
Example #12
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 #13
Source File: FlightRecorderMXBeanProvider.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static FlightRecorderMXBean getFlightRecorderMXBean() {
    FlightRecorderMXBean bean = flightRecorderMXBean;
    if (bean == null) {
        SettingDescriptorInfo.from(null); // Sets flightRecorderMXBeanFactory under <clinit> lock
        synchronized (flightRecorderMXBeanFactory) {
            bean = flightRecorderMXBean;
            if (bean != null) {
                return bean;
            }
            try {
                bean = flightRecorderMXBean = flightRecorderMXBeanFactory.call();
            } catch (Exception e) {
                ManagementSupport.logError("Could not create Flight Recorder "
                        + "instance for MBeanServer. " + e.getMessage());
            }
        }
    }
    return bean;
}
 
Example #14
Source File: TestRecordingStateInvalid.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 = createRecording(bean);
    verifyIllegalState(()->{ bean.stopRecording(recId); }, "Stop not started");

    startRecording(recId, bean);
    verifyIllegalState(()->{ bean.startRecording(recId); }, "Start already started");

    stopRecording(recId, bean);
    verifyIllegalState(()->{ bean.startRecording(recId); }, "Start already stopped");
    verifyIllegalState(()->{ bean.stopRecording(recId); }, "Stop already stopped");

    destroyRecording(recId, bean);
    verifyIllegalArg(()->{ bean.startRecording(recId); }, "Start already destroyed");
    verifyIllegalArg(()->{ bean.stopRecording(recId); }, "Stop already destroyed");

}
 
Example #15
Source File: TestStartRecording.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);

    // TODO: Remove debug logs
    List<ConfigurationInfo> configs = bean.getConfigurations();
    for (ConfigurationInfo config : configs) {
        System.out.println("config=" + config.toString());
    }
    Map<String, String> settings = bean.getRecordingSettings(recId);
    for (String key : settings.keySet()) {
        System.out.println("setting: " + key + "=" + settings.get(key));
    }
    List<EventTypeInfo> types = bean.getEventTypes();
    for (EventTypeInfo type : types) {
        System.out.println("type=" + type.getName());
    }
    //////////////////////

    bean.stopRecording(recId);
    bean.closeRecording(recId);
}
 
Example #16
Source File: TestMultipleRecordings.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();
    System.out.println("bean.class=" + bean.getClass().getName());

    // Start recA
    long recIdA = createRecording(bean);
    startRecording(recIdA, bean);

    // Start recB
    long recIdB = createRecording(bean);
    startRecording(recIdB, bean);

    // Stop and destroy recA
    stopRecording(recIdA, bean);
    destroyRecording(recIdA, bean);

    // Start, stop and destroy recC
    long recIdC = createRecording(bean);
    startRecording(recIdC, bean);
    stopRecording(recIdC, bean);
    destroyRecording(recIdC, bean);

    // Stop and destroy recB
    stopRecording(recIdB, bean);
    destroyRecording(recIdB, bean);
}
 
Example #17
Source File: TestCloneRepeat.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 orgId = bean.newRecording();
    bean.startRecording(orgId);

    List<Integer> ids = new ArrayList<>();
    for (int i=0; i<5; i++) {
        long cloneId = bean.cloneRecording(orgId, false);
        SimpleEventHelper.createEvent(i);
        bean.stopRecording(cloneId);
        Path path = Paths.get(".", i + "-org.jfr");
        bean.copyTo(cloneId, path.toString());
        bean.closeRecording(cloneId);
        ids.add(i);
        verifyEvents(path, ids);
    }

    bean.closeRecording(orgId);
}
 
Example #18
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 #19
Source File: TestCopyTo.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);
    bean.stopRecording(recId);

    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);
    }

    bean.closeRecording(recId);
}
 
Example #20
Source File: TestRecordingStateInvalid.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 = createRecording(bean);
    verifyIllegalState(()->{ bean.stopRecording(recId); }, "Stop not started");

    startRecording(recId, bean);
    verifyIllegalState(()->{ bean.startRecording(recId); }, "Start already started");

    stopRecording(recId, bean);
    verifyIllegalState(()->{ bean.startRecording(recId); }, "Start already stopped");
    verifyIllegalState(()->{ bean.stopRecording(recId); }, "Stop already stopped");

    destroyRecording(recId, bean);
    verifyIllegalArg(()->{ bean.startRecording(recId); }, "Start already destroyed");
    verifyIllegalArg(()->{ bean.stopRecording(recId); }, "Stop already destroyed");

}
 
Example #21
Source File: TestNoControlPermission.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 {
    try {
        FlightRecorderMXBean bean = JmxHelper.getFlighteRecorderMXBean();

        int dummyId = 1;
        java.util.Map<String, String> dummyMap = new java.util.HashMap<>();

        verifySecurityException(() -> bean.takeSnapshot(), "takeSnapshot()");
        verifySecurityException(() -> bean.newRecording(), "newRecording()");
        verifySecurityException(() -> bean.startRecording(dummyId), "startRecording()");
        verifySecurityException(() -> bean.stopRecording(dummyId), "stopRecording()");
        verifySecurityException(() -> bean.closeRecording(dummyId), "closeRecording()");
        verifySecurityException(() -> bean.openStream(dummyId, null), "openStream()");
        verifySecurityException(() -> bean.closeStream(dummyId), "closeStream()");
        verifySecurityException(() -> bean.setConfiguration(dummyId, "dummy"), "setConfiguration()");
        verifySecurityException(() -> bean.setPredefinedConfiguration(dummyId, "dummy"), "setPredefinedConfiguration()");
        verifySecurityException(() -> bean.setRecordingSettings(dummyId, dummyMap), "setRecordingSettings()");
        verifySecurityException(() -> bean.setRecordingOptions(dummyId, dummyMap), "setRecordingOptions()");
        verifySecurityException(() -> bean.copyTo(dummyId, "."), "dumpRecording()");
    } catch (Throwable t) {
        t.printStackTrace();
        throw t;
    }
}
 
Example #22
Source File: TestNotificationListenerPermission.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 {
    try {
        System.getProperty("user.name");
        Asserts.fail("Didn't get security exception. Test not configured propertly?");
    } catch (SecurityException se) {
        // as expected
    }
    FlightRecorderMXBean bean = JmxHelper.getFlighteRecorderMXBean();
    TestListener testListener = new TestListener();
    ManagementFactory.getPlatformMBeanServer().addNotificationListener(new ObjectName(FlightRecorderMXBean.MXBEAN_NAME), testListener, null, null);
    long id = bean.newRecording();
    bean.startRecording(id);
    testListener.awaitNotication();
    Asserts.assertTrue(gotSecurityException, "Should not get elevated privileges in notification handler!");
    bean.stopRecording(id);
    bean.closeRecording(id);
}
 
Example #23
Source File: TestNoControlPermission.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 {
    try {
        FlightRecorderMXBean bean = JmxHelper.getFlighteRecorderMXBean();

        int dummyId = 1;
        java.util.Map<String, String> dummyMap = new java.util.HashMap<>();

        verifySecurityException(() -> bean.takeSnapshot(), "takeSnapshot()");
        verifySecurityException(() -> bean.newRecording(), "newRecording()");
        verifySecurityException(() -> bean.startRecording(dummyId), "startRecording()");
        verifySecurityException(() -> bean.stopRecording(dummyId), "stopRecording()");
        verifySecurityException(() -> bean.closeRecording(dummyId), "closeRecording()");
        verifySecurityException(() -> bean.openStream(dummyId, null), "openStream()");
        verifySecurityException(() -> bean.closeStream(dummyId), "closeStream()");
        verifySecurityException(() -> bean.setConfiguration(dummyId, "dummy"), "setConfiguration()");
        verifySecurityException(() -> bean.setPredefinedConfiguration(dummyId, "dummy"), "setPredefinedConfiguration()");
        verifySecurityException(() -> bean.setRecordingSettings(dummyId, dummyMap), "setRecordingSettings()");
        verifySecurityException(() -> bean.setRecordingOptions(dummyId, dummyMap), "setRecordingOptions()");
        verifySecurityException(() -> bean.copyTo(dummyId, "."), "dumpRecording()");
    } catch (Throwable t) {
        t.printStackTrace();
        throw t;
    }
}
 
Example #24
Source File: TestNotificationListenerPermission.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 {
    try {
        System.getProperty("user.name");
        Asserts.fail("Didn't get security exception. Test not configured propertly?");
    } catch (SecurityException se) {
        // as expected
    }
    FlightRecorderMXBean bean = JmxHelper.getFlighteRecorderMXBean();
    TestListener testListener = new TestListener();
    ManagementFactory.getPlatformMBeanServer().addNotificationListener(new ObjectName(FlightRecorderMXBean.MXBEAN_NAME), testListener, null, null);
    long id = bean.newRecording();
    bean.startRecording(id);
    testListener.awaitNotication();
    Asserts.assertTrue(gotSecurityException, "Should not get elevated privileges in notification handler!");
    bean.stopRecording(id);
    bean.closeRecording(id);
}
 
Example #25
Source File: TestStartRecording.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);

    // TODO: Remove debug logs
    List<ConfigurationInfo> configs = bean.getConfigurations();
    for (ConfigurationInfo config : configs) {
        System.out.println("config=" + config.toString());
    }
    Map<String, String> settings = bean.getRecordingSettings(recId);
    for (String key : settings.keySet()) {
        System.out.println("setting: " + key + "=" + settings.get(key));
    }
    List<EventTypeInfo> types = bean.getEventTypes();
    for (EventTypeInfo type : types) {
        System.out.println("type=" + type.getName());
    }
    //////////////////////

    bean.stopRecording(recId);
    bean.closeRecording(recId);
}
 
Example #26
Source File: TestCopyToInvalidPath.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 {
    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 #27
Source File: TestStream.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void verifyStream(FlightRecorderMXBean bean, long recId, Map<String, String> options) throws IOException, Exception {
    long streamId = bean.openStream(recId, options);

    List<RecordedEvent> events = JmxHelper.parseStream(streamId, bean);
    SimpleEventHelper.verifyContains(events, 1);
    SimpleEventHelper.verifyNotContains(events, 0, 2);
    bean.closeStream(streamId);
}
 
Example #28
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 #29
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 #30
Source File: TestGetRecordings.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();

    List<RecordingInfo> preCreateRecordings = bean.getRecordings();
    long recId = bean.newRecording();
    JmxHelper.verifyNotExists(recId, preCreateRecordings);
    bean.closeRecording(recId);
    JmxHelper.verifyNotExists(recId, bean.getRecordings());
}