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

The following examples show how to use jdk.management.jfr.FlightRecorderMXBean#setRecordingSettings() . 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: 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 2
Source File: TestRecordingSettingsInvalid.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(null, "true");
    settings.put("java.exception_throw#stackTrace", null);
    settings.put("java.exception_throw#threshold", "not-a-number");
    settings.put("os.information#period", "4 x");

    // TODO: No exception for these settings. Not sure how much validation can be done on settings.
    //settings.put("java.exception_throw#enabled", "maybe");
    //settings.put("os.information#period", "-4 s");
    //settings.put("java.exception_throw#thread", "");
    //settings.put("", "true");
    //settings.put("os.information#what", "4 ms");
    //settings.put("#", "4 what");
    //settings.put("java.exception_throw#", "true");
    //settings.put("java.exception_throwenabled", "false");

    FlightRecorderMXBean bean = JmxHelper.getFlighteRecorderMXBean();

    for (String key : settings.keySet()) {
        System.out.printf("settings: %s=%s%n", key, settings.get(key));
        Map<String, String> temp = new HashMap<String, String>();
        temp.put(key, settings.get(key));
        long recId = -1;
        try {
            recId = bean.newRecording();
            bean.setRecordingSettings(recId, temp);
            bean.startRecording(recId);
            bean.stopRecording(recId);
            Asserts.fail("Missing exception");
        } catch (Exception e) {
            System.out.println("Got expected exception: " + e.getMessage());
        } finally {
            bean.closeRecording(recId);
        }
    }
}
 
Example 3
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 4
Source File: TestRecordingSettingsInvalid.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(null, "true");
    settings.put("java.exception_throw#stackTrace", null);
    settings.put("java.exception_throw#threshold", "not-a-number");
    settings.put("os.information#period", "4 x");

    // TODO: No exception for these settings. Not sure how much validation can be done on settings.
    //settings.put("java.exception_throw#enabled", "maybe");
    //settings.put("os.information#period", "-4 s");
    //settings.put("java.exception_throw#thread", "");
    //settings.put("", "true");
    //settings.put("os.information#what", "4 ms");
    //settings.put("#", "4 what");
    //settings.put("java.exception_throw#", "true");
    //settings.put("java.exception_throwenabled", "false");

    FlightRecorderMXBean bean = JmxHelper.getFlighteRecorderMXBean();

    for (String key : settings.keySet()) {
        System.out.printf("settings: %s=%s%n", key, settings.get(key));
        Map<String, String> temp = new HashMap<String, String>();
        temp.put(key, settings.get(key));
        long recId = -1;
        try {
            recId = bean.newRecording();
            bean.setRecordingSettings(recId, temp);
            bean.startRecording(recId);
            bean.stopRecording(recId);
            Asserts.fail("Missing exception");
        } catch (Exception e) {
            System.out.println("Got expected exception: " + e.getMessage());
        } finally {
            bean.closeRecording(recId);
        }
    }
}
 
Example 5
Source File: TestRecordingSettings.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 {
    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 6
Source File: TestRecordingSettingsInvalid.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 {
    Map<String, String> settings = new HashMap<>();
    settings.put(null, "true");
    settings.put("java.exception_throw#stackTrace", null);
    settings.put("java.exception_throw#threshold", "not-a-number");
    settings.put("os.information#period", "4 x");

    // TODO: No exception for these settings. Not sure how much validation can be done on settings.
    //settings.put("java.exception_throw#enabled", "maybe");
    //settings.put("os.information#period", "-4 s");
    //settings.put("java.exception_throw#thread", "");
    //settings.put("", "true");
    //settings.put("os.information#what", "4 ms");
    //settings.put("#", "4 what");
    //settings.put("java.exception_throw#", "true");
    //settings.put("java.exception_throwenabled", "false");

    FlightRecorderMXBean bean = JmxHelper.getFlighteRecorderMXBean();

    for (String key : settings.keySet()) {
        System.out.printf("settings: %s=%s%n", key, settings.get(key));
        Map<String, String> temp = new HashMap<String, String>();
        temp.put(key, settings.get(key));
        long recId = -1;
        try {
            recId = bean.newRecording();
            bean.setRecordingSettings(recId, temp);
            bean.startRecording(recId);
            bean.stopRecording(recId);
            Asserts.fail("Missing exception");
        } catch (Exception e) {
            System.out.println("Got expected exception: " + e.getMessage());
        } finally {
            bean.closeRecording(recId);
        }
    }
}
 
Example 7
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 8
Source File: TestRecordingSettingsMultiple.java    From TencentKona-8 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 9
Source File: TestRecordingSettingsMultiple.java    From openjdk-jdk8u 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);
}