jdk.jfr.Timespan Java Examples

The following examples show how to use jdk.jfr.Timespan. 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: RecordedObject.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private Duration getDuration(long timespan, String name) throws InternalError {
    ValueDescriptor v = getValueDescriptor(descriptors, name, null);
    Timespan ts = v.getAnnotation(Timespan.class);
    if (ts != null) {
        switch (ts.value()) {
        case Timespan.MICROSECONDS:
            return Duration.ofNanos(1000 * timespan);
        case Timespan.SECONDS:
            return Duration.ofSeconds(timespan);
        case Timespan.MILLISECONDS:
            return Duration.ofMillis(timespan);
        case Timespan.NANOSECONDS:
            return Duration.ofNanos(timespan);
        case Timespan.TICKS:
            return Duration.ofNanos(timeConverter.convertTimespan(timespan));
        }
        throw new IllegalArgumentException("Attempt to get " + v.getTypeName() + " field \"" + name + "\" with illegal timespan unit " + ts.value());
    }
    throw new IllegalArgumentException("Attempt to get " + v.getTypeName() + " field \"" + name + "\" with missing @Timespan");
}
 
Example #2
Source File: TestGetContentType.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.assertNull(plain.getContentType());

    SettingDescriptor annotatedType = Events.getSetting(type, "annotatedType");
    Asserts.assertNull(annotatedType.getContentType(), Timestamp.class.getName());

    SettingDescriptor newName = Events.getSetting(type, "newName");
    Asserts.assertEquals(newName.getContentType(), Timespan.class.getName());

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

    SettingDescriptor protectedBase = Events.getSetting(type, "protectedBase");
    Asserts.assertEquals(protectedBase.getContentType(), Frequency.class);

    SettingDescriptor publicBase = Events.getSetting(type, "publicBase");
    Asserts.assertEquals(publicBase.getContentType(), Timestamp.class.getName());

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

    CustomEvent.assertOnDisk((x, y) -> Objects.equals(x.getContentType(), y.getContentType()) ? 0 : 1);
}
 
Example #3
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 #4
Source File: RecordedObject.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private Duration getDuration(long timespan, String name) throws InternalError {
    ValueDescriptor v = getValueDescriptor(descriptors, name, null);
    if (timespan == Long.MIN_VALUE) {
        return Duration.ofSeconds(Long.MIN_VALUE, 0);
    }
    Timespan ts = v.getAnnotation(Timespan.class);
    if (ts != null) {
        switch (ts.value()) {
        case Timespan.MICROSECONDS:
            return Duration.ofNanos(1000 * timespan);
        case Timespan.SECONDS:
            return Duration.ofSeconds(timespan);
        case Timespan.MILLISECONDS:
            return Duration.ofMillis(timespan);
        case Timespan.NANOSECONDS:
            return Duration.ofNanos(timespan);
        case Timespan.TICKS:
            return Duration.ofNanos(timeConverter.convertTimespan(timespan));
        }
        throw new IllegalArgumentException("Attempt to get " + v.getTypeName() + " field \"" + name + "\" with illegal timespan unit " + ts.value());
    }
    throw new IllegalArgumentException("Attempt to get " + v.getTypeName() + " field \"" + name + "\" with missing @Timespan");
}
 
Example #5
Source File: RecordedObject.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private Duration getDuration(long timespan, String name) throws InternalError {
    ValueDescriptor v = getValueDescriptor(descriptors, name, null);
    if (timespan == Long.MIN_VALUE) {
        return Duration.ofSeconds(Long.MIN_VALUE, 0);
    }
    Timespan ts = v.getAnnotation(Timespan.class);
    if (ts != null) {
        switch (ts.value()) {
        case Timespan.MICROSECONDS:
            return Duration.ofNanos(1000 * timespan);
        case Timespan.SECONDS:
            return Duration.ofSeconds(timespan);
        case Timespan.MILLISECONDS:
            return Duration.ofMillis(timespan);
        case Timespan.NANOSECONDS:
            return Duration.ofNanos(timespan);
        case Timespan.TICKS:
            return Duration.ofNanos(timeConverter.convertTimespan(timespan));
        }
        throw new IllegalArgumentException("Attempt to get " + v.getTypeName() + " field \"" + name + "\" with illegal timespan unit " + ts.value());
    }
    throw new IllegalArgumentException("Attempt to get " + v.getTypeName() + " field \"" + name + "\" with missing @Timespan");
}
 
