jdk.jfr.Configuration Java Examples

The following examples show how to use jdk.jfr.Configuration. 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: EventEmitterAgent.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static void agentWork() throws Exception {
    try (Recording r = new Recording(Configuration.getConfiguration("default"))) {
        r.enable(EventNames.JavaExceptionThrow);
        r.setDestination(DUMP_PATH);
        r.start();
        Thread[] threads = new Thread[THREADS];
        for (int i = 0; i < THREADS; i++) {
            threads[i] = new Thread(EventEmitterAgent::emitEvents);
            threads[i].start();
        }
        for (int i = 0; i < THREADS; i++) {
            threads[i].join();
        }
        r.stop();
    }
}
 
Example #2
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 #3
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 #4
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 #5
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 #6
Source File: TestCreateNative.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 {
    JVM jvm = JVM.getJVM();
    // Ensure that repeated failures can be handled
    for (int i = 1; i < 4; i++) {
        System.out.println("About to try failed initialization, attempt " + i + " out of 3");
        assertFailedInitialization(jvm);
        System.out.println("As expected, initialization failed.");
    }
    // Ensure that Flight Recorder can be initialized properly after failures
    Configuration defConfig = Configuration.getConfiguration("default");
    Recording r = new Recording(defConfig);
    r.start();
    r.stop();
    r.dump(Paths.get("recording.jfr"));
    r.close();
}
 
Example #7
Source File: TestCreateConfigFromPath.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void testOkConfig() throws Exception {
    Path settingsPath = DIR.resolve("settings.jfc");
    if(!settingsPath.toFile().exists()) throw new RuntimeException("File " + settingsPath.toFile().getAbsolutePath() +  " not found ");

    Configuration config = Configuration.create(settingsPath);
    Map<String, String> settings = config.getSettings();

    Asserts.assertEquals(4, settings.size(), "Settings size differes from the expected size");
    String[] keys = {"enabled", "stackTrace", "threshold", "custom"};
    String[] vals = {"true", "true", "1 ms", "5"};
    for(int i=0; i<keys.length; ++i) {
        String fullKey = "com.oracle.jdk.JavaMonitorWait#" + keys[i];
        Asserts.assertEquals(vals[i], settings.get(fullKey), "Settings value differs from the expected: " + keys[i]);
    }
    Asserts.assertEquals(null, settings.get("doesNotExists"), "Error getting on-existent setting");

    Asserts.assertEquals("Oracle", config.getProvider(), "Configuration provider differs from the expected");
    Asserts.assertEquals("TestSettings", config.getLabel(), "Configuration label differs from the expected");
    Asserts.assertEquals("SampleConfiguration", config.getDescription(), "Configuration description differs from the expected");
    Asserts.assertEquals("settings", config.getName(), "Configuration name differs from the expected");
}
 
Example #8
Source File: TestGetConfigurations.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 {
    List<Configuration> predefinedConfigs = Configuration.getConfigurations();
    Asserts.assertNotNull(predefinedConfigs, "List of predefined configs is null");
    Asserts.assertEquals(predefinedConfigs.size(), 2, "Expected exactly two predefined configurations");

    Configuration defaultConfig = findConfigByName(predefinedConfigs, DEFAULT_CONFIG_NAME);
    Asserts.assertNotNull(defaultConfig, "Config '" + DEFAULT_CONFIG_NAME + "' not found");
    Asserts.assertEquals(defaultConfig.getLabel(), DEFAULT_CONFIG_LABEL);
    Asserts.assertEquals(defaultConfig.getDescription(), DEFAULT_CONFIG_DESCRIPTION);
    Asserts.assertEquals(defaultConfig.getProvider(), DEFAULT_CONFIG_PROVIDER);

    Configuration profileConfig = findConfigByName(predefinedConfigs, PROFILE_CONFIG_NAME);
    Asserts.assertNotNull(profileConfig, "Config '" + PROFILE_CONFIG_NAME + "' not found");
    Asserts.assertEquals(profileConfig.getLabel(), PROFILE_CONFIG_LABEL);
    Asserts.assertEquals(profileConfig.getDescription(), PROFILE_CONFIG_DESCRIPTION);
    Asserts.assertEquals(profileConfig.getProvider(), PROFILE_CONFIG_PROVIDER);
}
 
