Java Code Examples for jdk.jfr.Recording#enable()

The following examples show how to use jdk.jfr.Recording#enable() . 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: 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 2
Source File: TestCodeCacheFull.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static void testWithBlobType(BlobType btype, long availableSize) throws Exception {
    Recording r = new Recording();
    r.enable(EventNames.CodeCacheFull);
    r.start();
    WhiteBox.getWhiteBox().allocateCodeBlob(availableSize, btype.id);
    r.stop();

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

    String codeBlobType = Events.assertField(event, "codeBlobType").notNull().getValue();
    BlobType blobType = blobTypeFromName(codeBlobType);
    Asserts.assertTrue(blobType.allowTypeWhenOverflow(blobType), "Unexpected overflow BlobType " + blobType.id);
    Events.assertField(event, "entryCount").atLeast(0);
    Events.assertField(event, "methodCount").atLeast(0);
    Events.assertEventThread(event);
    Events.assertField(event, "fullCount").atLeast(0);
    Events.assertField(event, "startAddress").notEqual(0L);
    Events.assertField(event, "commitedTopAddress").notEqual(0L);
    Events.assertField(event, "reservedTopAddress").notEqual(0L);
}
 
Example 3
Source File: TestBiasedLockRevocationEvents.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
static void testSelfRevocation() throws Throwable {
    class MyLock {};

    Recording recording = new Recording();

    recording.enable(EventNames.BiasedLockSelfRevocation);
    recording.start();

    MyLock l = new MyLock();
    touch(l);
    Thread.holdsLock(l);

    recording.stop();
    List<RecordedEvent> events = getRevocationEvents(recording, "lockClass", MyLock.class);
    Asserts.assertEQ(events.size(), 1);

    RecordedEvent event = events.get(0);
    Events.assertEventThread(event, Thread.currentThread());

    validateStackTrace(event.getStackTrace(), "holdsLock");
}
 
Example 4
Source File: TestBiasedLockRevocationEvents.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
static void testSelfRevocation() throws Throwable {
    class MyLock {};

    Recording recording = new Recording();

    recording.enable(EventNames.BiasedLockSelfRevocation);
    recording.start();

    MyLock l = new MyLock();
    touch(l);
    Thread.holdsLock(l);

    recording.stop();
    List<RecordedEvent> events = getRevocationEvents(recording, "lockClass", MyLock.class);
    Asserts.assertEQ(events.size(), 1);

    RecordedEvent event = events.get(0);
    Events.assertEventThread(event, Thread.currentThread());

    validateStackTrace(event.getStackTrace(), "holdsLock");
}
 
Example 5
Source File: TestDumpLongPath.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 {
    Recording r = new Recording();
    final String eventPath = EventNames.OSInformation;
    r.enable(eventPath);
    r.start();
    r.stop();

    Path dir = FileHelper.createLongDir(Paths.get("."));
    Path path = Paths.get(dir.toString(), "my.jfr");
    r.dump(path);
    r.close();

    Asserts.assertTrue(Files.exists(path), "Recording file does not exist: " + path);
    List<RecordedEvent> events = RecordingFile.readAllEvents(path);
    Asserts.assertFalse(events.isEmpty(), "No events found");
    String foundEventPath = events.get(0).getEventType().getName();
    System.out.printf("Found event: %s%n", foundEventPath);
    Asserts.assertEquals(foundEventPath, eventPath, "Wrong event");
}
 
Example 6
Source File: TestDumpReadOnly.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Throwable {

        Path readOnlyDir = FileHelper.createReadOnlyDir(Paths.get(".", "readonlydir"));
        if (!FileHelper.isReadOnlyPath(readOnlyDir)) {
            System.out.println("Failed to create read-only path. Maybe running a root? Test skipped");
            return;
        }
        Recording r = new Recording();
        r.enable(OS_INFORMATION);
        r.start();
        r.stop();
        Path path = Paths.get(readOnlyDir.toString(), "my.jfr");
        verifyException(()->{r.dump(path);}, "No Exception when dumping read-only dir");
        r.close();
    }
 
