jdk.jfr.consumer.RecordedEvent Java Examples

The following examples show how to use jdk.jfr.consumer.RecordedEvent. 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: TestHeapSummaryEventConcurrentCMS.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    Recording recording = new Recording();
    recording.enable(EventNames.GarbageCollection).withThreshold(Duration.ofMillis(0));
    recording.enable(EventNames.GCHeapSummary).withThreshold(Duration.ofMillis(0));

    recording.start();
    // Need several GCs to ensure at least one heap summary event from concurrent CMS
    GCHelper.callSystemGc(6, true);
    recording.stop();

    // Remove first and last GCs which can be incomplete
    List<RecordedEvent> events = GCHelper.removeFirstAndLastGC(Events.fromRecording(recording));
    Asserts.assertFalse(events.isEmpty(), "No events found");
    for (RecordedEvent event : events) {
        System.out.println("Event: " + event);
        if (!isCmsGcEvent(event)) {
            continue;
        }
        int gcId = Events.assertField(event, "gcId").getValue();
        verifyHeapSummary(events, gcId, "Before GC");
        verifyHeapSummary(events, gcId, "After GC");
    }
}
 
Example #2
Source File: TestCMSConcurrentModeFailureEvent.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 {
    String[] vmFlags = {"-Xmx128m", "-XX:MaxTenuringThreshold=0", "-Xloggc:testCMSGC.log", "-verbose:gc",
        "-XX:+UseConcMarkSweepGC", "-XX:+UnlockExperimentalVMOptions", "-XX:-UseFastUnorderedTimeStamps"};

    if (!ExecuteOOMApp.execute(EVENT_SETTINGS_FILE, JFR_FILE, vmFlags, BYTES_TO_ALLOCATE)) {
        System.out.println("OOM happened in the other thread(not test thread). Skip test.");
        // Skip test, process terminates due to the OOME error in the different thread
        return;
    }

    Optional<RecordedEvent> event = RecordingFile.readAllEvents(Paths.get(JFR_FILE)).stream().findFirst();
    if (event.isPresent()) {
        Asserts.assertEquals(EVENT_NAME, event.get().getEventType().getName(), "Wrong event type");
    } else {
        // No event received. Check if test did trigger the event.
        boolean isEventTriggered = fileContainsString("testCMSGC.log", "concurrent mode failure");
        System.out.println("isEventTriggered=" +isEventTriggered);
        Asserts.assertFalse(isEventTriggered, "Event found in log, but not in JFR");
    }
}
 
Example #3
Source File: TestExceptionEvents.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void checkThrowableEvents(List<RecordedEvent> events, String eventName,
    int excpectedEvents, Class<?> expectedClass, String expectedMessage) throws Exception {
    int count = 0;
    for(RecordedEvent event : events) {
        if (Events.isEventType(event, eventName)) {
            String message = Events.assertField(event, "message").getValue();
            if (expectedMessage.equals(message)) {
                RecordedThread t = event.getThread();
                String threadName = t.getJavaName();
                if (threadName != null && threadName.equals(Thread.currentThread().getName())) {
                    RecordedClass jc = event.getValue("thrownClass");
                    if (jc.getName().equals(expectedClass.getName())) {
                        count++;
                    }
                }
            }
        }
    }
    Asserts.assertEquals(count, excpectedEvents, "Wrong event count for type " + eventName);
}
 
Example #4
Source File: TestRecordedEventGetThread.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 {
    Thread currentThread = Thread.currentThread();
    currentThread.setName(MY_THREAD_NAME);
    long expectedThreadId = currentThread.getId();

    Recording r = new Recording();
    r.start();
    SimpleEvent t = new SimpleEvent();
    t.commit();
    r.stop();
    List<RecordedEvent> events = Events.fromRecording(r);
    r.close();
    Events.hasEvents(events);
    RecordedEvent event = events.get(0);
    RecordedThread recordedThread = event.getThread();

    Asserts.assertNotNull(recordedThread);
    Asserts.assertEquals(recordedThread.getJavaName(), MY_THREAD_NAME);
    Asserts.assertEquals(recordedThread.getJavaThreadId(), expectedThreadId);
    Asserts.assertNotNull(recordedThread.getOSThreadId());
    Asserts.assertNotNull(recordedThread.getId());
    Asserts.assertEquals(recordedThread.getOSName(), MY_THREAD_NAME);
}
 
