Java Code Examples for jdk.jfr.consumer.RecordedObject#getDuration()

The following examples show how to use jdk.jfr.consumer.RecordedObject#getDuration() . 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: EventPrintWriter.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
protected Object getValue(RecordedObject object, ValueDescriptor v) {
    ValueType valueType = typeOfValues.get(v);
    if (valueType == null) {
        valueType = determineValueType(v);
        typeOfValues.put(v, valueType);
    }
    switch (valueType) {
    case TIMESPAN:
        return object.getDuration(v.getName());
    case TIMESTAMP:
        return RecordingInternals.INSTANCE.getOffsetDataTime(object, v.getName());
    default:
        return object.getValue(v.getName());
    }
}
 
Example 2
Source File: EventPrintWriter.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
protected Object getValue(RecordedObject object, ValueDescriptor v) {
    ValueType valueType = typeOfValues.get(v);
    if (valueType == null) {
        valueType = determineValueType(v);
        typeOfValues.put(v, valueType);
    }
    switch (valueType) {
    case TIMESPAN:
        return object.getDuration(v.getName());
    case TIMESTAMP:
        return RecordingInternals.INSTANCE.getOffsetDataTime(object, v.getName());
    default:
        return object.getValue(v.getName());
    }
}
 
Example 3
Source File: TestPrintXML.java    From TencentKona-8 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 4
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);
}