Example #6
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 #7
Source File: TestGetContentType.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.getContentType());

    SettingDescriptor annotatedType = Events.getSetting(type, "annotatedType");
    Asserts.assertNull(annotatedType.getContentType(), Timestamp.class.getName());

    SettingDescriptor newName = Events.getSetting(type, "newName");
    Asserts.assertEquals(newName.getContentType(), Timespan.class.getName());

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

    SettingDescriptor protectedBase = Events.getSetting(type, "protectedBase");
    Asserts.assertEquals(protectedBase.getContentType(), Frequency.class);

    SettingDescriptor publicBase = Events.getSetting(type, "publicBase");
    Asserts.assertEquals(publicBase.getContentType(), Timestamp.class.getName());

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

    CustomEvent.assertOnDisk((x, y) -> Objects.equals(x.getContentType(), y.getContentType()) ? 0 : 1);
}
 
Example #8
Source File: TestGetContentType.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.getContentType());

    SettingDescriptor annotatedType = Events.getSetting(type, "annotatedType");
    Asserts.assertNull(annotatedType.getContentType(), Timestamp.class.getName());

    SettingDescriptor newName = Events.getSetting(type, "newName");
    Asserts.assertEquals(newName.getContentType(), Timespan.class.getName());

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

    SettingDescriptor protectedBase = Events.getSetting(type, "protectedBase");
    Asserts.assertEquals(protectedBase.getContentType(), Frequency.class);

    SettingDescriptor publicBase = Events.getSetting(type, "publicBase");
    Asserts.assertEquals(publicBase.getContentType(), Timestamp.class.getName());

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

    CustomEvent.assertOnDisk((x, y) -> Objects.equals(x.getContentType(), y.getContentType()) ? 0 : 1);
}
 
Example #9
Source File: TestGetAnnotation.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 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: CustomEvent.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@SettingDefinition
@Name("newName")
@Label(ANNOTATED_METHOD)
@Description(DESCRIPTION_OF_AN_ANNOTATED_METHOD)
@Timespan(Timespan.NANOSECONDS)
public boolean whatever(AnnotatedSetting s) {
    return true;
}
 
Example #11
Source File: TypeLibrary.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
static void addImplicitFields(Type type, boolean requestable, boolean hasDuration, boolean hasThread, boolean hasStackTrace, boolean hasCutoff) {
    createAnnotationType(Timespan.class);
    createAnnotationType(Timestamp.class);
    createAnnotationType(Label.class);
    defineType(long.class, null,false);
    addFields(type, requestable, hasDuration, hasThread, hasStackTrace, hasCutoff);
}
 
Example #12
Source File: EventPrintWriter.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private ValueType determineValueType(ValueDescriptor v) {
    if (v.getAnnotation(Timespan.class) != null) {
        return ValueType.TIMESPAN;
    }
    if (v.getAnnotation(Timestamp.class) != null) {
        return ValueType.TIMESTAMP;
    }
    return ValueType.OTHER;
}
 
Example #13
Source File: TestContentType.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(SunnyDay.class);
        AnnotationElement aMax = Events.getAnnotation(t.getField("max"), Temperature.class);
        ContentType cMax = aMax.getAnnotation(ContentType.class);
        if (cMax == null) {
            throw new Exception("Expected Temperature annotation for field 'max' to have meta annotation ContentType");
        }
        AnnotationElement aHours = Events.getAnnotation(t.getField("hours"), Timespan.class);
        ContentType cHours = aHours.getAnnotation(ContentType.class);
        Asserts.assertTrue(cHours != null, "Expected Timespan annotation for field 'hours' to have meta annotation ContentType");
    }
 
Example #14
Source File: TestFieldAnnotations.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(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 #15
Source File: TestContentType.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(SunnyDay.class);
        AnnotationElement aMax = Events.getAnnotation(t.getField("max"), Temperature.class);
        ContentType cMax = aMax.getAnnotation(ContentType.class);
        if (cMax == null) {
            throw new Exception("Expected Temperature annotation for field 'max' to have meta annotation ContentType");
        }
        AnnotationElement aHours = Events.getAnnotation(t.getField("hours"), Timespan.class);
        ContentType cHours = aHours.getAnnotation(ContentType.class);
        Asserts.assertTrue(cHours != null, "Expected Timespan annotation for field 'hours' to have meta annotation ContentType");
    }
 
