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

The following examples show how to use jdk.jfr.consumer.RecordedObject#getFields() . 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: JSONWriter.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void printObject(RecordedObject object) {
    printObjectBegin();
    boolean first = true;
    for (ValueDescriptor v : object.getFields()) {
        printValueDescriptor(first, false, v, object.getValue(v.getName()));
        first = false;
    }
    printObjectEnd();
}
 
Example 2
Source File: PrettyWriter.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void print(RecordedObject struct, String postFix) throws IOException {
    println("{");
    indent();
    for (ValueDescriptor v : struct.getFields()) {
        printIndent();
        print(v.getName(), " = ");
        printValue(struct.getValue(v.getName()), "");
    }
    retract();
    printIndent();
    println("}" + postFix);
}
 
Example 3
Source File: XMLWriter.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void printObject(RecordedObject struct) {
    println();
    indent();
    for (ValueDescriptor v : struct.getFields()) {
        printValueDescriptor(v, struct.getValue(v.getName()), -1);
    }
    retract();
}
 
Example 4
Source File: TestPrintXML.java    From dragonwell8_jdk with GNU General Public License v2.0 5 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();
            if (!compare(re.getValue(name), xmlMap.get(name))) {
                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 5
Source File: Events.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static ValueDescriptor getValueDescriptor(RecordedObject struct, String name) throws Exception {
    List<ValueDescriptor> valueDescriptors = struct.getFields();
    for (ValueDescriptor d : valueDescriptors) {
        if (name.equals(d.getName())) {
            return d;
        }
    }
    System.out.printf("Failed struct:%s", struct.toString());
    fail(String.format("Field %s not in struct", name));
    return null;
}
 
Example 6
Source File: JSONWriter.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void printObject(RecordedObject object) {
    printObjectBegin();
    boolean first = true;
    for (ValueDescriptor v : object.getFields()) {
        printValueDescriptor(first, false, v, getValue(object, v));
        first = false;
    }
    printObjectEnd();
}
 
Example 7
Source File: PrettyWriter.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void print(RecordedObject struct, String postFix) {
    println("{");
    indent();
    for (ValueDescriptor v : struct.getFields()) {
        printFieldValue(struct, v);
    }
    retract();
    printIndent();
    println("}" + postFix);
}
 
Example 8
Source File: XMLWriter.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void printObject(RecordedObject struct) {
    println();
    indent();
    for (ValueDescriptor v : struct.getFields()) {
        printValueDescriptor(v, getValue(struct, v), -1);
    }
    retract();
}
 
Example 9
Source File: Events.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static ValueDescriptor getValueDescriptor(RecordedObject struct, String name) throws Exception {
    List<ValueDescriptor> valueDescriptors = struct.getFields();
    for (ValueDescriptor d : valueDescriptors) {
        if (name.equals(d.getName())) {
            return d;
        }
    }
    System.out.printf("Failed struct:%s", struct.toString());
    fail(String.format("Field %s not in struct", name));
    return null;
}
 
Example 10
Source File: JSONWriter.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void printObject(RecordedObject object) {
    printObjectBegin();
    boolean first = true;
    for (ValueDescriptor v : object.getFields()) {
        printValueDescriptor(first, false, v, getValue(object, v));
        first = false;
    }
    printObjectEnd();
}
 
Example 11
Source File: PrettyWriter.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void print(RecordedObject struct, String postFix) {
    println("{");
    indent();
    for (ValueDescriptor v : struct.getFields()) {
        printFieldValue(struct, v);
    }
    retract();
    printIndent();
    println("}" + postFix);
}
 
Example 12
Source File: XMLWriter.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void printObject(RecordedObject struct) {
    println();
    indent();
    for (ValueDescriptor v : struct.getFields()) {
        printValueDescriptor(v, getValue(struct, v), -1);
    }
    retract();
}
 
Example 13
Source File: Events.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static ValueDescriptor getValueDescriptor(RecordedObject struct, String name) throws Exception {
    List<ValueDescriptor> valueDescriptors = struct.getFields();
    for (ValueDescriptor d : valueDescriptors) {
        if (name.equals(d.getName())) {
            return d;
        }
    }
    System.out.printf("Failed struct:%s", struct.toString());
    fail(String.format("Field %s not in struct", name));
    return null;
}
 
Example 14
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 15
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);
}