Example 7
Source File: TestClassLoaderStatsEvent.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Throwable {
    createDummyClassLoader(CLASS_LOADER_NAME);

    Recording recording = new Recording();
    recording.enable(EVENT_NAME);
    recording.start();
    recording.stop();
    List<RecordedEvent> consumer = Events.fromRecording(recording);
    Events.hasEvents(consumer);

    boolean isAnyFound = false;
    for (RecordedEvent event : consumer) {
        System.out.println("Event:" + event);
        if (Events.assertField(event, "classLoader").getValue() == null) {
            continue;
        }
        RecordedClassLoader recordedClassLoader = event.getValue("classLoader");
        if (CLASSLOADER_TYPE_NAME.equals(recordedClassLoader.getType().getName())) {
            Asserts.assertEquals(CLASS_LOADER_NAME, recordedClassLoader.getName(),
                "Expected class loader name " + CLASS_LOADER_NAME + ", got name " + recordedClassLoader.getName());
            Events.assertField(event, "classCount").equal(1L);
            Events.assertField(event, "chunkSize").above(1L);
            Events.assertField(event, "blockSize").above(1L);
            Events.assertField(event, "anonymousClassCount").equal(1L);
            Events.assertField(event, "anonymousChunkSize").above(1L);
            Events.assertField(event, "anonymousBlockSize").above(1L);
            isAnyFound = true;
        }
    }
    Asserts.assertTrue(isAnyFound, "No events found");
}
 
Example 8
Source File: TestGCConfigurationEventWithDefaultPauseTarget.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 {
    Recording recording = new Recording();
    recording.enable(EventNames.GCConfiguration);
    recording.start();
    recording.stop();
    List<RecordedEvent> events = Events.fromRecording(recording);
    assertGreaterThanOrEqual(events.size(), 1, "Expected at least 1 event");
    DefaultGCConfigurationVerifier verifier = new DefaultGCConfigurationVerifier(events.get(0));
    verifier.verify();
}
 
Example 9
Source File: TestGCConfigurationEventWithDefaultPauseTarget.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 {
    Recording recording = new Recording();
    recording.enable(EventNames.GCConfiguration);
    recording.start();
    recording.stop();
    List<RecordedEvent> events = Events.fromRecording(recording);
    assertGreaterThanOrEqual(events.size(), 1, "Expected at least 1 event");
    DefaultGCConfigurationVerifier verifier = new DefaultGCConfigurationVerifier(events.get(0));
    verifier.verify();
}
 
Example 10
Source File: TestG1MMUEvent.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 {

        Recording recording = new Recording();

        // activate the event we are interested in and start recording
        recording.enable(EVENT_NAME);
        recording.start();

        // Setting NewSize and MaxNewSize will limit eden, so
        // allocating 1024 5k byte arrays should trigger at
        // least one Young GC.
        for (int i = 0; i < 1024; i++) {
            bytes  = new byte[5 * 1024];
        }
        recording.stop();

        // Verify recording
        List<RecordedEvent> all = Events.fromRecording(recording);
        Events.hasEvents(all);

        for (RecordedEvent e : all) {
            Events.assertField(e, "gcId").above(0);
            Events.assertField(e, "timeSlice").isEqual(TIME_SLICE);
            Events.assertField(e, "pauseTarget").isEqual(MAX_GC_TIME);
        }

        recording.close();
    }
 
Example 11
Source File: TestRecordingCopy.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 {

        Recording original = new Recording();
        original.enable(SimpleEvent.class);

        Recording newCopy = original.copy(false);
        Asserts.assertEquals(newCopy.getState(), RecordingState.NEW);

        Recording newStoppedCopy = original.copy(true);
        Asserts.assertEquals(newStoppedCopy.getState(), RecordingState.NEW);

        original.start();

        SimpleEvent ev = new SimpleEvent();
        ev.id = EVENT_ID;
        ev.commit();

        // Verify a stopped copy
        Recording stoppedCopy = original.copy(true);
        Asserts.assertEquals(stoppedCopy.getState(), RecordingState.STOPPED);
        assertCopy(stoppedCopy, original);

        // Verify a running copy
        Recording runningCopy = original.copy(false);
        Asserts.assertEquals(runningCopy.getState(), RecordingState.RUNNING);
        assertCopy(runningCopy, original);

        original.stop();

        // Verify a stopped copy of a stopped
        stoppedCopy = original.copy(true);
        Asserts.assertEquals(stoppedCopy.getState(), RecordingState.STOPPED);
        assertCopy(stoppedCopy, original);

        // Clean-up
        original.close();
        runningCopy.stop();
        runningCopy.close();
        stoppedCopy.close();
    }
 
