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

The following examples show how to use jdk.jfr.consumer.RecordedEvent#getValue() . 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: TestVMOperation.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 recording = new Recording();
    recording.enable(EVENT_NAME).withThreshold(Duration.ofMillis(0));
    recording.start();
    System.gc();
    recording.stop();

    List<RecordedEvent> events = Events.fromRecording(recording);
    Events.hasEvents(events);
    for (RecordedEvent event : Events.fromRecording(recording)) {
        String operation = Events.assertField(event, "operation").notEmpty().getValue();
        if (operation.equals(VM_OPERATION)) {
            Events.assertField(event, "safepoint").equal(true);
            Events.assertField(event, "blocking").equal(true);
            RecordedThread jt = event.getValue("caller");
            if (Thread.currentThread().getName().equals(jt.getJavaName())) {
                return;
            }
        }
    }
    throw new AssertionError("No matching event with VM operation name " + VM_OPERATION + " and current threasd as caller");
}
 
Example 2
Source File: IOEvent.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static IOEvent createTestEvent(RecordedEvent event) {
    EventType eventType = getEventType(event);
    if (eventType == EventType.UnknownEvent) {
        return null;
    }
    EventField ev = Events.assertField(event, "eventThread");
    RecordedThread t = ev.getValue();
    String thread = t.getJavaName();
    long size = 0L;
    if (isWriteEvent(eventType)) {
        size = Events.assertField(event, "bytesWritten").getValue();
    } else if (isReadEvent(eventType)) {
        size = Events.assertField(event, "bytesRead").getValue();
    }
    String address = getEventAddress(event);
    boolean endOfStream = false;
    if (event.hasField("endOfStream")) {
        endOfStream = event.getValue("endOfStream");
    }
    if (event.hasField("endOfFile")) {
        endOfStream = event.getValue("endOfFile");
    }
    return new IOEvent(thread, eventType, size, address, endOfStream);
}
 
Example 3
Source File: TestEventFactory.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static void verifyValues(RecordedEvent event) {
    for (Map.Entry<String, Object> entry : EVENT_VALUES.entrySet()) {
        String fieldName = entry.getKey();
        Object value = event.getValue(fieldName);
        Object expected = EVENT_VALUES.get(fieldName);
        if (expected instanceof Class) {
            value = ((RecordedClass) value).getName();
            expected = ((Class<?>) expected).getName();
        }
        if (expected instanceof Thread) {
            value = ((RecordedThread) value).getJavaName();
            expected = ((Thread) expected).getName();
        }
        Asserts.assertEQ(value, expected);
    }
}
 
Example 4
Source File: TestNativeLibrariesEvent.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 recording = new Recording();
    recording.enable(EVENT_NAME);
    recording.start();
    recording.stop();

    List<String> expectedLibs = getExpectedLibs();
    for (RecordedEvent event : Events.fromRecording(recording)) {
        System.out.println("Event:" + event);
        long unsignedTopAddress = event.getValue("topAddress");
        long unsignedBaseAddress = event.getValue("baseAddress");
        assertValidAddresses(unsignedBaseAddress, unsignedTopAddress);
        String lib = Events.assertField(event, "name").notEmpty().getValue();
        for (String expectedLib : new ArrayList<>(expectedLibs)) {
            if (lib.contains(expectedLib)) {
                expectedLibs.remove(expectedLib);
            }
        }
    }
    assertTrue(expectedLibs.isEmpty(), "Missing libraries:" + expectedLibs.stream().collect(Collectors.joining(", ")));
}
 
Example 5
Source File: TestLargeJavaEvent64k.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void verify(RecordedEvent event, Map<String, Object> fields) {
    for (Map.Entry<String, Object> entry : fields.entrySet()) {
        String fieldName = entry.getKey();
        Object value = event.getValue(fieldName);
        Object expected = fields.get(fieldName);
        Asserts.assertEQ(value, expected);
    }
}
 
Example 6
Source File: OldObjects.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static boolean matchingReferrerClass(RecordedEvent event, String className) {
    RecordedObject referrer = event.getValue("object.referrer");
    if (referrer != null) {
        if (!referrer.hasField("object.type")) {
            return false;
        }

        String reportedClass = ((RecordedClass) referrer.getValue("object.type")).getName();
        if (reportedClass.equals(className)) {
            return true;
        }
    }
    return false;
}
 
