Java Code Examples for jdk.jfr.EventType#getField()

The following examples show how to use jdk.jfr.EventType#getField() . 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: 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 2
Source File: TestLabel.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 {
    // 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 3
Source File: TestName.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(NamedEvent.class);
    ValueDescriptor testField = t.getField("testField");
    SettingDescriptor setting = getSetting(t, "name");
    AnnotationElement a = Events.getAnnotationByName(t, "com.oracle.TestAnnotation");

    // Check that names are overridden
    Asserts.assertNotNull(testField, "Can't find expected field testField");
    Asserts.assertEquals(t.getName(), "com.oracle.TestEvent", "Incorrect name for event");
    Asserts.assertEquals(a.getTypeName(), "com.oracle.TestAnnotation", "Incorrect name for annotation");
    Asserts.assertEquals(a.getTypeName(), "com.oracle.TestAnnotation", "Incorrect name for annotation");
    Asserts.assertEquals(setting.getName(), "name", "Incorrect name for setting");

    // Check that @Name is persisted
    assertAnnotation(t.getAnnotation(Name.class), "@Name should be persisted on event");
    assertAnnotation(testField.getAnnotation(Name.class), "@Name should be persisted on field");
    assertAnnotation(a.getAnnotation(Name.class), "@Name should be persisted on annotations");
    assertAnnotation(setting.getAnnotation(Name.class), "@Name should be persisted on setting");
}
 
Example 4
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 5
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 6
Source File: TestMetadata.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 {
    EventType t = EventType.getEventType(MetadataEvent.class);
    ValueDescriptor field = t.getField("field");
    Events.hasAnnotation(field, FirstJFRAnnotation.class);
    Asserts.assertTrue(field.getAnnotation(OtherAnnotation.class) == null, "Only annotation annotated with @Metadata should exist");

    AnnotationElement a = Events.getAnnotationByName(t, FirstJFRAnnotation.class.getName());
    Asserts.assertTrue(a.getAnnotation(SecondJFRAnnotation.class) != null , "Annotations with @Metadata should be followed for indirect annotations");
}
 
Example 7
Source File: TestIsArray.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Throwable {
    EventType type = EventType.getEventType(EventWithArray.class);

    ValueDescriptor d = type.getField("myIds");

    Asserts.assertNull(d, "ValueDescriptor for int[] was not null");

    type = EventType.getEventType(EventWithoutArray.class);
    d = type.getField("myId");
    Asserts.assertFalse(d.isArray(), "isArray() was true for int");
}
 
