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

The following examples show how to use jdk.jfr.Recording#stop() . 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: TestDestToDiskTrue.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 {
    Path dest = Paths.get(".", "my.jfr");
    Recording r = new Recording();
    r.enable(EventNames.OSInformation);
    r.setToDisk(true);
    r.setDestination(dest);
    Asserts.assertEquals(dest, r.getDestination(), "Wrong get/set destination");
    r.start();
    r.stop();

    Asserts.assertEquals(dest, r.getDestination(), "Wrong get/set destination after stop");

    Asserts.assertTrue(Files.exists(dest), "No recording file: " + dest);
    List<RecordedEvent> events = RecordingFile.readAllEvents(dest);
    Asserts.assertFalse(events.isEmpty(), "No event found");
    System.out.printf("Found event %s%n", events.get(0).getEventType().getName());
    System.out.printf("File size=%d, getSize()=%d%n", Files.size(dest), r.getSize());
    assertEquals(r.getSize(), 0L, "getSize() should return 0, chunks should have be released at stop");
    Asserts.assertNotEquals(Files.size(dest), 0L, "File length 0. Should at least be some bytes");
    r.close();
}
 
Example 2
Source File: TestDumpLongPath.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 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 3
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 4
Source File: TestRetransform.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 {
    EventType type = EventType.getEventType(TestEvent.class);
    if (type.isEnabled()) {
        Asserts.fail("Expected event to be disabled before recording start");
    }
    Recording r = new Recording();
    r.start();
    if (!type.isEnabled()) {
        Asserts.fail("Expected event to be enabled during recording");
    }
    TestEvent testEvent = new TestEvent();
    testEvent.commit();
    loadEventClassDuringRecording();
    r.stop();
    if (type.isEnabled()) {
        Asserts.fail("Expected event to be disabled after recording stopped");
    }
    Events.hasEvent(r, SimpleEvent.class.getName());
    Events.hasEvent(r, TestEvent.class.getName());
}
 
Example 5
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 6
Source File: TestAddListenerTwice.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 {
    MyListener listener = new MyListener();

    FlightRecorder.addListener(listener);
    FlightRecorder.addListener(listener);

    Recording r1 = new Recording();
    r1.start();
    listener.verifyState(2, RecordingState.RUNNING);

    FlightRecorder.removeListener(listener); // Should still get callback to one listener.
    r1.stop();
    listener.verifyState(3, RecordingState.STOPPED);
    r1.close();
    listener.verifyState(4, RecordingState.CLOSED);
}
 
Example 7
Source File: TestState.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 {
    Recording r = new Recording();
    CommonHelper.verifyRecordingState(r, RecordingState.NEW);
    r.scheduleStart(Duration.ofHours(2));
    CommonHelper.verifyRecordingState(r, RecordingState.DELAYED);
    r.start();
    CommonHelper.verifyRecordingState(r, RecordingState.RUNNING);
    r.stop();
    CommonHelper.verifyRecordingState(r, RecordingState.STOPPED);
    r.close();
    CommonHelper.verifyRecordingState(r, RecordingState.CLOSED);
}
 
Example 8
Source File: TestEnableDisable.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 {
    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 9
Source File: TestThreadContextSwitches.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);
        Events.assertField(event, "switchRate").atLeast(0.0f);
    }
}
 
Example 10
Source File: TestCPUTimeStampCounter.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, "fastTimeEnabled");
        Events.assertField(event, "fastTimeAutoEnabled");
        Events.assertField(event, "osFrequency").atLeast(0L);
        Events.assertField(event, "fastTimeFrequency").atLeast(0L);
    }
}
 
Example 11
Source File: TestCompilerInlining.java    From openjdk-jdk8u 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 12
Source File: TestRecorderListener.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void testDefaultrecordingStateChangedListener() {
    FlightRecorder.addListener(new DummyListener());
    Recording recording = new Recording();
    recording.start();
    recording.stop();
    recording.close();
}
 
Example 13
Source File: TestRecordedObject.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static RecordedObject makeRecordedObject() throws IOException {
    Recording r = new Recording();
    r.start();
    EventWithValues t = new EventWithValues();
    t.commit();
    r.stop();
    List<RecordedEvent> events = Events.fromRecording(r);
    Events.hasEvents(events);
    return events.get(0);
}
 