Example #16
Source File: CustomEvent.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@SettingDefinition
@Name("newName")
@Label(ANNOTATED_METHOD)
@Description(DESCRIPTION_OF_AN_ANNOTATED_METHOD)
@Timespan(Timespan.NANOSECONDS)
public boolean whatever(AnnotatedSetting s) {
    return true;
}
 
Example #17
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 #18
Source File: TraceHandler.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
TraceHandler() {

        // Content types handled using annotation in Java
        annotationTypes.put("BYTES64", new AnnotationElement(DataAmount.class, DataAmount.BYTES));
        annotationTypes.put("BYTES", new AnnotationElement(DataAmount.class, DataAmount.BYTES));
        annotationTypes.put("MILLIS", new AnnotationElement(Timespan.class, Timespan.MILLISECONDS));
        annotationTypes.put("EPOCHMILLIS", new AnnotationElement(Timestamp.class, Timestamp.MILLISECONDS_SINCE_EPOCH));
        annotationTypes.put("NANOS", new AnnotationElement(Timespan.class, Timespan.NANOSECONDS));
        annotationTypes.put("TICKSPAN",  new AnnotationElement(Timespan.class, Timespan.TICKS));
        annotationTypes.put("TICKS",  new AnnotationElement(Timestamp.class, Timespan.TICKS));
        annotationTypes.put("ADDRESS", new AnnotationElement(MemoryAddress.class));
        annotationTypes.put("PERCENTAGE",  new AnnotationElement(Percentage.class));

        // Add known unsigned types, and their counter part in Java
        unsignedTypes.put("U8", Type.LONG);
        unsignedTypes.put("U4", Type.INT);
        unsignedTypes.put("U2", Type.SHORT);
        unsignedTypes.put("U1", Type.BYTE);

        // Map trace.xml primitive to Java type
        typedef.put("U8", Type.LONG.getName());
        typedef.put("U4", Type.INT.getName());
        typedef.put("U2", Type.SHORT.getName());
        typedef.put("U1", Type.BYTE.getName());
        typedef.put("LONG", Type.LONG.getName());
        typedef.put("INT", Type.INT.getName());
        typedef.put("SHORT", Type.SHORT.getName());
        typedef.put("BYTE", Type.BYTE.getName());
        typedef.put("DOUBLE", Type.DOUBLE.getName());
        typedef.put("BOOLEAN", Type.BOOLEAN.getName());
        typedef.put("FLOAT", Type.FLOAT.getName());
        typedef.put("CHAR", Type.CHAR.getName());
        typedef.put("STRING", Type.STRING.getName());
        typedef.put("THREAD", Type.THREAD.getName());
        typedef.put("CLASS", Type.CLASS.getName());
        // Add known types
        for (Type type : Type.getKnownTypes()) {
            types.put(type.getName(), type);
        }
    }
 
Example #19
Source File: TypeLibrary.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
static void addImplicitFields(Type type, boolean requestable, boolean hasDuration, boolean hasThread, boolean hasStackTrace, boolean hasCutoff) {
    createAnnotationType(Timespan.class);
    createAnnotationType(Timestamp.class);
    createAnnotationType(Label.class);
    defineType(long.class, null,false);
    addFields(type, requestable, hasDuration, hasThread, hasStackTrace, hasCutoff);
}
 
Example #20
Source File: TypeLibrary.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
static void addImplicitFields(Type type, boolean requestable, boolean hasDuration, boolean hasThread, boolean hasStackTrace, boolean hasCutoff) {
    createAnnotationType(Timespan.class);
    createAnnotationType(Timestamp.class);
    createAnnotationType(Label.class);
    defineType(long.class, null,false);
    addFields(type, requestable, hasDuration, hasThread, hasStackTrace, hasCutoff);
}
 
Example #21
Source File: CustomEvent.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@SettingDefinition
@Name("newName")
@Label(ANNOTATED_METHOD)
@Description(DESCRIPTION_OF_AN_ANNOTATED_METHOD)
@Timespan(Timespan.NANOSECONDS)
public boolean whatever(AnnotatedSetting s) {
    return true;
}
 