Example 8
Source File: TestRelational.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 {
    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 9
Source File: TestMetadata.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 {
    EventType t = EventType.getEventType(MetadataEvent.class);
    ValueDescriptor field = t.getField("field");
    Events.hasAnnotation(field, FirstJFRAnnotation.class);
    Asserts.assertTrue(field.getAnnotation(OtherAnnotation.class) == null, "Only annotation annotated with @Metadata should exist");

    AnnotationElement a = Events.getAnnotationByName(t, FirstJFRAnnotation.class.getName());
    Asserts.assertTrue(a.getAnnotation(SecondJFRAnnotation.class) != null , "Annotations with @Metadata should be followed for indirect annotations");
}
 
Example 10
Source File: EventParser.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
EventParser(TimeConverter timeConverter, EventType type, Parser[] parsers) {
    this.timeConverter = timeConverter;
    this.parsers = parsers;
    this.eventType = type;
    this.hasDuration = type.getField(FIELD_DURATION) != null;
    this.valueDescriptors = type.getFields();
}
 
Example 11
Source File: TestValueDescriptorContentType.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 {
    EventType type = EventType.getEventType(AlohaEvent.class);

    // check field annotation on event value
    ValueDescriptor filter = type.getField("greeting");
    Asserts.assertEquals(filter.getContentType(), Hawaiian.class.getName());

    // check field annotation with missing content type
    ValueDescriptor missing = type.getField("missing");
    Asserts.assertEquals(missing.getContentType(), null);

    // check field annotation with annotation but not content type
    ValueDescriptor otherAnnotation = type.getField("otherAnnotation");
    Asserts.assertEquals(otherAnnotation.getContentType(), null);
}
 
Example 12
Source File: TestGetField.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Throwable {
    EventType type = EventType.getEventType(MyEvent.class);

    ValueDescriptor v = type.getField("myByte");
    Asserts.assertNotNull(v, "getFiled(myByte) was null");
    Asserts.assertEquals(v.getTypeName(), "byte", "myByte was not type byte");

    v = type.getField("myInt");
    Asserts.assertNotNull(v, "getFiled(myInt) was null");
    Asserts.assertEquals(v.getTypeName(), "int", "myInt was not type int");

    v = type.getField("myStatic");
    Asserts.assertNull(v, "got static field");

    v = type.getField("notAField");
    Asserts.assertNull(v, "got field that does not exist");

    v = type.getField("");
    Asserts.assertNull(v, "got field for empty name");

    try {
        v = type.getField(null);
        Asserts.fail("No Exception when getField(null)");
    } catch (NullPointerException e) {
        // Expected exception
    }
}
 
Example 13
Source File: TestIsArray.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 {
    EventType type = EventType.getEventType(EventWithArray.class);

    ValueDescriptor d = type.getField("myIds");

    Asserts.assertNull(d, "ValueDescriptor for int[] was not null");

    type = EventType.getEventType(EventWithoutArray.class);
    d = type.getField("myId");
    Asserts.assertFalse(d.isArray(), "isArray() was true for int");
}
 
Example 14
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 15
Source File: TestFieldAnnotations.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 {
    EventType t = EventType.getEventType(FieldAnnotationEvent.class);

    ValueDescriptor field = t.getField("memoryAmount");
    Events.hasAnnotation(field, DataAmount.class);

    field = t.getField("frequency");
    Events.hasAnnotation(field, Frequency.class);

    field = t.getField("memoryAddress");
    Events.hasAnnotation(field, MemoryAddress.class);

    field = t.getField("percentage");
    Events.hasAnnotation(field, Percentage.class);

    field = t.getField("fromThread");
    Events.hasAnnotation(field, TransitionFrom.class);

    field = t.getField("toThread");
    Events.hasAnnotation(field, TransitionTo.class);

    field = t.getField("unsigned");
    Events.hasAnnotation(field, Unsigned.class);

    field = t.getField("timespan");
    Events.assertAnnotation(field, Timespan.class, Timespan.MILLISECONDS);

    field = t.getField("timestamp");
    Events.assertAnnotation(field, Timestamp.class, Timestamp.MILLISECONDS_SINCE_EPOCH);
}
 
Example 16
Source File: TestGetField.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Throwable {
    EventType type = EventType.getEventType(MyEvent.class);

    ValueDescriptor v = type.getField("myByte");
    Asserts.assertNotNull(v, "getFiled(myByte) was null");
    Asserts.assertEquals(v.getTypeName(), "byte", "myByte was not type byte");

    v = type.getField("myInt");
    Asserts.assertNotNull(v, "getFiled(myInt) was null");
    Asserts.assertEquals(v.getTypeName(), "int", "myInt was not type int");

    v = type.getField("myStatic");
    Asserts.assertNull(v, "got static field");

    v = type.getField("notAField");
    Asserts.assertNull(v, "got field that does not exist");

    v = type.getField("");
    Asserts.assertNull(v, "got field for empty name");

    try {
        v = type.getField(null);
        Asserts.fail("No Exception when getField(null)");
    } catch (NullPointerException e) {
        // Expected exception
    }
}
 
Example 17
Source File: TestExtends.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
private static void verifyField(EventType t, String name) throws Exception {
    ValueDescriptor d = t.getField(name);
    if (d == null) {
        throw new Exception("Missing field " + name + " in event " + t.getName());
    }
}
 
Example 18
Source File: TestExtends.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private static void verifyField(EventType t, String name) throws Exception {
    ValueDescriptor d = t.getField(name);
    if (d == null) {
        throw new Exception("Missing field " + name + " in event " + t.getName());
    }
}
 
Example 19
Source File: TestActiveRecordingEvent.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private static void testWithPath(Path path) throws Throwable {
    Recording recording = new Recording();
    recording.enable(ACTIVE_RECORDING_EVENT_NAME);

    recording.setDuration(REC_DURATION);
    recording.setMaxSize(MAX_SIZE);
    recording.setMaxAge(MAX_AGE);
    recording.setName(REC_NAME);
    if (path != null) {
        recording.setToDisk(true);
        recording.setDestination(path);
    }

    long tsBeforeStart = Instant.now().toEpochMilli();
    recording.start();
    recording.stop();
    long tsAfterStop = Instant.now().toEpochMilli();

    List<RecordedEvent> events = Events.fromRecording(recording);

    Events.hasEvents(events);
    RecordedEvent ev = events.get(0);

    // Duration must be kept in milliseconds
    assertEquals(REC_DURATION.toMillis(), ev.getValue("recordingDuration"));

    assertEquals(MAX_SIZE, ev.getValue("maxSize"));

    // maxAge must be kept in milliseconds
    assertEquals(MAX_AGE.toMillis(), ev.getValue("maxAge"));

    EventType evType = ev.getEventType();
    ValueDescriptor durationField = evType.getField("recordingDuration");
    assertEquals(durationField.getAnnotation(Timespan.class).value(), Timespan.MILLISECONDS);

    if (path == null) {
        assertNull(ev.getValue("destination"));
    } else {
        assertEquals(path.toAbsolutePath().toString(), ev.getValue("destination").toString());
    }

    ValueDescriptor recordingStartField = evType.getField("recordingStart");
    assertEquals(recordingStartField.getAnnotation(Timestamp.class).value(), Timestamp.MILLISECONDS_SINCE_EPOCH);

    long tsRecordingStart = ev.getValue("recordingStart");
    assertTrue(tsBeforeStart <= tsRecordingStart);
    assertTrue(tsAfterStop >= tsRecordingStart);

    assertEquals(recording.getId(), ev.getValue("id"));

    ValueDescriptor maxAgeField = evType.getField("maxAge");
    assertEquals(maxAgeField.getAnnotation(Timespan.class).value(), Timespan.MILLISECONDS);
}
 
Example 20
Source File: TestExtends.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private static void verifyField(EventType t, String name) throws Exception {
    ValueDescriptor d = t.getField(name);
    if (d == null) {
        throw new Exception("Missing field " + name + " in event " + t.getName());
    }
}