Example #9
Source File: TestStartStopRecording.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 {
    Configuration defaultConfig = Configuration.getConfiguration("default");
    // Memory
    Recording inMemory = new Recording(defaultConfig);
    inMemory.setToDisk(false);

    inMemory.start();

    Path memoryFile = Files.createTempFile("memory-recording", ".jfr");
    inMemory.dump(memoryFile);
    assertValid(memoryFile, "Not a valid memory file.");
    inMemory.stop();
    inMemory.close();
    // Disk
    Recording toDisk = new Recording(defaultConfig);
    toDisk.setToDisk(true);

    toDisk.start();
    toDisk.stop();
    Path diskFile = Files.createTempFile("disk-recording", ".jfr");
    toDisk.dump(diskFile);
    assertValid(diskFile, "Not a valid disk file.");
    toDisk.close();
}
 
Example #10
Source File: TestDefaultConfigurations.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static List<String> checkSettings(Configuration config, EventType eventType, Element event) {
    List<String> errors = new ArrayList<>();

    Set<String> requiredSettings = createRequiredSettingNameSet(eventType);
    for (Element setting : getChildElements(event, "setting")) {
        String settingName = setting.getAttribute("name");
        if (requiredSettings.contains(settingName)) {
            requiredSettings.remove(settingName);
        } else {
            errors.add("Setting '" + settingName + "' for event '" + eventType.getName() + "' should not be part of confirguaration '" + config.getName()
                    + "' since it won't have an impact on the event.");
        }
    }
    for (String required : requiredSettings) {
        errors.add("Setting '" + required + "' in event '" + eventType.getName() + "' was not configured in the configuration '" + config.getName() + "'");
    }

    return errors;
}
 
Example #11
Source File: TestSplit.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void makeRecordingWithChunks(int count, Path file) throws IOException, ParseException {
    Recording main = new Recording(Configuration.getConfiguration("default"));
    // default config disable all events, so ...
    main.enable(EventNames.JVMInformation);
    main.setToDisk(true);
    main.start();
    for (int i = 0; i < count; i++) {
        Recording r = new Recording();
        r.setToDisk(true);
        r.start();
        r.stop();
        r.close();
    }
    main.stop();
    main.dump(file);
    main.close();
}
 
Example #12
Source File: TestCreateConfigFromReader.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static void testOkConfig() throws Exception {
    File settingsFile = new File(DIR, "settings.jfc");
    if(!settingsFile.exists()) throw new RuntimeException("File " + settingsFile.getAbsolutePath() +  " not found ");

        FileReader reader = new FileReader(settingsFile);

        Configuration config = Configuration.create(reader);
        Map<String, String> settings = config.getSettings();

        Asserts.assertEquals(4, settings.size(), "Settings size differes from the expected size");
        String[] keys = {"enabled", "stackTrace", "threshold", "custom"};
        String[] vals = {"true", "true", "1 ms", "5"};
        for(int i=0; i<keys.length; ++i) {
            String fullKey = EventNames.JavaMonitorWait + "#" + keys[i];
            Asserts.assertEquals(vals[i], settings.get(fullKey), "Settings value differs from the expected: " + keys[i]);
        }
        Asserts.assertEquals(null, settings.get("doesNotExists"), "Error getting on-existent setting");

        Asserts.assertEquals("Oracle", config.getProvider(), "Configuration provider differs from the expected");
        Asserts.assertEquals("TestSettings", config.getLabel(), "Configuration label differs from the expected");
        Asserts.assertEquals("SampleConfiguration", config.getDescription(), "Configuration description differs from the expected");
        Asserts.assertNull(config.getName(), "Name should be null if created from reader");
}
 
Example #13
Source File: TestCreateNative.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 {
    JVM jvm = JVM.getJVM();
    // Ensure that repeated failures can be handled
    for (int i = 1; i < 4; i++) {
        System.out.println("About to try failed initialization, attempt " + i + " out of 3");
        assertFailedInitialization(jvm);
        System.out.println("As expected, initialization failed.");
    }
    // Ensure that Flight Recorder can be initialized properly after failures
    Configuration defConfig = Configuration.getConfiguration("default");
    Recording r = new Recording(defConfig);
    r.start();
    r.stop();
    r.dump(Paths.get("recording.jfr"));
    r.close();
}
 