Example 12
Source File: TestEventTypes.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 {
    FlightRecorderMXBean bean = JmxHelper.getFlighteRecorderMXBean();
    FlightRecorder jfr = FlightRecorder.getFlightRecorder();

    Recording r = new Recording();
    r.enable(MyEvent.class);
    new MyEvent(); // triggers <clinit>
    List<EventTypeInfo> infos = bean.getEventTypes();
    List<EventType> types = jfr.getEventTypes();
    Asserts.assertFalse(infos.isEmpty(), "No EventTypeInfos found");
    verifyMyEventType(infos);
    assertSame(infos, types);
    r.close();
}
 
Example 13
Source File: TestDump.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 {
    Recording r = new Recording();
    r.enable(EventNames.OSInformation);
    r.start();
    r.stop();

    Path path = Paths.get(".", "my.jfr");
    r.dump(path);
    r.close();

    Asserts.assertTrue(Files.exists(path), "Recording file does not exist: " + path);
    Asserts.assertFalse(RecordingFile.readAllEvents(path).isEmpty(), "No events found");
}
 
Example 14
Source File: TestClassLoadingStatisticsEvent.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static RecordedEvent getCurrentEvent() throws Throwable {
    Recording recording = new Recording();
    recording.enable(EVENT_PATH);
    recording.start();
    recording.stop();
    List<RecordedEvent> events = Events.fromRecording(recording);
    Asserts.assertFalse(events.isEmpty(), "No events in recording");
    RecordedEvent event = events.get(0);
    return event;
}
 
Example 15
Source File: TestGetSizeToMem.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 {
    Path dest = Paths.get(".", "my.jfr");
    Recording r = new Recording();
    r.setToDisk(false);
    r.setDestination(dest);
    r.enable(EventNames.OSInformation);
    r.start();
    r.stop();
    r.close();
    assertTrue(Files.exists(dest), "TestGetSize recording missing: " + dest);
    System.out.printf("%s size: %d%n", dest, Files.size(dest));
    System.out.printf("r.getSize(): %d%n", r.getSize());
    Asserts.assertNotEquals(Files.size(dest), 0L, "File should not be empty");
    assertEquals(r.getSize(), 0L, "r.getSize() should be 0 after setToDisk(false)");
}
 
Example 16
Source File: TestBiasedLockRevocationEvents.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
static void testBulkRevocationNoRebias() throws Throwable {
    class MyLock {};

    Recording recording = new Recording();

    recording.enable(EventNames.BiasedLockClassRevocation);
    recording.start();

    Thread biasBreaker0 = triggerRevocation(BULK_REVOKE_THRESHOLD, MyLock.class);
    Thread biasBreaker1 = triggerRevocation(BULK_REVOKE_THRESHOLD, MyLock.class);

    recording.stop();
    List<RecordedEvent> events = Events.fromRecording(recording);
    Asserts.assertEQ(events.size(), 2);

    RecordedEvent eventRebias = events.get(0);
    Events.assertEventThread(eventRebias, biasBreaker0);
    Events.assertField(eventRebias, "disableBiasing").equal(false);

    RecordedEvent eventNoRebias = events.get(1);
    Events.assertEventThread(eventNoRebias, biasBreaker1);
    Events.assertField(eventNoRebias, "disableBiasing").equal(true);

    RecordedClass lockClassRebias = eventRebias.getValue("revokedClass");
    Asserts.assertEquals(lockClassRebias.getName(), MyLock.class.getName());
    RecordedClass lockClassNoRebias = eventNoRebias.getValue("revokedClass");
    Asserts.assertEquals(lockClassNoRebias.getName(), MyLock.class.getName());

    validateStackTrace(eventRebias.getStackTrace());
    validateStackTrace(eventNoRebias.getStackTrace());
}
 
Example 17
Source File: TestCompilerConfig.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 {
    Recording recording = new Recording();
    recording.enable(EVENT_NAME);
    recording.start();
    recording.stop();

    List<RecordedEvent> events = Events.fromRecording(recording);
    Events.hasEvents(events);
    for (RecordedEvent event : events) {
        System.out.println("Event:" + event);
        Events.assertField(event, "threadCount").atLeast(0);
        Events.assertField(event, "tieredCompilation");
    }
}
 