Example #5
Source File: TestActiveSettingEvent.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static void testUnregistered() throws Exception {
    FlightRecorder.register(MyEvent.class);
    EventType type = EventType.getEventType(MyEvent.class);
    FlightRecorder.unregister(MyEvent.class);
    try (Recording recording = new Recording()) {
        recording.enable(ACTIVE_SETTING_EVENT_NAME);
        recording.start();
        MyEvent m = new MyEvent();
        m.commit();
        recording.stop();
        List<RecordedEvent> events = Events.fromRecording(recording);
        Events.hasEvents(events);
        assertNotSetting(events, type, "threshold", "0 ns");
        assertNotSetting(events, type, "enabled", "true");
        assertNotSetting(events, type, "stackTrace", "true");
    }
}
 
Example #6
Source File: GCEventAll.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private void verifyPhaseEvents(List<GCHelper.GcBatch> batches) {
    for (GCHelper.GcBatch batch : batches) {
        for(RecordedEvent event : batch.getEvents()) {
            if (event.getEventType().getName().contains(GCHelper.pauseLevelEvent)) {
                Instant batchStartTime = batch.getEndEvent().getStartTime();
                Asserts.assertGreaterThanOrEqual(
                    event.getStartTime(), batchStartTime, "Phase startTime >= batch startTime. Event:" + event);

                // Duration for event "vm/gc/phases/pause" must be >= 1. Other phase event durations must be >= 0.
                Duration minDuration = Duration.ofNanos(GCHelper.event_phases_pause.equals(event.getEventType().getName()) ? 1 : 0);
                Duration duration = event.getDuration();
                Asserts.assertGreaterThanOrEqual(duration, minDuration, "Wrong duration. Event:" + event);
            }
        }
    }
}
 
Example #7
Source File: TestInitialEnvironmentVariable.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 {
    Map<String, String> env = new HashMap<>();
    env.put("keytest1", "value1");
    env.put("keytest2", "value 2");

    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);
        String key = Events.assertField(event, "key").notNull().getValue();
        String value = Events.assertField(event, "value").notNull().getValue();
        if (env.containsKey(key)) {
            assertEquals(value, env.get(key), "Wrong value for key: " + key);
            env.remove(key);
        }
    }
    assertTrue(env.isEmpty(), "Missing env keys " + env.keySet());
}
 
Example #8
Source File: TestThreadAllocationEvent.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
  * Verify that total allocated bytes in JFR event approximately matches the value in ThreadMXBean.
  */
private static void verifyTotalAllocated(List<RecordedEvent> events, AllocatorThread[] threads) {
    boolean[] isEventFound = new boolean[threads.length];
    for (RecordedEvent event : events) {
        RecordedThread rt = Events.assertField(event, "thread").notNull().getValue();
        String name = rt.getJavaName();
        for (int i = 0; i < threads.length; ++i) {
            if (name.equals(threads[i].getName())) {
                System.out.println("Event:" + event);
                long maxAllowed = threads[i].totalAllocated + allowedTotalAllocatedDiff;
                long minAllowed = Math.max(0, threads[i].totalAllocated - allowedTotalAllocatedDiff);
                Events.assertField(event, "allocated").atLeast(minAllowed).atMost(maxAllowed);
                isEventFound[i] = true;
            }
        }
    }
    for (int i = 0; i < threads.length; ++i) {
        assertTrue(isEventFound[i], "No event for thread id " + i);
    }
}
 
Example #9
Source File: TestRandomAccessFileThread.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static void verifyReadWriteTimes(List<RecordedEvent> readEvents, List<RecordedEvent> writeEvents) {
    List<RecordedEvent> events = new ArrayList<>();
    events.addAll(readEvents);
    events.addAll(writeEvents);
    events.sort(new EventComparator());

    int countRead = 0;
    int countWrite = 0;
    for (RecordedEvent event : events) {
        if (Events.isEventType(event, IOEvent.EVENT_FILE_READ)) {
            ++countRead;
        } else {
            ++countWrite;
        }
        // We can not read from the file before it has been written.
        // This check verifies that times of different threads are correct.
        // Since the read and write are from different threads, it is possible that the read
        // is committed before the same write.
        // But read operation may only be 1 step ahead of the write operation.
        Asserts.assertLessThanOrEqual(countRead, countWrite + 1, "read must be after write");
    }
}
 
