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

The following examples show how to use jdk.jfr.consumer.RecordedEvent#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: TestValueDescriptorRecorded.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Throwable {
    Recording r = new Recording();
    r.enable(MyEvent.class).withoutStackTrace();
    r.start();
    MyEvent event = new MyEvent();
    event.commit();
    r.stop();

    List<RecordedEvent> events = Events.fromRecording(r);
    Events.hasEvents(events);
    RecordedEvent recordedEvent = events.get(0);

    for (ValueDescriptor desc : recordedEvent.getFields()) {
        if ("myValue".equals(desc.getName())) {
            Asserts.assertEquals(desc.getLabel(), "myLabel");
            Asserts.assertEquals(desc.getDescription(), "myDescription");
            Asserts.assertEquals(desc.getTypeName(), int.class.getName());
            Asserts.assertFalse(desc.isArray());
            Asserts.assertNull(desc.getContentType());
        }
    }
}
 
Example 2
Source File: PrettyWriter.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public void print(RecordedEvent event) {
    currentEvent = event;
    print(event.getEventType().getName(), " ");
    println("{");
    indent();
    for (ValueDescriptor v : event.getFields()) {
        String name = v.getName();
        if (!isZeroDuration(event, name) && !isLateField(name)) {
            printFieldValue(event, v);
        }
    }
    if (event.getThread() != null) {
        printIndent();
        print(EVENT_THREAD_FIELD + " = ");
        printThread(event.getThread(), "");
    }
    if (event.getStackTrace() != null) {
        printIndent();
        print(STACK_TRACE_FIELD + " = ");
        printStackTrace(event.getStackTrace());
    }
    retract();
    printIndent();
    println("}");
    println();
}
 
Example 3
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 4
Source File: TestValueDescriptorRecorded.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Throwable {
    Recording r = new Recording();
    r.enable(MyEvent.class).withoutStackTrace();
    r.start();
    MyEvent event = new MyEvent();
    event.commit();
    r.stop();

    List<RecordedEvent> events = Events.fromRecording(r);
    Events.hasEvents(events);
    RecordedEvent recordedEvent = events.get(0);

    for (ValueDescriptor desc : recordedEvent.getFields()) {
        if ("myValue".equals(desc.getName())) {
            Asserts.assertEquals(desc.getLabel(), "myLabel");
            Asserts.assertEquals(desc.getDescription(), "myDescription");
            Asserts.assertEquals(desc.getTypeName(), int.class.getName());
            Asserts.assertFalse(desc.isArray());
            Asserts.assertNull(desc.getContentType());
        }
    }
}
 
Example 5
Source File: PrettyWriter.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public void print(RecordedEvent event) {
    currentEvent = event;
    print(event.getEventType().getName(), " ");
    println("{");
    indent();
    for (ValueDescriptor v : event.getFields()) {
        String name = v.getName();
        if (!isZeroDuration(event, name) && !isLateField(name)) {
            printFieldValue(event, v);
        }
    }
    if (event.getThread() != null) {
        printIndent();
        print(EVENT_THREAD_FIELD + " = ");
        printThread(event.getThread(), "");
    }
    if (event.getStackTrace() != null) {
        printIndent();
        print(STACK_TRACE_FIELD + " = ");
        printStackTrace(event.getStackTrace());
    }
    retract();
    printIndent();
    println("}");
    println();
}
 
Example 6
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 7
Source File: TestValueDescriptorRecorded.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Throwable {
    Recording r = new Recording();
    r.enable(MyEvent.class).withoutStackTrace();
    r.start();
    MyEvent event = new MyEvent();
    event.commit();
    r.stop();

    List<RecordedEvent> events = Events.fromRecording(r);
    Events.hasEvents(events);
    RecordedEvent recordedEvent = events.get(0);

    for (ValueDescriptor desc : recordedEvent.getFields()) {
        if ("myValue".equals(desc.getName())) {
            Asserts.assertEquals(desc.getLabel(), "myLabel");
            Asserts.assertEquals(desc.getDescription(), "myDescription");
            Asserts.assertEquals(desc.getTypeName(), int.class.getName());
            Asserts.assertFalse(desc.isArray());
            Asserts.assertNull(desc.getContentType());
        }
    }
}
 
Example 8
Source File: GCHelper.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static boolean isGcEvent(RecordedEvent event) {
    for (ValueDescriptor v : event.getFields()) {
        if ("gcId".equals(v.getName())) {
            return true;
        }
    }
    return false;
}
 
Example 9
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 10
Source File: GCHelper.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static boolean isGcEvent(RecordedEvent event) {
    for (ValueDescriptor v : event.getFields()) {
        if ("gcId".equals(v.getName())) {
            return true;
        }
    }
    return false;
}
 
Example 11
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 12
Source File: GCHelper.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static boolean isGcEvent(RecordedEvent event) {
    for (ValueDescriptor v : event.getFields()) {
        if ("gcId".equals(v.getName())) {
            return true;
        }
    }
    return false;
}
 