Example 7
Source File: TestClassLoaderLeak.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 {
    WhiteBox.setWriteAllObjectSamples(true);

    try (Recording r = new Recording()) {
        r.enable(EventNames.OldObjectSample).withStackTrace().with("cutoff", "infinity");
        r.start();
        TestClassLoader testClassLoader = new TestClassLoader();
        for (Class<?> clazz : testClassLoader.loadClasses(OldObjects.MIN_SIZE / 20)) {
            // Allocate array to trigger sampling code path for interpreter / c1
            for (int i = 0; i < 20; i++) {
                Object classArray = Array.newInstance(clazz, 20);
                Array.set(classArray, i, clazz.newInstance());
                classObjects.add(classArray);
            }
        }
        r.stop();
        List<RecordedEvent> events = Events.fromRecording(r);
        Events.hasEvents(events);
        for (RecordedEvent e : events) {
            RecordedObject object = e.getValue("object");
            RecordedClass rc = object.getValue("type");
            if (rc.getName().contains("TestClass")) {
                return;
            }
        }
        Asserts.fail("Could not find class leak");
    }
}
 
Example 8
Source File: TestClassLoadEvent.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Throwable {
    Recording recording = new Recording();
    recording.enable(EVENT_NAME).withThreshold(Duration.ofMillis(0));
    TestClassLoader cl = new TestClassLoader();
    recording.start();
    cl.loadClass(TEST_CLASS_NAME);
    recording.stop();

    List<RecordedEvent> events = Events.fromRecording(recording);
    boolean isLoaded = false;
    for (RecordedEvent event : events) {
        RecordedClass loadedClass = event.getValue("loadedClass");
        if (SEARCH_CLASS_NAME.equals(loadedClass.getName())) {
            System.out.println(event);
            /** unsupported now
            Events.assertClassPackage(loadedClass, SEARCH_PACKAGE_NAME);
            Events.assertClassModule(loadedClass, SEARCH_MODULE_NAME);
            */
            RecordedClassLoader initiatingClassLoader = event.getValue("initiatingClassLoader");
            Asserts.assertEquals(cl.getClass().getName(), initiatingClassLoader.getType().getName(),
                "Expected type " + cl.getClass().getName() + ", got type " + initiatingClassLoader.getType().getName());
            RecordedClassLoader definingClassLoader = loadedClass.getClassLoader();
            Asserts.assertEquals(BOOT_CLASS_LOADER_NAME, definingClassLoader.getName(),
                "Expected boot loader to be the defining class loader");
            Asserts.assertNull(definingClassLoader.getType(), "boot loader should not have a type");
            isLoaded = true;
        }
    }
    Asserts.assertTrue(isLoaded, "No class load event found for class " + SEARCH_CLASS_NAME);
}
 
Example 9
Source File: TestActiveSettingEvent.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static boolean hasSetting(List<RecordedEvent> events, EventType evenType, String settingName, String settingValue) throws Exception {
    for (RecordedEvent e : events) {
        if (e.getEventType().getName().equals(ACTIVE_SETTING_EVENT_NAME)) {
            String name = e.getValue("name");
            String value = e.getValue("value");
            Long id = e.getValue("id");
            if (evenType.getId() == id && name.equals(settingName) && settingValue.equals(value)) {
                return true;
            }
        }
    }
    return false;
}
 
Example 10
Source File: TestPeriod.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static boolean isMyThread(RecordedEvent event) {
    Object o = event.getValue("thread");
    if (o instanceof RecordedThread) {
        RecordedThread rt = (RecordedThread) o;
        return Thread.currentThread().getId() == rt.getJavaThreadId();
    }
    return false;
}
 
Example 11
Source File: TestMetadataRetention.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void validateClassUnloadEvent(List<RecordedEvent> events) throws Throwable {
    for (RecordedEvent event : events) {
        if (event.getEventType().getName().equals(EventNames.ClassUnload)) {
            RecordedClass unloadedClass = event.getValue("unloadedClass");
            if (TEST_CLASS_NAME.equals(unloadedClass.getName())) {
                RecordedClassLoader definingClassLoader = unloadedClass.getClassLoader();
                Asserts.assertEquals(TEST_CLASS_LOADER_NAME, definingClassLoader.getName(), "Expected " + TEST_CLASS_LOADER_NAME + ", got " + definingClassLoader.getType().getName());
                return;
            }
        }
    }
}
 