Example #10
Source File: TestThreadAllocationEvent.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
* Verify that the allocated value never decreases.
* We only compare our own allocator threads. The reason for that is that other threads
* may start/stop at any time, and we do not know if other thread names are unique.
*/
private static void verifyAllocationsNotDecreasing(List<RecordedEvent> events, AllocatorThread[] threads) {
    Collections.sort(events, (u,v) -> u.getEndTime().compareTo(v.getEndTime()));
    long[] prevAllocated = new long[threads.length];
    for (RecordedEvent event : events) {
        RecordedThread rt = Events.assertField(event, "thread").notNull().getValue(); // Check that we have a thread.
        String name = rt.getJavaName();
        for (int i = 0; i < threads.length; i++) {
            if (name.equals(threads[i].getName())) {
                long curr = Events.assertField(event, "allocated").atLeast(prevAllocated[i]).getValue();
                prevAllocated[i] = curr;
            }
        }
    }

    for (int i = 0; i < threads.length; i++) {
        assertGreaterThan(prevAllocated[i], 0L, "No allocations for thread " + threads[i].getName());
    }
}
 
Example #11
Source File: ObjectCountEventVerifier.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void verify(List<RecordedEvent> objectCountEvents) throws Exception {
    Asserts.assertFalse(objectCountEvents.isEmpty(), "Expected at least one object count event");
    // Object count events should be sent only for those classes which instances occupy over 0.5%
    // of the heap. Therefore there can't be more than 200 events
    Asserts.assertLessThanOrEqual(objectCountEvents.size(), 200, "Expected at most 200 object count events");

    HashMap<String, Long> numInstancesOfClass = new HashMap<String, Long>();
    HashMap<String, Long> sizeOfInstances = new HashMap<String, Long>();

    for (RecordedEvent event : objectCountEvents) {
        String className = Events.assertField(event, "objectClass.name").notEmpty().getValue();
        long count = Events.assertField(event, "count").atLeast(0L).getValue();
        long totalSize = Events.assertField(event, "totalSize").atLeast(1L).getValue();
        System.out.println(className);
        numInstancesOfClass.put(className, count);
        sizeOfInstances.put(className, totalSize);
    }
    System.out.println(numInstancesOfClass);
    final String fooArrayName = "[Ljdk/jfr/event/gc/objectcount/Foo;";
    Asserts.assertTrue(numInstancesOfClass.containsKey(fooArrayName), "Expected an event for the Foo array");
    Asserts.assertEquals(sizeOfInstances.get(fooArrayName), expectedFooArraySize(Constants.oneMB), "Wrong size of the Foo array");
}
 
Example #12
Source File: PromotionFailedEvent.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void test(String testName, String[] vmFlags) throws Throwable {
    String jfr_file = testName + ".jfr";

    if (!ExecuteOOMApp.execute(EVENT_SETTINGS_FILE, jfr_file, vmFlags, BYTES_TO_ALLOCATE)) {
        System.out.println("OOM happened in the other thread(not test thread). Skip test.");
        // Skip test, process terminates due to the OOME error in the different thread
        return;
    }

    // This test can not always trigger the expected event.
    // Test is ok even if no events found.
    List<RecordedEvent> events = RecordingFile.readAllEvents(Paths.get(jfr_file));
    for (RecordedEvent event : events) {
        System.out.println("Event: " + event);
        long smallestSize = Events.assertField(event, "promotionFailed.smallestSize").atLeast(1L).getValue();
        long firstSize = Events.assertField(event, "promotionFailed.firstSize").atLeast(smallestSize).getValue();
        long totalSize = Events.assertField(event, "promotionFailed.totalSize").atLeast(firstSize).getValue();
        long objectCount = Events.assertField(event, "promotionFailed.objectCount").atLeast(1L).getValue();
        Asserts.assertLessThanOrEqual(smallestSize * objectCount, totalSize, "smallestSize * objectCount <= totalSize");
    }
}
 
Example #13
Source File: TestG1EvacMemoryStatsEvent.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void runTest(String event_name) 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);
        for (RecordedEvent e : all) {
            Events.assertField(e, "statistics.gcId").above(0);
        }

        recording.close();
    }
 
Example #14
Source File: TestCPUInformation.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<RecordedEvent> events = Events.fromRecording(recording);
    Events.hasEvents(events);
    for (RecordedEvent event : events) {
        System.out.println("Event: " + event);
        Events.assertField(event, "hwThreads").atLeast(1);
        Events.assertField(event, "cores").atLeast(1);
        Events.assertField(event, "sockets").atLeast(1);
        Events.assertField(event, "cpu").containsAny("Intel", "AMD", "Unknown x86", "sparc", "ARM", "PPC", "PowerPC", "AArch64", "s390");
        Events.assertField(event, "description").containsAny("Intel", "AMD", "Unknown x86", "SPARC", "ARM", "PPC", "PowerPC", "AArch64", "zArch");
    }
}
 