Example #14
Source File: TestCreateConfigFromPath.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static void testOkConfig() throws Exception {
    Path settingsPath = DIR.resolve("settings.jfc");
    if(!settingsPath.toFile().exists()) throw new RuntimeException("File " + settingsPath.toFile().getAbsolutePath() +  " not found ");

    Configuration config = Configuration.create(settingsPath);
    Map<String, String> settings = config.getSettings();

    Asserts.assertEquals(4, settings.size(), "Settings size differes from the expected size");
    String[] keys = {"enabled", "stackTrace", "threshold", "custom"};
    String[] vals = {"true", "true", "1 ms", "5"};
    for(int i=0; i<keys.length; ++i) {
        String fullKey = EventNames.JavaMonitorWait + "#" + keys[i];
        Asserts.assertEquals(vals[i], settings.get(fullKey), "Settings value differs from the expected: " + keys[i]);
    }
    Asserts.assertEquals(null, settings.get("doesNotExists"), "Error getting on-existent setting");

    Asserts.assertEquals("Oracle", config.getProvider(), "Configuration provider differs from the expected");
    Asserts.assertEquals("TestSettings", config.getLabel(), "Configuration label differs from the expected");
    Asserts.assertEquals("SampleConfiguration", config.getDescription(), "Configuration description differs from the expected");
    Asserts.assertEquals("settings", config.getName(), "Configuration name differs from the expected");
}
 
Example #15
Source File: TestDefaultConfigurations.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static List<String> checkSettings(Configuration config, EventType eventType, Element event) {
    List<String> errors = new ArrayList<>();

    Set<String> requiredSettings = createRequiredSettingNameSet(eventType);
    for (Element setting : getChildElements(event, "setting")) {
        String settingName = setting.getAttribute("name");
        if (requiredSettings.contains(settingName)) {
            requiredSettings.remove(settingName);
        } else {
            errors.add("Setting '" + settingName + "' for event '" + eventType.getName() + "' should not be part of confirguaration '" + config.getName()
                    + "' since it won't have an impact on the event.");
        }
    }
    for (String required : requiredSettings) {
        errors.add("Setting '" + required + "' in event '" + eventType.getName() + "' was not configured in the configuration '" + config.getName() + "'");
    }

    return errors;
}
 
Example #16
Source File: TestStartStopRecording.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 {
    Configuration defaultConfig = Configuration.getConfiguration("default");
    // Memory
    Recording inMemory = new Recording(defaultConfig);
    inMemory.setToDisk(false);

    inMemory.start();

    Path memoryFile = Utils.createTempFile("start-stop-memory-recording", ".jfr");
    inMemory.dump(memoryFile);
    assertValid(memoryFile, "Not a valid memory file.");
    inMemory.stop();
    inMemory.close();
    // Disk
    Recording toDisk = new Recording(defaultConfig);
    toDisk.setToDisk(true);

    toDisk.start();
    toDisk.stop();
    Path diskFile = Utils.createTempFile("start-stop-disk-recording", ".jfr");
    toDisk.dump(diskFile);
    assertValid(diskFile, "Not a valid disk file.");
    toDisk.close();
}
 
Example #17
Source File: TestCreateConfigFromReader.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static void testOkConfig() throws Exception {
    File settingsFile = new File(DIR, "settings.jfc");
    if(!settingsFile.exists()) throw new RuntimeException("File " + settingsFile.getAbsolutePath() +  " not found ");

        FileReader reader = new FileReader(settingsFile);

        Configuration config = Configuration.create(reader);
        Map<String, String> settings = config.getSettings();

        Asserts.assertEquals(4, settings.size(), "Settings size differes from the expected size");
        String[] keys = {"enabled", "stackTrace", "threshold", "custom"};
        String[] vals = {"true", "true", "1 ms", "5"};
        for(int i=0; i<keys.length; ++i) {
            String fullKey = EventNames.JavaMonitorWait + "#" + keys[i];
            Asserts.assertEquals(vals[i], settings.get(fullKey), "Settings value differs from the expected: " + keys[i]);
        }
        Asserts.assertEquals(null, settings.get("doesNotExists"), "Error getting on-existent setting");

        Asserts.assertEquals("Oracle", config.getProvider(), "Configuration provider differs from the expected");
        Asserts.assertEquals("TestSettings", config.getLabel(), "Configuration label differs from the expected");
        Asserts.assertEquals("SampleConfiguration", config.getDescription(), "Configuration description differs from the expected");
        Asserts.assertNull(config.getName(), "Name should be null if created from reader");
}
 