Example 14
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 15
Source File: TestAllocInNewTLAB.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).withThreshold(Duration.ofMillis(0));

    recording.start();
    System.gc();
    for (int i = 0; i < OBJECTS_TO_ALLOCATE; ++i) {
        tmp = new byte[OBJECT_SIZE - BYTE_ARRAY_OVERHEAD];
    }
    recording.stop();

    int countAllTlabs = 0;  // Count all matching tlab allocations.
    int countFullTlabs = 0; // Count matching tlab allocations with full tlab size.
    for (RecordedEvent event : Events.fromRecording(recording)) {
        if (!EVENT_NAME.equals(event.getEventType().getName())) {
            continue;
        }
        System.out.println("Event:" + event);

        long allocationSize = Events.assertField(event, "allocationSize").atLeast(1L).getValue();
        long tlabSize = Events.assertField(event, "tlabSize").atLeast(allocationSize).getValue();
        String className = Events.assertField(event, "objectClass.name").notEmpty().getValue();

        boolean isMyEvent = Thread.currentThread().getId() == event.getThread().getJavaThreadId()
             && className.equals(BYTE_ARRAY_CLASS_NAME)
             && (allocationSize == OBJECT_SIZE || allocationSize == OBJECT_SIZE_ALT);
        if (isMyEvent) {
            countAllTlabs++;
            if (tlabSize == INITIAL_TLAB_SIZE + OBJECT_SIZE || tlabSize == INITIAL_TLAB_SIZE + OBJECT_SIZE_ALT) {
                countFullTlabs++;
            }
        }
    }

    int minCount = (int) floor(OBJECTS_TO_ALLOCATE * 0.80);
    assertGreaterThanOrEqual(countAllTlabs, minCount, "Too few tlab objects allocated");
    assertLessThanOrEqual(countAllTlabs, OBJECTS_TO_ALLOCATE, "Too many tlab objects allocated");

    // For most GCs we expect the size of each tlab to be
    // INITIAL_TLAB_SIZE + ALLOCATION_SIZE, but that is not always true for G1.
    // G1 may use a smaller tlab size if the full tlab does not fit in the
    // selected memory region.
    //
    // For example, if a G1 memory region has room for 4.7 tlabs,
    // then the first 4 tlabs will have the expected size,
    // but the fifth tlab would only have a size of 0.7*expected.
    //
    // It is only the last tlab in each region that has a smaller size.
    // This means that at least 50% of the allocated tlabs should
    // have the expected size (1 full tlab, and 1 fractional tlab).
    assertGreaterThanOrEqual(2*countFullTlabs, countAllTlabs, "Too many fractional tlabs.");
}
 
Example 16
Source File: AllocationStackTrace.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Performs JFR recording, GC provocation/detection and stacktrace
 * verification for JFR event.
 *
 * @param bean MX bean for desired GC
 * @param memory allocator for desired type of allocations
 * @param expectedStack array of expected frames
 * @throws Exception
 */
private static boolean allocAndCheck(GarbageCollectorMXBean bean, MemoryAllocator memory,
        String[] expectedStack) throws Exception {
    String threadName = Thread.currentThread().getName();
    String event = EventNames.AllocationRequiringGC;

    Recording r = new Recording();
    r.enable(event).withStackTrace();
    r.start();

    long prevCollectionCount = bean.getCollectionCount();
    long collectionCount = -1;

    long iterationCount = 0;

    do {
        memory.allocate();
        collectionCount = bean.getCollectionCount();
        iterationCount++;
    } while (collectionCount == prevCollectionCount);

    System.out.println("Allocation num: " + iterationCount);
    System.out.println("GC detected: " + collectionCount);

    r.stop();
    List<RecordedEvent> events = Events.fromRecording(r);

    System.out.println("JFR GC events found: " + events.size());

    // Find any event that matched the expected stack trace
    for (RecordedEvent e : events) {
        System.out.println("Event: " + e);
        RecordedThread thread = e.getThread();
        String eventThreadName = thread.getJavaName();
        if (!threadName.equals(eventThreadName)) {
            continue;
        }
        if (matchingStackTrace(e.getStackTrace(), expectedStack)) {
            return true;
        }
    }
    return false;
}
 