Example #15
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 #16
Source File: TestCompilerInlining.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void testLevel(Map<Call, Boolean> expectedResult, int level) throws IOException {
    System.out.println("****** Testing level " + level + " *******");
    Recording r = new Recording();
    r.enable(EventNames.CompilerInlining);
    r.start();
    WHITE_BOX.enqueueMethodForCompilation(ENTRY_POINT, level);
    WHITE_BOX.deoptimizeMethod(ENTRY_POINT);
    r.stop();
    System.out.println("Expected:");

    List<RecordedEvent> events = Events.fromRecording(r);
    Set<Call> foundEvents = new HashSet<>();
    int foundRelevantEvent = 0;
    for (RecordedEvent event : events) {
        RecordedMethod callerObject = event.getValue("caller");
        RecordedObject calleeObject = event.getValue("callee");
        MethodDesc caller = methodToMethodDesc(callerObject);
        MethodDesc callee = ciMethodToMethodDesc(calleeObject);
        // only TestCase.* -> TestCase.* OR TestCase.* -> Object.<init> are tested/filtered
        if (caller.className.equals(TEST_CASE_CLASS_NAME) && (callee.className.equals(TEST_CASE_CLASS_NAME)
                || (callee.className.equals("java/lang/Object") && callee.methodName.equals("<init>")))) {
            System.out.println(event);
            boolean succeeded = (boolean) event.getValue("succeeded");
            int bci = Events.assertField(event, "bci").atLeast(0).getValue();
            Call call = new Call(caller, callee, bci);
            foundRelevantEvent++;
            Boolean expected = expectedResult.get(call);
            Asserts.assertNotNull(expected, "Unexpected inlined call : " + call);
            Asserts.assertEquals(expected, succeeded, "Incorrect result for " + call);
            Asserts.assertTrue(foundEvents.add(call), "repeated event for " + call);
        }
    }
    Asserts.assertEquals(foundRelevantEvent, expectedResult.size(), String.format("not all events found at lavel %d. " + "found = '%s'. expected = '%s'", level, events, expectedResult.keySet()));
    System.out.println();
    System.out.println();
}
 
Example #17
Source File: OldObjects.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static Predicate<RecordedEvent> hasFieldName(String fieldName) {
    if (fieldName != null) {
        return e -> {
            RecordedObject referrer = e.getValue("object.referrer");
            return referrer != null ? referrer.hasField("field.name") && referrer.getValue("field.name").equals(fieldName) : false;
        };
    } else {
        return e -> true;
    }
}
 
Example #18
Source File: IOHelper.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void verifyEqualsInOrder(List<RecordedEvent> events, List<IOEvent> expectedEvents) throws Throwable {
    List<IOEvent> actualEvents = getTestEvents(events, expectedEvents);
    try {
        assertEquals(actualEvents.size(), expectedEvents.size(), "Wrong number of events.");
        for (int i = 0; i < actualEvents.size(); ++i) {
            assertEquals(actualEvents.get(i), expectedEvents.get(i), "Wrong event at pos " + i);
        }
    } catch (Throwable t) {
        logEvents(actualEvents, expectedEvents);
        throw t;
    }
}
 
Example #19
Source File: TestVMInfoEvent.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 {
    RuntimeMXBean mbean = ManagementFactory.getRuntimeMXBean();
    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, "jvmName").equal(mbean.getVmName());
        String jvmVersion = Events.assertField(event, "jvmVersion").notEmpty().getValue();
        if (!jvmVersion.contains(mbean.getVmVersion())) {
            Asserts.fail(String.format("%s does not contain %s", jvmVersion, mbean.getVmVersion()));
        }

        String jvmArgs = Events.assertField(event, "jvmArguments").notNull().getValue();
        String jvmFlags = Events.assertField(event, "jvmFlags").notNull().getValue();
        Long pid = Events.assertField(event, "pid").atLeast(0L).getValue();
        Asserts.assertEquals(pid, ProcessTools.getProcessId());
        String eventArgs = (jvmFlags.trim() + " " + jvmArgs).trim();
        String beanArgs = mbean.getInputArguments().stream().collect(Collectors.joining(" "));
        Asserts.assertEquals(eventArgs, beanArgs, "Wrong inputArgs");

        final String javaCommand = mbean.getSystemProperties().get("sun.java.command");
        Events.assertField(event, "javaArguments").equal(javaCommand);
        Events.assertField(event, "jvmStartTime").equal(mbean.getStartTime());
    }
}
 
Example #20
Source File: TestThreadContextSwitches.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 {
    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, "switchRate").atLeast(0.0f);
    }
}
 