Example 12
Source File: TestJcmdDumpPathToGCRoots.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static boolean hasChains(List<RecordedEvent> events) throws IOException {
    for (RecordedEvent e : events) {
        RecordedObject ro = e.getValue("object");
        if (ro.getValue("referrer") != null) {
            return true;
        }
    }
    return false;
}
 
Example 13
Source File: MainTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void assertOrdinaryEvent(List<RecordedEvent> events) {
    for (RecordedEvent e : events) {
        String message = e.getValue("message");
        if (message.equals(HELLO_PERIODIC)) {
            return;
        }
    }
    throw new RuntimeException("Could not find periodic event in recording");
}
 
Example 14
Source File: TestLargeJavaEvent512k.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void verify(RecordedEvent event, Map<String, Object> fields) {
    for (Map.Entry<String, Object> entry : fields.entrySet()) {
        String fieldName = entry.getKey();
        Object value = event.getValue(fieldName);
        Object expected = fields.get(fieldName);
        Asserts.assertEQ(value, expected);
    }
}
 
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());
}
 
Example 16
Source File: TestJavaMonitorWaitTimeOut.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private static boolean isWaitEvent(RecordedEvent event) {
    RecordedClass t = event.getValue("monitorClass");
    return t != null && t.getName().equals(Lock.class.getName());
}
 
Example 17
Source File: TestCodeCacheConfig.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    Recording recording = new Recording();
    recording.enable(EVENT_NAME);
    recording.start();
    recording.stop();

    List<RecordedEvent> events = Events.fromRecording(recording);
    Events.hasEvents(events);
    RecordedEvent event = events.get(0);
    long initialSize = (long) event.getValue("initialSize");
    long reservedSize = (long) event.getValue("reservedSize");
    long nonNMethodSize = (long) event.getValue("nonNMethodSize");
    long profiledSize = (long) event.getValue("profiledSize");
    long nonProfiledSize = (long) event.getValue("nonProfiledSize");
    long expansionSize = (long) event.getValue("expansionSize");
    long minBlockLength = (long) event.getValue("minBlockLength");
    long startAddress = (long) event.getValue("startAddress");
    long reservedTopAddress = (long) event.getValue("reservedTopAddress");

    Asserts.assertGT(initialSize, 1024L,
        "initialSize less than 1024 byte, got " + initialSize);

    Asserts.assertEQ(reservedSize, CodeCacheExpectedSize,
        String.format("Unexpected reservedSize value. Expected %d but " + "got %d", CodeCacheExpectedSize, reservedSize));

    Asserts.assertLTE(nonNMethodSize, CodeCacheExpectedSize,
        String.format("Unexpected nonNMethodSize value. Expected <= %d but " + "got %d", CodeCacheExpectedSize, nonNMethodSize));

    Asserts.assertLTE(profiledSize, CodeCacheExpectedSize,
        String.format("Unexpected profiledSize value. Expected <= %d but " + "got %d", CodeCacheExpectedSize, profiledSize));

    Asserts.assertLTE(nonProfiledSize, CodeCacheExpectedSize,
        String.format("Unexpected nonProfiledSize value. Expected <= %d but " + "got %d", CodeCacheExpectedSize, nonProfiledSize));

    Asserts.assertGTE(expansionSize, 1024L,
        "expansionSize less than 1024 " + "bytes, got " + expansionSize);

    Asserts.assertGTE(minBlockLength, 1L,
        "minBlockLength less than 1 byte, got " + minBlockLength);

    Asserts.assertNE(startAddress, 0L,
        "startAddress null");

    Asserts.assertNE(reservedTopAddress, 0L,
        "codeCacheReservedTopAddr null");
}
 
Example 18
Source File: OldObjects.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static String getReferrerFieldName(RecordedEvent event) {
    RecordedObject referrer = event.getValue("object.referrer");
    return referrer != null && referrer.hasField("field.name") ? referrer.getValue("field.name") : null;
}
 
Example 19
Source File: OldObjects.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static String getReferrerFieldName(RecordedEvent event) {
    RecordedObject referrer = event.getValue("object.referrer");
    return referrer != null && referrer.hasField("field.name") ? referrer.getValue("field.name") : null;
}
 
Example 20
Source File: OldObjects.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static String getReferrerFieldName(RecordedEvent event) {
    RecordedObject referrer = event.getValue("object.referrer");
    return referrer != null && referrer.hasField("field.name") ? referrer.getValue("field.name") : null;
}