Example #22
Source File: TestContentType.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(SunnyDay.class);
        AnnotationElement aMax = Events.getAnnotation(t.getField("max"), Temperature.class);
        ContentType cMax = aMax.getAnnotation(ContentType.class);
        if (cMax == null) {
            throw new Exception("Expected Temperature annotation for field 'max' to have meta annotation ContentType");
        }
        AnnotationElement aHours = Events.getAnnotation(t.getField("hours"), Timespan.class);
        ContentType cHours = aHours.getAnnotation(ContentType.class);
        Asserts.assertTrue(cHours != null, "Expected Timespan annotation for field 'hours' to have meta annotation ContentType");
    }
 
Example #23
Source File: TestFieldAnnotations.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(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 #24
Source File: CustomEvent.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@SettingDefinition
@Name("newName")
@Label(ANNOTATED_METHOD)
@Description(DESCRIPTION_OF_AN_ANNOTATED_METHOD)
@Timespan(Timespan.NANOSECONDS)
public boolean whatever(AnnotatedSetting s) {
    return true;
}
 
Example #25
Source File: EventPrintWriter.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private ValueType determineValueType(ValueDescriptor v) {
    if (v.getAnnotation(Timespan.class) != null) {
        return ValueType.TIMESPAN;
    }
    if (v.getAnnotation(Timestamp.class) != null) {
        return ValueType.TIMESTAMP;
    }
    return ValueType.OTHER;
}
 
Example #26
Source File: TypeLibrary.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private static ValueDescriptor createDurationField() {
    List<AnnotationElement> annos = new ArrayList<>();
    annos = createStandardAnnotations("Duration", null);
    annos.add(new jdk.jfr.AnnotationElement(Timespan.class, Timespan.TICKS));
    return PrivateAccess.getInstance().newValueDescriptor(EventInstrumentation.FIELD_DURATION, Type.LONG, annos, 0, false, EventInstrumentation.FIELD_DURATION);
}
 
Example #27
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 #28
Source File: TestPrintXML.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
static boolean compare(Object eventObject, Object xmlObject) {
    if (eventObject == null) {
        return xmlObject == null;
    }
    if (eventObject instanceof RecordedObject) {
        RecordedObject re = (RecordedObject) eventObject;
        Map<String, Object> xmlMap = (Map<String, Object>) xmlObject;
        List<ValueDescriptor> fields = re.getFields();
        if (fields.size() != xmlMap.size()) {
            return false;
        }
        for (ValueDescriptor v : fields) {
            String name = v.getName();
            Object xmlValue = xmlMap.get(name);
            Object expectedValue = re.getValue(name);
            if (v.getAnnotation(Timestamp.class) != null) {
                // Make instant of OffsetDateTime
                xmlValue = OffsetDateTime.parse("" + xmlValue).toInstant().toString();
                expectedValue = re.getInstant(name);
            }
            if (v.getAnnotation(Timespan.class) != null) {
                expectedValue = re.getDuration(name);
            }
            if (!compare(expectedValue, xmlValue)) {
                return false;
            }
        }
        return true;
    }
    if (eventObject.getClass().isArray()) {
        Object[] array = (Object[]) eventObject;
        Object[] xmlArray = (Object[]) xmlObject;
        if (array.length != xmlArray.length) {
            return false;
        }
        for (int i = 0; i < array.length; i++) {
            if (!compare(array[i], xmlArray[i])) {
                return false;
            }
        }
        return true;
    }
    String s1 = String.valueOf(eventObject);
    String s2 = (String) xmlObject;
    return s1.equals(s2);
}
 
Example #29
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 #30
Source File: TypeLibrary.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private static ValueDescriptor createDurationField() {
    List<AnnotationElement> annos = new ArrayList<>();
    annos = createStandardAnnotations("Duration", null);
    annos.add(new jdk.jfr.AnnotationElement(Timespan.class, Timespan.TICKS));
    return PrivateAccess.getInstance().newValueDescriptor(EventInstrumentation.FIELD_DURATION, Type.LONG, annos, 0, false, EventInstrumentation.FIELD_DURATION);
}