Example 17
Source File: TestRecordedClassLoader.java    From dragonwell8_jdk 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).withoutStackTrace();
    TestClassLoader cl = new TestClassLoader();
    recording.start();
    cl.loadClass(TEST_CLASS_NAME);
    recording.stop();

    List<RecordedEvent> events = Events.fromRecording(recording);
    boolean isDefined = false;
    System.out.println(events);
    for (RecordedEvent event : events) {
        RecordedClass definedClass = event.getValue("definedClass");
        if (TEST_CLASS_NAME.equals(definedClass.getName())) {
            System.out.println(event);

            // get the RecordedClassLoader from the RecordedClass, the "definedClass"
            RecordedClassLoader definingClassLoader = definedClass.getClassLoader();
            Asserts.assertNotNull(definingClassLoader, "Defining Class Loader should not be null");

            // invoke RecordedClassLoader.getType() in order to validate the type of the RecordedClassLoader
            RecordedClass definingClassLoaderType = definingClassLoader.getType();
            Asserts.assertNotNull(definingClassLoaderType, "The defining Class Loader type should not be null");

            // verify matching types
            Asserts.assertEquals(cl.getClass().getName(), definingClassLoaderType.getName(),
                "Expected type " + cl.getClass().getName() + ", got type " + definingClassLoaderType.getName());

            // get a RecordedClassLoader directly from the "definingClassLoader" field as well
            RecordedClassLoader definingClassLoaderFromField = event.getValue("definingClassLoader");
            Asserts.assertNotNull(definingClassLoaderFromField,
                "Defining Class Loader instantatiated from field should not be null");

            // ensure that the class loader instance used in the test actually has a name
            /** unsupport now
            Asserts.assertNotNull(cl.getName(),
                "Expected a valid name for the TestClassLoader");

            // invoke RecordedClassLoader.getName() to get the name of the class loader instance
            Asserts.assertEquals(cl.getName(), definingClassLoader.getName(),
                "Defining Class Loader should have the same name as the original class loader");
            Asserts.assertEquals(definingClassLoaderFromField.getName(), definingClassLoader.getName(),
                "Defining Class Loader representations should have the same class loader name");
            */

            // invoke uniqueID()
            Asserts.assertGreaterThan(definingClassLoader.getId(), 0L, "Invalid id assignment");

            // second order class loader information ("check class loader of the class loader")
            RecordedClassLoader classLoaderOfDefClassLoader = definingClassLoaderType.getClassLoader();
            Asserts.assertNotNull(classLoaderOfDefClassLoader,
                "The class loader for the definining class loader should not be null");
            /** unsupport now
            Asserts.assertEquals(cl.getClass().getClassLoader().getName(), classLoaderOfDefClassLoader.getName(),
                "Expected class loader name " + cl.getClass().getClassLoader().getName() + ", got name " + classLoaderOfDefClassLoader.getName());
            */

            RecordedClass classLoaderOfDefClassLoaderType = classLoaderOfDefClassLoader.getType();
            Asserts.assertNotNull(classLoaderOfDefClassLoaderType,
                "The class loader type for the defining class loader should not be null");
            Asserts.assertEquals(cl.getClass().getClassLoader().getClass().getName(), classLoaderOfDefClassLoaderType.getName(),
                "Expected type " + cl.getClass().getClassLoader().getClass().getName() + ", got type " + classLoaderOfDefClassLoaderType.getName());

            Asserts.assertGreaterThan(definingClassLoader.getId(), classLoaderOfDefClassLoader.getId(),
                "expected id assignment invariant broken for Class Loaders");

            isDefined = true;
        }
    }
    Asserts.assertTrue(isDefined, "No class define event found to verify RecordedClassLoader");
}
 
Example 18
Source File: TestFileStreamEvents.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 {
    File tmp = File.createTempFile("TestFileStreamEvents", ".tmp", new File("."));
    tmp.deleteOnExit();
    Recording recording = new Recording();
    List<IOEvent> expectedEvents = new ArrayList<>();

    try(FileOutputStream fos = new FileOutputStream(tmp); FileInputStream fis = new FileInputStream(tmp);) {
        recording.enable(IOEvent.EVENT_FILE_READ).withThreshold(Duration.ofMillis(0));
        recording.enable(IOEvent.EVENT_FILE_WRITE).withThreshold(Duration.ofMillis(0));
        recording.start();

        int writeByte = 47;
        byte[] writeBuf = {11, 12, 13, 14};

        // Write
        fos.write(writeByte);
        expectedEvents.add(IOEvent.createFileWriteEvent(1, tmp));
        fos.write(writeBuf);
        expectedEvents.add(IOEvent.createFileWriteEvent(writeBuf.length, tmp));
        fos.write(writeBuf, 0, 2);
        expectedEvents.add(IOEvent.createFileWriteEvent(2, tmp));

        // Read
        int readByte = fis.read();
        assertEquals(readByte, writeByte, "Wrong byte read");
        expectedEvents.add(IOEvent.createFileReadEvent(1, tmp));

        byte[] readBuf = new byte[writeBuf.length];
        long size = fis.read(readBuf);
        assertEquals(size, (long)writeBuf.length, "Wrong size when reading byte[]");
        expectedEvents.add(IOEvent.createFileReadEvent(size, tmp));

        size = fis.read(readBuf, 0, 2);
        assertEquals(size, 2L, "Wrong size when reading 2 bytes");
        expectedEvents.add(IOEvent.createFileReadEvent(size, tmp));

        // We are at EOF. Read more and verify we get size -1.
        size = fis.read(readBuf);
        assertEquals(size, -1L, "Size should be -1 at EOF");
        expectedEvents.add(IOEvent.createFileReadEvent(size, tmp));

        recording.stop();
        List<RecordedEvent> events = Events.fromRecording(recording);
        IOHelper.verifyEqualsInOrder(events, expectedEvents);
    }
}
 
Example 19
Source File: TestIsEnabledMultiple.java    From openjdk-jdk8u 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();
    }
 
Example 20
Source File: TestClonedEvent.java    From TencentKona-8 with GNU General Public License v2.0 3 votes vote down vote up
public static void main(String[] args) throws Throwable {
    Recording r = new Recording();
    r.enable(MyEvent.class);

    r.start();

    MyEvent event = new MyEvent();

    MyEvent event2 = (MyEvent)event.clone();

    FlightRecorder.register(MyEvent.class);
    event.commit();
    event2.commit();

    r.stop();

    List<RecordedEvent> events = Events.fromRecording(r);
    Asserts.assertEquals(2, events.size());

    r.close();

    FlightRecorder.unregister(MyEvent.class);

    Recording r2 = new Recording();
    r2.enable(MyEvent.class);

    r2.start();
    event.commit();
    event2.commit();

    r2.stop();

    events = Events.fromRecording(r2);
    Asserts.assertEquals(0, events.size());

    r2.close();
}