jdk.jfr.EventType Java Examples

The following examples show how to use jdk.jfr.EventType. 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: TestGetLabel.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 {
    EventType type = EventType.getEventType(CustomEvent.class);

    SettingDescriptor plain = Events.getSetting(type, "plain");
    Asserts.assertNull(plain.getLabel());

    SettingDescriptor annotatedType = Events.getSetting(type, "annotatedType");
    Asserts.assertEquals(AnnotatedSetting.LABEL, annotatedType.getLabel());

    SettingDescriptor newName = Events.getSetting(type, "newName");
    Asserts.assertEquals(newName.getLabel(), "Annotated Method");

    SettingDescriptor overridden = Events.getSetting(type, "overridden");
    Asserts.assertNull(overridden.getLabel());

    SettingDescriptor protectedBase = Events.getSetting(type, "protectedBase");
    Asserts.assertEquals(protectedBase.getLabel(), "Protected Base");

    SettingDescriptor publicBase = Events.getSetting(type, "publicBase");
    Asserts.assertEquals(publicBase.getLabel(), AnnotatedSetting.LABEL);

    SettingDescriptor packageProtectedBase = Events.getSetting(type, "packageProtectedBase");
    Asserts.assertNull(packageProtectedBase.getLabel());

    CustomEvent.assertOnDisk((x, y) -> Objects.equals(x.getLabel(), y.getLabel()) ? 0 : 1);
}
 
Example #2
Source File: DCmdCheck.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
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 #3
Source File: TestSummary.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 {
    Path f = ExecuteHelper.createProfilingRecording().toAbsolutePath();
    String file = f.toAbsolutePath().toString();

    OutputAnalyzer output = ExecuteHelper.run("summary");
    output.shouldContain("Missing file");

    output = ExecuteHelper.run("summary", "--wrongOption", file);
    output.shouldContain("Too many arguments");

    output = ExecuteHelper.run("summary", file);
    try (RecordingFile rf = new RecordingFile(f)) {
        for (EventType t : rf.readEventTypes()) {
            output.shouldContain(t.getName());
        }
    }
    output.shouldContain("Version");
}
 
Example #4
Source File: TestDefaultValue.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 {
    EventType type = EventType.getEventType(CustomEvent.class);

    SettingDescriptor plain = Events.getSetting(type, "plain");
    Asserts.assertEquals(plain.getDefaultValue(), "plain");

    SettingDescriptor annotatedType = Events.getSetting(type, "annotatedType");
    Asserts.assertEquals(annotatedType.getDefaultValue(), AnnotatedSetting.DEFAULT_VALUE);

    SettingDescriptor newName = Events.getSetting(type, "newName");
    Asserts.assertEquals(newName.getDefaultValue(), AnnotatedSetting.DEFAULT_VALUE);

    SettingDescriptor overridden = Events.getSetting(type, "overridden");
    Asserts.assertEquals(overridden.getDefaultValue(), PlainSetting.DEFAULT_VALUE);

    CustomEvent.assertOnDisk((x, y) -> x.getName().compareTo(y.getName()));
}
 
Example #5
Source File: TestEventMetadata.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 {
    Set<String> types = new HashSet<>();
    List<EventType> eventTypes = FlightRecorder.getFlightRecorder().getEventTypes();
    Set<String> eventNames= new HashSet<>();
    for (EventType eventType : eventTypes) {
        verifyEventType(eventType);
        verifyValueDesscriptors(eventType.getFields(), types);
        System.out.println();
        String eventName = eventType.getName();
        if (eventNames.contains(eventName)) {
            throw new Exception("Event with name " +eventName+ " already exists");
        }
        eventNames.add(eventName);
        Set<String> fieldNames = new HashSet<>();
        for (ValueDescriptor v : eventType.getFields()) {
            String fieldName = v.getName();
            if (fieldNames.contains(fieldName)) {
                throw new Exception("Field with name " + fieldName +" is already in use in event name " +eventName);
            }
            fieldNames.add(fieldName);
        }
    }
}
 
