Java Code Examples for jdk.jfr.EventType#getSettingDescriptors()
The following examples show how to use
jdk.jfr.EventType#getSettingDescriptors() .
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: TestDescription.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { EventType t = EventType.getEventType(DescriptionEvent.class); // field description AnnotationElement aMax = Events.getAnnotation(t.getField("field"), Description.class); String d = (String) aMax.getValue("value"); Asserts.assertEquals("Field Annotation", d, "Incorrect annotation for field, got '" + d + "'"); // event description d = t.getAnnotation(Description.class).value(); Asserts.assertEquals("Event Annotation", d, "Incorrect annotation for event, got '" + d + "'"); // annotation description AnnotationElement a = Events.getAnnotationByName(t, AnnotationWithDescription.class.getName()); Description de = a.getAnnotation(Description.class); Asserts.assertEquals("Meta Annotation", de.value(), "Incorrect annotation for event, got '" + de.value() + "'"); for (SettingDescriptor v: t.getSettingDescriptors()) { if (v.getName().equals("dummy")) { Description settingDescription = v.getAnnotation(Description.class); Asserts.assertEquals(settingDescription.value(), "Setting description", "Incorrect description for setting"); } } }
Example 2
Source File: TestSettingsAvailability.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
private static void testSetting(String eventName, String... settingNames) throws Exception { for (EventType type : FlightRecorder.getFlightRecorder().getEventTypes()) { if (eventName.equals(type.getName())) { Set<String> settings = new HashSet<>(); for (SettingDescriptor sd : type.getSettingDescriptors()) { settings.add(sd.getName()); } for (String settingName : settingNames) { if (!settings.contains(settingName)) { throw new Exception("Missing setting " + settingName + " in " + eventName); } settings.remove(settingName); } if (!settings.isEmpty()) { throw new Exception("Superflous settings " + settings + " in event " + eventName); } } } }
Example 3
Source File: TestGetName.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { EventType type = EventType.getEventType(CustomEvent.class); // subclass Events.getSetting(type, "plain"); Events.getSetting(type, "annotatedType"); Events.getSetting(type, "newName"); Events.getSetting(type, "overridden"); // base class Events.getSetting(type, "overridden"); Events.getSetting(type, "protectedBase"); Events.getSetting(type, "publicBase"); Events.getSetting(type, "packageProtectedBase"); int defaultNumberOfSettings = 3; // Enabled , Stack Trace, Threshold if (type.getSettingDescriptors().size() != 8 + defaultNumberOfSettings) { for (SettingDescriptor s : type.getSettingDescriptors()) { System.out.println(s.getName()); } throw new Exception("Wrong number of settings"); } CustomEvent.assertOnDisk((x, y) -> x.getName().compareTo(y.getName())); }
Example 4
Source File: TestGetName.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { EventType type = EventType.getEventType(CustomEvent.class); // subclass Events.getSetting(type, "plain"); Events.getSetting(type, "annotatedType"); Events.getSetting(type, "newName"); Events.getSetting(type, "overridden"); // base class Events.getSetting(type, "overridden"); Events.getSetting(type, "protectedBase"); Events.getSetting(type, "publicBase"); Events.getSetting(type, "packageProtectedBase"); int defaultNumberOfSettings = 3; // Enabled , Stack Trace, Threshold if (type.getSettingDescriptors().size() != 8 + defaultNumberOfSettings) { for (SettingDescriptor s : type.getSettingDescriptors()) { System.out.println(s.getName()); } throw new Exception("Wrong number of settings"); } CustomEvent.assertOnDisk((x, y) -> x.getName().compareTo(y.getName())); }
Example 5
Source File: CustomEvent.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public static void assertOnDisk(Comparator<SettingDescriptor> c) throws Exception { EventType in = EventType.getEventType(CustomEvent.class); Path p = Paths.get("custom.jfr"); try (Recording r = new Recording()) { r.start(); r.stop(); r.dump(p); } try (RecordingFile f = new RecordingFile(p)) { for (EventType out : f.readEventTypes()) { if (out.getName().equals(CustomEvent.class.getName())) { if (out.getSettingDescriptors().size() != in.getSettingDescriptors().size()) { throw new Exception("Number of settings doesn't match"); } for (SettingDescriptor os : out.getSettingDescriptors()) { SettingDescriptor is = Events.getSetting(in, os.getName()); if (c.compare(os, is) != 0) { throw new Exception("Setting with name " + is.getName() + " doesn't match"); } } return; } } } throw new Exception("Could not event type with name " + CustomEvent.class.getName()); }
Example 6
Source File: DCmdCheck.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
private void printSetttings(Recording recording) { Map<String, String> settings = recording.getSettings(); for (EventType eventType : sortByEventPath(getFlightRecorder().getEventTypes())) { StringJoiner sj = new StringJoiner(",", "[", "]"); sj.setEmptyValue(""); for (SettingDescriptor s : eventType.getSettingDescriptors()) { String settingsPath = eventType.getName() + "#" + s.getName(); if (settings.containsKey(settingsPath)) { sj.add(s.getName() + "=" + settings.get(settingsPath)); } } String settingsText = sj.toString(); if (!settingsText.isEmpty()) { print(" %s (%s)", eventType.getLabel(), eventType.getName()); println(); println(" " + settingsText); } } }
Example 7
Source File: TestDescription.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { EventType t = EventType.getEventType(DescriptionEvent.class); // field description AnnotationElement aMax = Events.getAnnotation(t.getField("field"), Description.class); String d = (String) aMax.getValue("value"); Asserts.assertEquals("Field Annotation", d, "Incorrect annotation for field, got '" + d + "'"); // event description d = t.getAnnotation(Description.class).value(); Asserts.assertEquals("Event Annotation", d, "Incorrect annotation for event, got '" + d + "'"); // annotation description AnnotationElement a = Events.getAnnotationByName(t, AnnotationWithDescription.class.getName()); Description de = a.getAnnotation(Description.class); Asserts.assertEquals("Meta Annotation", de.value(), "Incorrect annotation for event, got '" + de.value() + "'"); for (SettingDescriptor v: t.getSettingDescriptors()) { if (v.getName().equals("dummy")) { Description settingDescription = v.getAnnotation(Description.class); Asserts.assertEquals(settingDescription.value(), "Setting description", "Incorrect description for setting"); } } }
Example 8
Source File: CustomEvent.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public static void assertOnDisk(Comparator<SettingDescriptor> c) throws Exception { EventType in = EventType.getEventType(CustomEvent.class); Path p = Paths.get("custom.jfr"); try (Recording r = new Recording()) { r.start(); r.stop(); r.dump(p); } try (RecordingFile f = new RecordingFile(p)) { for (EventType out : f.readEventTypes()) { if (out.getName().equals(CustomEvent.class.getName())) { if (out.getSettingDescriptors().size() != in.getSettingDescriptors().size()) { throw new Exception("Number of settings doesn't match"); } for (SettingDescriptor os : out.getSettingDescriptors()) { SettingDescriptor is = Events.getSetting(in, os.getName()); if (c.compare(os, is) != 0) { throw new Exception("Setting with name " + is.getName() + " doesn't match"); } } return; } } } throw new Exception("Could not event type with name " + CustomEvent.class.getName()); }
Example 9
Source File: Events.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public static SettingDescriptor getSetting(EventType type, String name) { for (SettingDescriptor s : type.getSettingDescriptors()) { if (s.getName().equals(name)) { return s; } } throw new IllegalArgumentException("Could not setting with name " + name); }
Example 10
Source File: TestDefaultConfigurations.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private static Set<String> createRequiredSettingNameSet(EventType cd) { Set<String> requiredSettings = new HashSet<>(); for (SettingDescriptor s : cd.getSettingDescriptors()) { requiredSettings.add(s.getName()); } return requiredSettings; }
Example 11
Source File: TestSettingsAvailability.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private static void testSettingPersistence() throws IOException, Exception { Map<String, EventType> inMemoryTypes = new HashMap<>(); for (EventType type : FlightRecorder.getFlightRecorder().getEventTypes()) { inMemoryTypes.put(type.getName(), type); } Path p = Paths.get("recording.jfr"); try (Recording r = new Recording()) { r.start(); r.stop(); r.dump(p); try (RecordingFile rf = new RecordingFile(p)) { for (EventType parsedType : rf.readEventTypes()) { EventType inMem = inMemoryTypes.get(parsedType.getName()); if (inMem == null) { throw new Exception("Superflous event type " + parsedType.getName() + " in recording"); } Set<String> inMemsettings = new HashSet<>(); for (SettingDescriptor sd : inMem.getSettingDescriptors()) { inMemsettings.add(sd.getName()); } for (SettingDescriptor parsedSetting : parsedType.getSettingDescriptors()) { if (!inMemsettings.contains(parsedSetting.getName())) { throw new Exception("Superflous setting " + parsedSetting.getName() + " in " + parsedType.getName()); } inMemsettings.remove(parsedSetting.getName()); } if (!inMemsettings.isEmpty()) { throw new Exception("Missing settings " + inMemsettings + " for event type " + parsedType.getName() + " in recording"); } } } } }
Example 12
Source File: EventTypeInfo.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private static List<SettingDescriptorInfo> creatingSettingDescriptorInfos(EventType eventType) { List<SettingDescriptor> settings = eventType.getSettingDescriptors(); List<SettingDescriptorInfo> settingDescriptorInfos = new ArrayList<>(settings.size()); for (SettingDescriptor s : settings) { settingDescriptorInfos.add(new SettingDescriptorInfo(s)); } return Collections.unmodifiableList(settingDescriptorInfos); }
Example 13
Source File: Events.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public static SettingDescriptor getSetting(EventType type, String name) { for (SettingDescriptor s : type.getSettingDescriptors()) { if (s.getName().equals(name)) { return s; } } throw new IllegalArgumentException("Could not setting with name " + name); }
Example 14
Source File: TestName.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private static SettingDescriptor getSetting(EventType t, String name) { for (SettingDescriptor v : t.getSettingDescriptors()) { if (v.getName().equals(name)) { return v; } } Asserts.fail("Could not find setting with name " + name); return null; }
Example 15
Source File: TestDefaultConfigurations.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
private static Set<String> createRequiredSettingNameSet(EventType cd) { Set<String> requiredSettings = new HashSet<>(); for (SettingDescriptor s : cd.getSettingDescriptors()) { requiredSettings.add(s.getName()); } return requiredSettings; }
Example 16
Source File: TestName.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
private static SettingDescriptor getSetting(EventType t, String name) { for (SettingDescriptor v : t.getSettingDescriptors()) { if (v.getName().equals(name)) { return v; } } Asserts.fail("Could not find setting with name " + name); return null; }
Example 17
Source File: TestGetSettings.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Throwable { EventType eventType = EventType.getEventType(EventWithCustomSettings.class); List<SettingDescriptor> settings = eventType.getSettingDescriptors(); Asserts.assertEquals(settings.size(), 5, "Wrong number of settings"); // test immutability try { settings.add(settings.get(0)); Asserts.fail("Should not be able to modify list returned by getSettings()"); } catch (UnsupportedOperationException uoe) { // OK, as expected } }
Example 18
Source File: TestSettingsAvailability.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
private static void testSettingPersistence() throws IOException, Exception { Map<String, EventType> inMemoryTypes = new HashMap<>(); for (EventType type : FlightRecorder.getFlightRecorder().getEventTypes()) { inMemoryTypes.put(type.getName(), type); } Path p = Paths.get("recording.jfr"); try (Recording r = new Recording()) { r.start(); r.stop(); r.dump(p); try (RecordingFile rf = new RecordingFile(p)) { for (EventType parsedType : rf.readEventTypes()) { EventType inMem = inMemoryTypes.get(parsedType.getName()); if (inMem == null) { throw new Exception("Superflous event type " + parsedType.getName() + " in recording"); } Set<String> inMemsettings = new HashSet<>(); for (SettingDescriptor sd : inMem.getSettingDescriptors()) { inMemsettings.add(sd.getName()); } for (SettingDescriptor parsedSetting : parsedType.getSettingDescriptors()) { if (!inMemsettings.contains(parsedSetting.getName())) { throw new Exception("Superflous setting " + parsedSetting.getName() + " in " + parsedType.getName()); } inMemsettings.remove(parsedSetting.getName()); } if (!inMemsettings.isEmpty()) { throw new Exception("Missing settings " + inMemsettings + " for event type " + parsedType.getName() + " in recording"); } } } } }
Example 19
Source File: TestGetSettings.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Throwable { EventType eventType = EventType.getEventType(EventWithCustomSettings.class); List<SettingDescriptor> settings = eventType.getSettingDescriptors(); Asserts.assertEquals(settings.size(), 5, "Wrong number of settings"); // test immutability try { settings.add(settings.get(0)); Asserts.fail("Should not be able to modify list returned by getSettings()"); } catch (UnsupportedOperationException uoe) { // OK, as expected } }
Example 20
Source File: EventTypeInfo.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
private static List<SettingDescriptorInfo> creatingSettingDescriptorInfos(EventType eventType) { List<SettingDescriptor> settings = eventType.getSettingDescriptors(); List<SettingDescriptorInfo> settingDescriptorInfos = new ArrayList<>(settings.size()); for (SettingDescriptor s : settings) { settingDescriptorInfos.add(new SettingDescriptorInfo(s)); } return Collections.unmodifiableList(settingDescriptorInfos); }