Example #21
Source File: TestHiddenMethod.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static boolean hasHiddenStackFrame(RecordedEvent event) throws Throwable {
    RecordedStackTrace stacktrace = event.getStackTrace();
    List<RecordedFrame> frames = stacktrace.getFrames();
    assertFalse(frames.isEmpty(), "Stacktrace frames was empty");
    for (RecordedFrame frame : frames) {
        if (frame.getMethod().isHidden()) {
            return true;
        }
    }
    return false;
}
 
Example #22
Source File: GCHelper.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public boolean addEvent(RecordedEvent event) {
    if (!events.isEmpty()) {
        assertEquals(getGcId(), GCHelper.getGcId(event), "Wrong gcId in event. Error in test code.");
    }
    boolean isEndEvent = event_garbage_collection.equals(event.getEventType().getName());
    if (isEndEvent) {
        // Verify that we have not already got a garbage_collection event with this gcId.
        assertNull(getEndEvent(), String.format("Multiple %s for gcId %d", event_garbage_collection, getGcId()));
    }
    events.add(event);
    return isEndEvent;
}
 
Example #23
Source File: TestObjectDescription.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static Set<String> extractObjectDecriptions(List<RecordedEvent> events) {
    Set<String> objectDescriptions = new HashSet<>();
    for (RecordedEvent e : events) {
        objectDescriptions.addAll(extractObjectDescriptions(e.getValue("object")));
    }
    return objectDescriptions;
}
 
Example #24
Source File: TestMetadataRetention.java    From dragonwell8_jdk 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 #25
Source File: TestExceptionEvents.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void checkStatisticsEvent(List<RecordedEvent> events, long minCount) throws Exception {
    // Events are not guaranteed to be in chronological order, take highest value.
    long count = -1;
    for(RecordedEvent event : events) {
        if (Events.isEventType(event, EXCEPTION_STATISTICS_PATH)) {
            System.out.println("Event: " + event);
            count = Math.max(count, Events.assertField(event, "throwables").getValue());
            System.out.println("count=" +  count);
        }
    }
    Asserts.assertTrue(count != -1, "No events of type " + EXCEPTION_STATISTICS_PATH);
    Asserts.assertGreaterThanOrEqual(count, minCount, "Too few exception count in statistics event");
}
 
Example #26
Source File: TestEnableDisable.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 {
    List<MyEvent> expectedEvents = new ArrayList<>();
    Recording r = new Recording();

    r.start();
    createEvent(expectedEvents, true); // id=0 Custom event classes are enabled by default.

    r.disable(MyEvent.class);
    createEvent(expectedEvents, false); // id=1
    r.enable(MyEvent.class);
    createEvent(expectedEvents, true);  // id=2

    // enable/disable by event setting name
    String eventSettingName = String.valueOf(EventType.getEventType(MyEvent.class).getId());
    System.out.println("eventSettingName=" + eventSettingName);

    r.disable(eventSettingName);
    createEvent(expectedEvents, false); // id=3
    r.enable(eventSettingName);
    createEvent(expectedEvents, true);

    r.stop();
    createEvent(expectedEvents, false);

    Iterator<MyEvent> expectedIterator = expectedEvents.iterator();
    for (RecordedEvent event : Events.fromRecording(r)) {
        System.out.println("event.id=" + Events.assertField(event, "id").getValue());
        Asserts.assertTrue(expectedIterator.hasNext(), "Found more events than expected");
        Events.assertField(event, "id").equal(expectedIterator.next().id);
    }
    Asserts.assertFalse(expectedIterator.hasNext(), "Did not find all expected events.");

    r.close();
}
 
Example #27
Source File: TestLargeJavaEvent512k.java    From TencentKona-8 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 #28
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 #29
Source File: TestPhysicalMemoryEvent.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);
    recording.start();
    recording.stop();
    List<RecordedEvent> events = Events.fromRecording(recording);
    Events.hasEvents(events);
    for (RecordedEvent event : events) {
        System.out.println("Event: " + event);
        long totalSize = Events.assertField(event, "totalSize").atLeast(0L).getValue();
        Events.assertField(event, "usedSize").atLeast(0L).atMost(totalSize);
    }
}
 
Example #30
Source File: TestExtends.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static RecordedEvent findEvent(Recording r, String name) throws Exception {
    for (RecordedEvent re : Events.fromRecording(r)) {
        if (re.getEventType().getName().equals(name)) {
            return re;
        }
    }
    throw new Exception("Event type hierarchy exist, but missing event " + name + " from recording");
}