Example #18
Source File: TestGetConfigurations.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 {
    List<Configuration> predefinedConfigs = Configuration.getConfigurations();
    Asserts.assertNotNull(predefinedConfigs, "List of predefined configs is null");
    Asserts.assertEquals(predefinedConfigs.size(), 2, "Expected exactly two predefined configurations");

    Configuration defaultConfig = findConfigByName(predefinedConfigs, DEFAULT_CONFIG_NAME);
    Asserts.assertNotNull(defaultConfig, "Config '" + DEFAULT_CONFIG_NAME + "' not found");
    Asserts.assertEquals(defaultConfig.getLabel(), DEFAULT_CONFIG_LABEL);
    Asserts.assertEquals(defaultConfig.getDescription(), DEFAULT_CONFIG_DESCRIPTION);
    Asserts.assertEquals(defaultConfig.getProvider(), DEFAULT_CONFIG_PROVIDER);

    Configuration profileConfig = findConfigByName(predefinedConfigs, PROFILE_CONFIG_NAME);
    Asserts.assertNotNull(profileConfig, "Config '" + PROFILE_CONFIG_NAME + "' not found");
    Asserts.assertEquals(profileConfig.getLabel(), PROFILE_CONFIG_LABEL);
    Asserts.assertEquals(profileConfig.getDescription(), PROFILE_CONFIG_DESCRIPTION);
    Asserts.assertEquals(profileConfig.getProvider(), PROFILE_CONFIG_PROVIDER);
}
 
Example #19
Source File: TestCreateConfigFromPath.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static void testOkConfig() throws Exception {
    Path settingsPath = DIR.resolve("settings.jfc");
    if(!settingsPath.toFile().exists()) throw new RuntimeException("File " + settingsPath.toFile().getAbsolutePath() +  " not found ");

    Configuration config = Configuration.create(settingsPath);
    Map<String, String> settings = config.getSettings();

    Asserts.assertEquals(4, settings.size(), "Settings size differes from the expected size");
    String[] keys = {"enabled", "stackTrace", "threshold", "custom"};
    String[] vals = {"true", "true", "1 ms", "5"};
    for(int i=0; i<keys.length; ++i) {
        String fullKey = EventNames.JavaMonitorWait + "#" + keys[i];
        Asserts.assertEquals(vals[i], settings.get(fullKey), "Settings value differs from the expected: " + keys[i]);
    }
    Asserts.assertEquals(null, settings.get("doesNotExists"), "Error getting on-existent setting");

    Asserts.assertEquals("Oracle", config.getProvider(), "Configuration provider differs from the expected");
    Asserts.assertEquals("TestSettings", config.getLabel(), "Configuration label differs from the expected");
    Asserts.assertEquals("SampleConfiguration", config.getDescription(), "Configuration description differs from the expected");
    Asserts.assertEquals("settings", config.getName(), "Configuration name differs from the expected");
}
 
Example #20
Source File: TestStartStopRecording.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 {
    Configuration defaultConfig = Configuration.getConfiguration("default");
    // Memory
    Recording inMemory = new Recording(defaultConfig);
    inMemory.setToDisk(false);

    inMemory.start();

    Path memoryFile = Utils.createTempFile("start-stop-memory-recording", ".jfr");
    inMemory.dump(memoryFile);
    assertValid(memoryFile, "Not a valid memory file.");
    inMemory.stop();
    inMemory.close();
    // Disk
    Recording toDisk = new Recording(defaultConfig);
    toDisk.setToDisk(true);

    toDisk.start();
    toDisk.stop();
    Path diskFile = Utils.createTempFile("start-stop-disk-recording", ".jfr");
    toDisk.dump(diskFile);
    assertValid(diskFile, "Not a valid disk file.");
    toDisk.close();
}
 
