Java Code Examples for jdk.jfr.consumer.RecordedEvent#getEventType()

The following examples show how to use jdk.jfr.consumer.RecordedEvent#getEventType() . 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: XMLWriter.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private void printEvent(RecordedEvent event) {
    EventType type = event.getEventType();
    printIndent();
    print("<event");
    printAttribute("type", type.getName());
    print(">");
    println();
    indent();
    for (ValueDescriptor v : event.getFields()) {
        printValueDescriptor(v, getValue(event, v), -1);
    }
    retract();
    printIndent();
    println("</event>");
    println();
}
 
Example 3
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 4
Source File: XMLWriter.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private void printEvent(RecordedEvent event) {
    EventType type = event.getEventType();
    printIndent();
    print("<event");
    printAttribute("type", type.getName());
    print(">");
    println();
    indent();
    for (ValueDescriptor v : event.getFields()) {
        printValueDescriptor(v, getValue(event, v), -1);
    }
    retract();
    printIndent();
    println("</event>");
    println();
}
 
Example 5
Source File: MainTest.java    From openjdk-jdk8u 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: JSONWriter.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private void printEvent(RecordedEvent e) {
    printObjectBegin();
    EventType type = e.getEventType();
    printValue(true, false, "name", type.getName());
    printValue(false, false, "typeId", type.getId());
    printValue(false, false, "startTime", e.getStartTime());
    printValue(false, false, "duration", e.getDuration());
    printNewDataStructure(false, false, "values");
    printObject(e);
    printObjectEnd();
}
 
Example 7
Source File: XMLWriter.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private void printEvent(RecordedEvent e) throws IOException {
    EventType type = e.getEventType();
    printIndent();
    print("<event");
    printAttribute("typeId", String.valueOf(type.getId()));
    printAttribute("name", type.getName());
    printAttribute("startTime",e.getStartTime().toString());
    printAttribute("duration", e.getDuration().toString());
    print(">");
    printObject(e);
    printIndent();
    println("</event>");
    println();
}
 
Example 8
Source File: JSONWriter.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private void printEvent(RecordedEvent event) {
    printObjectBegin();
    EventType type = event.getEventType();
    printValue(true, false, "type", type.getName());
    printNewDataStructure(false, false, "values");
    printObjectBegin();
    boolean first = true;
    for (ValueDescriptor v : event.getFields()) {
        printValueDescriptor(first, false, v, getValue(event, v));
        first = false;
    }
    printObjectEnd();
    printObjectEnd();
}
 
Example 9
Source File: JSONWriter.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private void printEvent(RecordedEvent event) {
    printObjectBegin();
    EventType type = event.getEventType();
    printValue(true, false, "type", type.getName());
    printNewDataStructure(false, false, "values");
    printObjectBegin();
    boolean first = true;
    for (ValueDescriptor v : event.getFields()) {
        printValueDescriptor(first, false, v, getValue(event, v));
        first = false;
    }
    printObjectEnd();
    printObjectEnd();
}
 
Example 10
Source File: TestActiveRecordingEvent.java    From dragonwell8_jdk 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 11
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 12
Source File: TestActiveRecordingEvent.java    From openjdk-jdk8u 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);
}