Example 13
Source File: TestRecordedEvent.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Throwable {
    Recording r = new Recording();
    r.start();
    TestEvent t = new TestEvent();
    t.commit();
    r.stop();
    List<RecordedEvent> events = Events.fromRecording(r);
    Events.hasEvents(events);

    Asserts.assertEquals(events.size(), 1);

    RecordedEvent event = events.get(0);
    System.out.println(event);

    List<ValueDescriptor> descriptors = event.getFields();

    System.out.println("Descriptors");
    for (ValueDescriptor descriptor : descriptors) {
        System.out.println(descriptor.getName());
        System.out.println(descriptor.getTypeName());
    }
    System.out.println("Descriptors end");

    Object recordedClass = event.getValue("clzField");
    Asserts.assertTrue(recordedClass instanceof RecordedClass, "Expected Recorded Class got " + recordedClass);

    Object recordedInt = event.getValue("intField");
    Asserts.assertTrue(recordedInt instanceof Integer);

    Object recordedString = event.getValue("stringField");
    System.out.println("recordedString class: " + recordedString.getClass());
    Asserts.assertTrue(recordedString instanceof String);

    Object myClass = event.getValue("myClass");
    Asserts.assertTrue(myClass instanceof RecordedClass, "Expected Recorded Class got " + recordedClass);

    RecordedClass myRecClass = (RecordedClass) myClass;
    Asserts.assertEquals(MyClass.class.getName(), myRecClass.getName(), "Got " + myRecClass.getName());

    Object recordedClassLoader = myRecClass.getValue("classLoader");
    Asserts.assertTrue(recordedClassLoader instanceof RecordedClassLoader, "Expected Recorded ClassLoader got " + recordedClassLoader);

    RecordedClassLoader myRecClassLoader = (RecordedClassLoader)recordedClassLoader;
    ClassLoader cl = MyClass.class.getClassLoader();
    Asserts.assertEquals(cl.getClass().getName(), myRecClassLoader.getType().getName(), "Expected Recorded ClassLoader type to equal loader type");

    Asserts.assertNotNull(myRecClass.getModifiers());
}
 
Example 14
Source File: TestRecordedEvent.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Throwable {
    Recording r = new Recording();
    r.start();
    TestEvent t = new TestEvent();
    t.commit();
    r.stop();
    List<RecordedEvent> events = Events.fromRecording(r);
    Events.hasEvents(events);

    Asserts.assertEquals(events.size(), 1);

    RecordedEvent event = events.get(0);

    List<ValueDescriptor> descriptors = event.getFields();

    System.out.println("Descriptors");
    for (ValueDescriptor descriptor : descriptors) {
        System.out.println(descriptor.getName());
        System.out.println(descriptor.getTypeName());
    }
    System.out.println("Descriptors end");

    Object recordedClass = event.getValue("clzField");
    Asserts.assertTrue(recordedClass instanceof RecordedClass, "Expected Recorded Class got " + recordedClass);

    Object recordedInt = event.getValue("intField");
    Asserts.assertTrue(recordedInt instanceof Integer);

    Object recordedString = event.getValue("stringField");
    System.out.println("recordedString class: " + recordedString.getClass());
    Asserts.assertTrue(recordedString instanceof String);

    Object myClass = event.getValue("myClass");
    Asserts.assertTrue(myClass instanceof RecordedClass, "Expected Recorded Class got " + recordedClass);

    RecordedClass myRecClass = (RecordedClass) myClass;
    Asserts.assertEquals(MyClass.class.getName(), myRecClass.getName(), "Got " + myRecClass.getName());

    Object recordedClassLoader = myRecClass.getValue("classLoader");
    Asserts.assertTrue(recordedClassLoader instanceof RecordedClassLoader, "Expected Recorded ClassLoader got " + recordedClassLoader);

    RecordedClassLoader myRecClassLoader = (RecordedClassLoader)recordedClassLoader;
    ClassLoader cl = MyClass.class.getClassLoader();
    Asserts.assertEquals(cl.getClass().getName(), myRecClassLoader.getType().getName(), "Expected Recorded ClassLoader type to equal loader type");

    Asserts.assertNotNull(myRecClass.getModifiers());
}
 
Example 15
Source File: TestRecordedEvent.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Throwable {
    Recording r = new Recording();
    r.start();
    TestEvent t = new TestEvent();
    t.commit();
    r.stop();
    List<RecordedEvent> events = Events.fromRecording(r);
    Events.hasEvents(events);

    Asserts.assertEquals(events.size(), 1);

    RecordedEvent event = events.get(0);

    List<ValueDescriptor> descriptors = event.getFields();

    System.out.println("Descriptors");
    for (ValueDescriptor descriptor : descriptors) {
        System.out.println(descriptor.getName());
        System.out.println(descriptor.getTypeName());
    }
    System.out.println("Descriptors end");

    Object recordedClass = event.getValue("clzField");
    Asserts.assertTrue(recordedClass instanceof RecordedClass, "Expected Recorded Class got " + recordedClass);

    Object recordedInt = event.getValue("intField");
    Asserts.assertTrue(recordedInt instanceof Integer);

    Object recordedString = event.getValue("stringField");
    System.out.println("recordedString class: " + recordedString.getClass());
    Asserts.assertTrue(recordedString instanceof String);

    Object myClass = event.getValue("myClass");
    Asserts.assertTrue(myClass instanceof RecordedClass, "Expected Recorded Class got " + recordedClass);

    RecordedClass myRecClass = (RecordedClass) myClass;
    Asserts.assertEquals(MyClass.class.getName(), myRecClass.getName(), "Got " + myRecClass.getName());

    Object recordedClassLoader = myRecClass.getValue("classLoader");
    Asserts.assertTrue(recordedClassLoader instanceof RecordedClassLoader, "Expected Recorded ClassLoader got " + recordedClassLoader);

    RecordedClassLoader myRecClassLoader = (RecordedClassLoader)recordedClassLoader;
    ClassLoader cl = MyClass.class.getClassLoader();
    Asserts.assertEquals(cl.getClass().getName(), myRecClassLoader.getType().getName(), "Expected Recorded ClassLoader type to equal loader type");

    Asserts.assertNotNull(myRecClass.getModifiers());
}