Example #21
Source File: TestPredefinedConfiguration.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();
    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 #22
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 #23
Source File: TestDefaultConfigurations.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static List<String> checkSettings(Configuration config, EventType eventType, Element event) {
    List<String> errors = new ArrayList<>();

    Set<String> requiredSettings = createRequiredSettingNameSet(eventType);
    for (Element setting : getChildElements(event, "setting")) {
        String settingName = setting.getAttribute("name");
        if (requiredSettings.contains(settingName)) {
            requiredSettings.remove(settingName);
        } else {
            errors.add("Setting '" + settingName + "' for event '" + eventType.getName() + "' should not be part of confirguaration '" + config.getName()
                    + "' since it won't have an impact on the event.");
        }
    }
    for (String required : requiredSettings) {
        errors.add("Setting '" + required + "' in event '" + eventType.getName() + "' was not configured in the configuration '" + config.getName() + "'");
    }

    return errors;
}
 
Example #24
Source File: TestConfigurationGetContents.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 {
    List<Configuration> predefinedConfigs = Configuration.getConfigurations();

    Asserts.assertNotNull(predefinedConfigs, "List of predefined configs is null");
    Asserts.assertTrue(predefinedConfigs.size() > 0, "List of predefined configs is empty");

    for (Configuration conf : predefinedConfigs) {
        String name = conf.getName();
        System.out.println("Verifying configuration " + name);
        String fpath = JFR_DIR + name + ".jfc";
        String contents = conf.getContents();
        String fileContents = readFile(fpath);
        Asserts.assertEquals(fileContents, contents, "getContents() does not return the actual contents of the file " + fpath);
    }
}
 
Example #25
Source File: TestCreateConfigFromPath.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void testNullReader() throws Exception {
    try {
        Configuration.create((Reader)null);
        Asserts.fail("Exception was not thrown");
    } catch(NullPointerException x) {
    }
}
 
Example #26
Source File: TestGetConfigurations.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static Configuration findConfigByName(List<Configuration> configs, String name) {
    for (Configuration config : configs) {
        if (name.equals(config.getName())) {
            return config;
        }
    }
    return null;
}
 
Example #27
Source File: FlightRecorderMXBeanImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void setPredefinedConfiguration(long recording, String configurationName) throws IllegalArgumentException {
    Objects.requireNonNull(configurationName);
    MBeanUtils.checkControl();
    Recording r = getExistingRecording(recording);
    for (Configuration c : Configuration.getConfigurations()) {
        if (c.getName().equals(configurationName)) {
            r.setSettings(c.getSettings());
            return;
        }
    }
    throw new IllegalArgumentException("Could not find configuration with name " + configurationName);
}
 
Example #28
Source File: ExecuteHelper.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static Path createProfilingRecording() throws Exception {
    Path file = Utils.createTempFile("profiling-recording", ".jfr");
    // Create a recording with some data
    try (Recording r = new Recording(Configuration.getConfiguration("profile"))) {
        r.start();

        // Allocation event
        array = new Object[1000000];
        array = null;

        // Class loading event etc
        provokeClassLoading();

        // GC events
        System.gc();

        // ExecutionSample
        long t = System.currentTimeMillis();
        while (System.currentTimeMillis() - t < 50) {
            // do nothing
        }

        // Other periodic events, i.e CPU load
        Thread.sleep(1000);

        r.stop();
        r.dump(file);
    }

    return file;
}
 
Example #29
Source File: FlightRecorderMXBeanImpl.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void setPredefinedConfiguration(long recording, String configurationName) throws IllegalArgumentException {
    Objects.requireNonNull(configurationName);
    MBeanUtils.checkControl();
    Recording r = getExistingRecording(recording);
    for (Configuration c : Configuration.getConfigurations()) {
        if (c.getName().equals(configurationName)) {
            r.setSettings(c.getSettings());
            return;
        }
    }
    throw new IllegalArgumentException("Could not find configuration with name " + configurationName);
}
 
Example #30
Source File: FlightRecorderMXBeanImpl.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void setConfiguration(long recording, String configuration) throws IllegalArgumentException {
    Objects.requireNonNull(configuration);
    MBeanUtils.checkControl();
    try {
        Configuration c = Configuration.create(new StringReader(configuration));
        getExistingRecording(recording).setSettings(c.getSettings());
    } catch (IOException | ParseException e) {
        throw new IllegalArgumentException("Could not parse configuration", e);
    }
}