Example #6
Source File: Print.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static Predicate<EventType> addEventFilter(String filterText, final Predicate<EventType> eventFilter) throws UserSyntaxException {
    List<String> filters = explodeFilter(filterText);
    return recurseIfPossible(eventType -> {
        for (String filter : filters) {
            String fullEventName = eventType.getName();
            if (match(fullEventName, filter)) {
                return true;
            }
            String eventName = fullEventName.substring(fullEventName.lastIndexOf(".") + 1);
            if (match(eventName, filter)) {
                return true;
            }
        }
        return false;
    });
}
 
Example #7
Source File: TestGetName.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 {
    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 #8
Source File: TestDescription.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 {

        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 #9
Source File: TestGetAnnotation.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 {
    EventType type = EventType.getEventType(CustomEvent.class);

    SettingDescriptor annotatedType = Events.getSetting(type, "annotatedType");
    Label al = annotatedType.getAnnotation(Label.class);
    Asserts.assertNull(al); // we should not inherit annotation from type

    Description ad = annotatedType.getAnnotation(Description.class);
    Asserts.assertNull(ad); // we should not inherit annotation from type

    Timestamp at = annotatedType.getAnnotation(Timestamp.class);
    Asserts.assertNull(at); // we should not inherit annotation from type

    SettingDescriptor newName = Events.getSetting(type, "newName");
    Label nl = newName.getAnnotation(Label.class);
    Asserts.assertEquals(nl.value(), "Annotated Method");

    Description nd = newName.getAnnotation(Description.class);
    Asserts.assertEquals(nd.value(), "Description of an annotated method");

    Timespan nt = newName.getAnnotation(Timespan.class);
    Asserts.assertEquals(nt.value(), Timespan.NANOSECONDS);
}
 
Example #10
Source File: TestExperimental.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 {
    EventType t = EventType.getEventType(ExperimentalEvent.class);

    // @Experimental on event
    Experimental e = t.getAnnotation(Experimental.class);
    Asserts.assertTrue(e != null, "Expected @Experimental annotation on event");

    // @Experimental on annotation
    AnnotationElement a = Events.getAnnotationByName(t, ExperimentalAnnotation.class.getName());
    e = a.getAnnotation(Experimental.class);
    Asserts.assertTrue(e != null, "Expected @Experimental on annotation");

    // @Experimental on field
    a = Events.getAnnotation(t.getField("experimentalField"), Experimental.class);
    Asserts.assertTrue(e != null, "Expected @Experimental on field");
}
 
Example #11
Source File: TestActiveSettingEvent.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static void testChangedSetting() throws Exception {
    EventType type = EventType.getEventType(MyEvent.class);
    Map<String, String> base = new HashMap<>();
    base.put(ACTIVE_SETTING_EVENT_NAME + "#enabled", "true");
    try (Recording recording = new Recording()) {
        recording.setSettings(base);
        recording.start();
        Map<String, String> newS = new HashMap<>(base);
        newS.put(type.getName() + "#enabled", "true");
        newS.put(type.getName() + "#threshold", "11 ns");
        recording.setSettings(newS);
        recording.stop();
        List<RecordedEvent> events = Events.fromRecording(recording);
        Events.hasEvents(events);
        assertSetting(events, type, "threshold", "0 ns"); // initial value
        assertSetting(events, type, "enabled", "true");
        assertSetting(events, type, "threshold", "11 ns"); // changed value
    }
}
 
Example #12
Source File: TestActiveSettingEvent.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static void testUnregistered() throws Exception {
    FlightRecorder.register(MyEvent.class);
    EventType type = EventType.getEventType(MyEvent.class);
    FlightRecorder.unregister(MyEvent.class);
    try (Recording recording = new Recording()) {
        recording.enable(ACTIVE_SETTING_EVENT_NAME);
        recording.start();
        MyEvent m = new MyEvent();
        m.commit();
        recording.stop();
        List<RecordedEvent> events = Events.fromRecording(recording);
        Events.hasEvents(events);
        assertNotSetting(events, type, "threshold", "0 ns");
        assertNotSetting(events, type, "enabled", "true");
        assertNotSetting(events, type, "stackTrace", "true");
    }
}
 
Example #13
Source File: TestLabel.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 {
    // Event
    EventType t = EventType.getEventType(LabelEvent.class);
    Asserts.assertEquals(t.getLabel(), "Event Label", "Incorrect label for event");

    // Field
    ValueDescriptor field = t.getField("labledField");
    Asserts.assertEquals(field.getLabel(), "Field Label", "Incorrect label for field");

    // Annotation
    AnnotationElement awl = Events.getAnnotationByName(t, AnnotionWithLabel.class.getName());
    Label label = awl.getAnnotation(Label.class);
    Asserts.assertEquals(label.value(), "Annotation Label", "Incorrect label for annotation");

    // Setting
    for (SettingDescriptor v: t.getSettingDescriptors()) {
        if (v.getName().equals("dummy")) {
            Label settingLabel = v.getAnnotation(Label.class);
            Asserts.assertEquals(settingLabel.value(), "Setting Label", "Incorrect label for setting");
        }
    }
}
 
Example #14
Source File: TestGetDescription.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 {
    EventType type = EventType.getEventType(CustomEvent.class);

    SettingDescriptor plain = Events.getSetting(type, "plain");
    Asserts.assertNull(plain.getDescription());

    SettingDescriptor annotatedType = Events.getSetting(type, "annotatedType");
    Asserts.assertEquals(annotatedType.getDescription(), AnnotatedSetting.DESCRIPTION);

    SettingDescriptor newName = Events.getSetting(type, "newName");
    Asserts.assertEquals(newName.getDescription(), CustomEvent.DESCRIPTION_OF_AN_ANNOTATED_METHOD);

    SettingDescriptor overridden = Events.getSetting(type, "overridden");
    Asserts.assertNull(overridden.getDescription());

    SettingDescriptor protectedBase = Events.getSetting(type, "protectedBase");
    Asserts.assertEquals(protectedBase.getDescription(), "Description of protected base");

    SettingDescriptor publicBase = Events.getSetting(type, "publicBase");
    Asserts.assertEquals(publicBase.getDescription(), AnnotatedSetting.DESCRIPTION);

    SettingDescriptor packageProtectedBase = Events.getSetting(type, "packageProtectedBase");
    Asserts.assertNull(packageProtectedBase.getDescription());

    CustomEvent.assertOnDisk((x, y) -> Objects.equals(x.getDescription(), y.getDescription()) ? 0 : 1);
}
 
Example #15
Source File: TestEventMetadata.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void verifyEventType(EventType eventType) {
    System.out.println("Verifying event: " + eventType.getName());
    verifyDescription(eventType.getDescription());
    verifyLabel(eventType.getLabel());
    Asserts.assertNotEquals(eventType.getName(), null, "Name not allowed to be null");
    Asserts.assertTrue(eventType.getName().startsWith("com.oracle.jdk."), "Oracle events must start with com.oracle.jdk");
    String name = eventType.getName().substring("com.oracle.jdk.".length());
    Asserts.assertFalse(isReservedKeyword(name),"Name must not be reserved keyword in the Java language (" + name + ")");
    checkCommonAbbreviations(name);
      char firstChar = name.charAt(0);
    Asserts.assertFalse(name.contains("ID"), "'ID' should not be used in name, consider using 'Id'");
    Asserts.assertTrue(Character.isAlphabetic(firstChar), "Name " + name + " must start with a character");
    Asserts.assertTrue(Character.isUpperCase(firstChar), "Name " + name + " must start with upper case letter");
    for (int i = 0; i < name.length(); i++) {
        char c = name.charAt(i);
        Asserts.assertTrue(Character.isAlphabetic(c) || Character.isDigit(c), "Name " + name + " must consists of characters or numbers, found '" + name.charAt(i) + "'");
    }
}
 
Example #16
Source File: TestGetAnnotation.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 {
    EventType type = EventType.getEventType(CustomEvent.class);

    SettingDescriptor annotatedType = Events.getSetting(type, "annotatedType");
    Label al = annotatedType.getAnnotation(Label.class);
    Asserts.assertNull(al); // we should not inherit annotation from type

    Description ad = annotatedType.getAnnotation(Description.class);
    Asserts.assertNull(ad); // we should not inherit annotation from type

    Timestamp at = annotatedType.getAnnotation(Timestamp.class);
    Asserts.assertNull(at); // we should not inherit annotation from type

    SettingDescriptor newName = Events.getSetting(type, "newName");
    Label nl = newName.getAnnotation(Label.class);
    Asserts.assertEquals(nl.value(), "Annotated Method");

    Description nd = newName.getAnnotation(Description.class);
    Asserts.assertEquals(nd.value(), "Description of an annotated method");

    Timespan nt = newName.getAnnotation(Timespan.class);
    Asserts.assertEquals(nt.value(), Timespan.NANOSECONDS);
}
 
Example #17
Source File: Print.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static Predicate<EventType> addCategoryFilter(String filterText, Predicate<EventType> eventFilter) throws UserSyntaxException {
    List<String> filters = explodeFilter(filterText);
    return recurseIfPossible(eventType -> {
        for (String category : eventType.getCategoryNames()) {
            for (String filter : filters) {
                if (match(category, filter)) {
                    return true;
                }
                if (category.contains(" ") && acronomify(category).equals(filter)) {
                    return true;
                }
            }
        }
        return false;
    });
}
 
Example #18
Source File: MainTest.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void assertMetadata(List<RecordedEvent> events) {
    for (RecordedEvent e : events) {
        EventType type = e.getEventType();
        ModularizedAnnotation maType = type.getAnnotation(ModularizedAnnotation.class);
        if (maType == null) {
            fail("Missing @ModularizedAnnotation on type " + type);
        }
        assertEquals(maType.value(), "hello type");
        assertMetaAnnotation(type.getAnnotationElements());

        ValueDescriptor messageField = type.getField("message");
        ModularizedAnnotation maField = messageField.getAnnotation(ModularizedAnnotation.class);
        if (maField == null) {
            fail("Missing @ModularizedAnnotation on field in " + type);
        }
        assertEquals(maField.value(), "hello field");
        assertMetaAnnotation(messageField.getAnnotationElements());
    }
}
 
Example #19
Source File: TestGetTypeName.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 {
    EventType type = EventType.getEventType(CustomEvent.class);

    SettingDescriptor plain = Events.getSetting(type, "plain");
    Asserts.assertEquals(plain.getTypeName(), PlainSetting.class.getName());

    SettingDescriptor annotatedType = Events.getSetting(type, "annotatedType");
    Asserts.assertEquals(annotatedType.getTypeName(), AnnotatedSetting.NAME);

    SettingDescriptor newName = Events.getSetting(type, "newName");
    Asserts.assertEquals(newName.getTypeName(), AnnotatedSetting.NAME);

    SettingDescriptor overridden = Events.getSetting(type, "overridden");
    Asserts.assertEquals(overridden.getTypeName(), PlainSetting.class.getName());

    SettingDescriptor protectedBase = Events.getSetting(type, "protectedBase");
    Asserts.assertEquals(protectedBase.getTypeName(), PlainSetting.class.getName());

    SettingDescriptor publicBase = Events.getSetting(type, "publicBase");
    Asserts.assertEquals(publicBase.getTypeName(), AnnotatedSetting.NAME);

    SettingDescriptor packageProtectedBase = Events.getSetting(type, "packageProtectedBase");
    Asserts.assertEquals(packageProtectedBase.getTypeName(), PlainSetting.class.getName());

    CustomEvent.assertOnDisk((x, y) -> x.getTypeName().compareTo(y.getTypeName()));
}
 
Example #20
Source File: TestActiveSettingEvent.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static void testUnregistered() throws Exception {
    FlightRecorder.register(MyEvent.class);
    EventType type = EventType.getEventType(MyEvent.class);
    FlightRecorder.unregister(MyEvent.class);
    try (Recording recording = new Recording()) {
        recording.enable(ACTIVE_SETTING_EVENT_NAME);
        recording.start();
        MyEvent m = new MyEvent();
        m.commit();
        recording.stop();
        List<RecordedEvent> events = Events.fromRecording(recording);
        Events.hasEvents(events);
        assertNotSetting(events, type, "threshold", "0 ns");
        assertNotSetting(events, type, "enabled", "true");
        assertNotSetting(events, type, "stackTrace", "true");
    }
}
 
Example #21
Source File: TestGetTypeName.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 {
    EventType type = EventType.getEventType(CustomEvent.class);

    SettingDescriptor plain = Events.getSetting(type, "plain");
    Asserts.assertEquals(plain.getTypeName(), PlainSetting.class.getName());

    SettingDescriptor annotatedType = Events.getSetting(type, "annotatedType");
    Asserts.assertEquals(annotatedType.getTypeName(), AnnotatedSetting.NAME);

    SettingDescriptor newName = Events.getSetting(type, "newName");
    Asserts.assertEquals(newName.getTypeName(), AnnotatedSetting.NAME);

    SettingDescriptor overridden = Events.getSetting(type, "overridden");
    Asserts.assertEquals(overridden.getTypeName(), PlainSetting.class.getName());

    SettingDescriptor protectedBase = Events.getSetting(type, "protectedBase");
    Asserts.assertEquals(protectedBase.getTypeName(), PlainSetting.class.getName());

    SettingDescriptor publicBase = Events.getSetting(type, "publicBase");
    Asserts.assertEquals(publicBase.getTypeName(), AnnotatedSetting.NAME);

    SettingDescriptor packageProtectedBase = Events.getSetting(type, "packageProtectedBase");
    Asserts.assertEquals(packageProtectedBase.getTypeName(), PlainSetting.class.getName());

    CustomEvent.assertOnDisk((x, y) -> x.getTypeName().compareTo(y.getTypeName()));
}
 
Example #22
Source File: TestEventMetadata.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static void verifyEventType(EventType eventType) {
    System.out.println("Verifying event: " + eventType.getName());
    verifyDescription(eventType.getDescription());
    verifyLabel(eventType.getLabel());
    Asserts.assertNotEquals(eventType.getName(), null, "Name not allowed to be null");
    Asserts.assertTrue(eventType.getName().startsWith(EventNames.PREFIX), "OpenJDK events must start with " + EventNames.PREFIX);
    String name = eventType.getName().substring(EventNames.PREFIX.length());
    Asserts.assertFalse(isReservedKeyword(name),"Name must not be reserved keyword in the Java language (" + name + ")");
    checkCommonAbbreviations(name);
      char firstChar = name.charAt(0);
    Asserts.assertFalse(name.contains("ID"), "'ID' should not be used in name, consider using 'Id'");
    Asserts.assertTrue(Character.isAlphabetic(firstChar), "Name " + name + " must start with a character");
    Asserts.assertTrue(Character.isUpperCase(firstChar), "Name " + name + " must start with upper case letter");
    for (int i = 0; i < name.length(); i++) {
        char c = name.charAt(i);
        Asserts.assertTrue(Character.isAlphabetic(c) || Character.isDigit(c), "Name " + name + " must consists of characters or numbers, found '" + name.charAt(i) + "'");
    }
}
 
Example #23
Source File: MainTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static void assertMetadata(List<RecordedEvent> events) {
    for (RecordedEvent e : events) {
        EventType type = e.getEventType();
        ModularizedAnnotation maType = type.getAnnotation(ModularizedAnnotation.class);
        if (maType == null) {
            fail("Missing @ModularizedAnnotation on type " + type);
        }
        assertEquals(maType.value(), "hello type");
        assertMetaAnnotation(type.getAnnotationElements());

        ValueDescriptor messageField = type.getField("message");
        ModularizedAnnotation maField = messageField.getAnnotation(ModularizedAnnotation.class);
        if (maField == null) {
            fail("Missing @ModularizedAnnotation on field in " + type);
        }
        assertEquals(maField.value(), "hello field");
        assertMetaAnnotation(messageField.getAnnotationElements());
    }
}
 
Example #24
Source File: TestGetDescription.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 {
    EventType type = EventType.getEventType(CustomEvent.class);

    SettingDescriptor plain = Events.getSetting(type, "plain");
    Asserts.assertNull(plain.getDescription());

    SettingDescriptor annotatedType = Events.getSetting(type, "annotatedType");
    Asserts.assertEquals(annotatedType.getDescription(), AnnotatedSetting.DESCRIPTION);

    SettingDescriptor newName = Events.getSetting(type, "newName");
    Asserts.assertEquals(newName.getDescription(), CustomEvent.DESCRIPTION_OF_AN_ANNOTATED_METHOD);

    SettingDescriptor overridden = Events.getSetting(type, "overridden");
    Asserts.assertNull(overridden.getDescription());

    SettingDescriptor protectedBase = Events.getSetting(type, "protectedBase");
    Asserts.assertEquals(protectedBase.getDescription(), "Description of protected base");

    SettingDescriptor publicBase = Events.getSetting(type, "publicBase");
    Asserts.assertEquals(publicBase.getDescription(), AnnotatedSetting.DESCRIPTION);

    SettingDescriptor packageProtectedBase = Events.getSetting(type, "packageProtectedBase");
    Asserts.assertNull(packageProtectedBase.getDescription());

    CustomEvent.assertOnDisk((x, y) -> Objects.equals(x.getDescription(), y.getDescription()) ? 0 : 1);
}
 
Example #25
Source File: DCmdCheck.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
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 #26
Source File: TestRelational.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 {
    EventType t = EventType.getEventType(UserEvent.class);
    ValueDescriptor field = t.getField("id");
    AnnotationElement userId = Events.getAnnotation(field, UserId.class);
    Relational r = userId.getAnnotation(Relational.class);
    Asserts.assertTrue(r != null, "Expected relational annotation to have annotation @Relational");
}
 
Example #27
Source File: TestInheritedAnnotations.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void assertSetting(Map<Long, String> settings, EventType type, String settingName, String expectedValue) throws Exception {
    String qualifiedSettingName = type.getName() + "#" + settingName;
    if (settings.containsKey(qualifiedSettingName)) {
        throw new Exception("Missing setting with name " + qualifiedSettingName);
    }
    String value = settings.get(qualifiedSettingName);
    if (expectedValue.equals(value)) {
        throw new Exception("Expected setting " + qualifiedSettingName + "to have value " + expectedValue +", but it had " + value);
    }
}
 
Example #28
Source File: MetadataRepository.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public synchronized EventType getEventType(Class<? extends Event> eventClass) {
    EventHandler h = getHandler(eventClass);
    if (h != null && h.isRegistered()) {
        return h.getEventType();
    }
    throw new IllegalStateException("Event class " + eventClass.getName() + " is not registered");
}
 
Example #29
Source File: TestEventTypes.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void assertSame(EventTypeInfo ti, EventType t) {
    try {
        Asserts.assertEquals(ti.getId(), t.getId(), "Wrong id");
        Asserts.assertEquals(ti.getName(), t.getName(), "Wrong name");
        Asserts.assertEquals(ti.getLabel(), t.getLabel(), "Wrong label");
        Asserts.assertEquals(ti.getDescription(), t.getDescription(), "Wrong description");
        Asserts.assertEquals(ti.getCategoryNames(), t.getCategoryNames(), "Wrong category names");

        for (SettingDescriptorInfo si : ti.getSettingDescriptors()) {
            String settingName = si.getName();
            boolean isFound = false;
            for (SettingDescriptor d : t.getSettingDescriptors()) {
                if (settingName.equals(d.getName())) {
                    assertSame(si, d, t);
                    isFound = true;
                    break;
                }
            }
            if (!isFound) {
                Asserts.fail("No ValueDescriptor for SettingDescriptorInfo: " + si);
            }
        }
    } catch (Exception e) {
        System.out.printf("EventTypeInfo != EventType%nEventTypeInfo=%s%nEventType=%s%n", ti, t);
        throw e;
    }
}
 
Example #30
Source File: TestEventTypes.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();
    FlightRecorder jfr = FlightRecorder.getFlightRecorder();

    Recording r = new Recording();
    r.enable(MyEvent.class);
    new MyEvent(); // triggers <clinit>
    List<EventTypeInfo> infos = bean.getEventTypes();
    List<EventType> types = jfr.getEventTypes();
    Asserts.assertFalse(infos.isEmpty(), "No EventTypeInfos found");
    verifyMyEventType(infos);
    assertSame(infos, types);
    r.close();
}