Example 18
Source File: TestGetSizeToMem.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Throwable {
    Path dest = Paths.get(".", "my.jfr");
    Recording r = new Recording();
    r.setToDisk(false);
    r.setDestination(dest);
    r.enable(EventNames.OSInformation);
    r.start();
    r.stop();
    r.close();
    assertTrue(Files.exists(dest), "TestGetSize recording missing: " + dest);
    System.out.printf("%s size: %d%n", dest, Files.size(dest));
    System.out.printf("r.getSize(): %d%n", r.getSize());
    Asserts.assertNotEquals(Files.size(dest), 0L, "File should not be empty");
    assertEquals(r.getSize(), 0L, "r.getSize() should be 0 after setToDisk(false)");
}
 
Example 19
Source File: ObjectCountAfterGCEvent.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void test(String gcName) throws Exception {
    Recording recording = new Recording();
    recording.enable(objectCountEventPath);
    recording.enable(gcEventPath);
    recording.enable(heapSummaryEventPath);

    ObjectCountEventVerifier.createTestData();
    recording.start();
    System.gc();
    System.gc();
    recording.stop();

    System.out.println("gcName=" + gcName);
    for (RecordedEvent event : Events.fromRecording(recording)) {
        System.out.println("Event: " + event);
    }

    List<RecordedEvent> events= Events.fromRecording(recording);
    Optional<RecordedEvent> gcEvent = events.stream()
                            .filter(e -> isMySystemGc(e, gcName))
                            .findFirst();
    Asserts.assertTrue(gcEvent.isPresent(), "No event System.gc event of type " + gcEventPath);
    System.out.println("Found System.gc event: " + gcEvent.get());
    int gcId = Events.assertField(gcEvent.get(), "gcId").getValue();

    List<RecordedEvent> objCountEvents = events.stream()
                            .filter(e -> Events.isEventType(e, objectCountEventPath))
                            .filter(e -> isGcId(e, gcId))
                            .collect(Collectors.toList());
    Asserts.assertFalse(objCountEvents.isEmpty(), "No objCountEvents for gcId=" + gcId);

    Optional<RecordedEvent> heapSummaryEvent = events.stream()
                            .filter(e -> Events.isEventType(e, heapSummaryEventPath))
                            .filter(e -> isGcId(e, gcId))
                            .filter(e -> "After GC".equals(Events.assertField(e, "when").getValue()))
                            .findFirst();
    Asserts.assertTrue(heapSummaryEvent.isPresent(), "No heapSummary for gcId=" + gcId);
    System.out.println("Found heapSummaryEvent: " + heapSummaryEvent.get());

    Events.assertField(heapSummaryEvent.get(), "heapUsed").atLeast(0L).getValue();
    ObjectCountEventVerifier.verify(objCountEvents);
}
 
Example 20
Source File: TestIsEnabledMultiple.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
private static void assertEnabled(RecState recStateA, RecState recStateB, EnableState enableStateA, EnableState enableStateB) {

        Recording a = new Recording();
        Recording b = new Recording();
        assertEnablement(false); // no recording running

        if (enableStateA == EnableState.Disabled) {
            a.disable(MyEvent.class);
        }
        if (enableStateA == EnableState.Enabled) {
            a.enable(MyEvent.class);
        }
        if (enableStateB == EnableState.Disabled) {
            b.disable(MyEvent.class);
        }
        if (enableStateB == EnableState.Enabled) {
            b.enable(MyEvent.class);
        }
        if ( enableStateA == EnableState.Disabled && recStateA == RecState.Running) {
            if ( enableStateB == EnableState.Disabled && recStateB == RecState.Running) {
                System.out.println();
            }
        }
        if (recStateA == RecState.Running) {
            a.start();
        }
        if (recStateB == RecState.Running) {
            b.start();
        }

        System.out.println("Recording a is " + a.getState() + ". Event is " + enableStateA);
        System.out.println("Recording b is " + b.getState() + ". Event is " + enableStateB);
        // an event is enabled if at least one recording is running
        // and the event is on by default or has been enabled.
        boolean aEnabled = recStateA == RecState.Running && enableStateA == EnableState.Enabled;
        boolean bEnabled = recStateB == RecState.Running && enableStateB == EnableState.Enabled;
        boolean enabled = aEnabled || bEnabled;
        System.out.println("Expected enablement: " + enabled);
        System.out.println();
        assertEnablement(enabled);
        if (recStateA == RecState.Running) {
            a.stop();
        }
        if (recStateB == RecState.Running) {
            b.stop();
        }
        assertEnablement(false); // no recording running
        a.close();
        b.close();
    }