Java Code Examples for jdk.management.jfr.FlightRecorderMXBean#openStream()

The following examples show how to use jdk.management.jfr.FlightRecorderMXBean#openStream() . 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: TestStreamClosed.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 {
    FlightRecorderMXBean bean = JmxHelper.getFlighteRecorderMXBean();

    long recId = bean.newRecording();
    bean.startRecording(recId);
    SimpleEventHelper.createEvent(1);
    bean.stopRecording(recId);

    long streamId = bean.openStream(recId, null);
    bean.closeStream(streamId);
    try {
        bean.readStream(streamId);
        Asserts.fail("No exception whean reading closed stream");
    } catch (IOException e) {
        // Expected exception.
        String msg = e.getMessage().toLowerCase();
        Asserts.assertTrue(msg.contains("stream") && msg.contains("closed"), "No 'stream closed' in " + msg);
    }
    bean.closeRecording(recId);
}
 
Example 2
Source File: TestStreamClosed.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    FlightRecorderMXBean bean = JmxHelper.getFlighteRecorderMXBean();

    long recId = bean.newRecording();
    bean.startRecording(recId);
    SimpleEventHelper.createEvent(1);
    bean.stopRecording(recId);

    long streamId = bean.openStream(recId, null);
    bean.closeStream(streamId);
    try {
        bean.readStream(streamId);
        Asserts.fail("No exception whean reading closed stream");
    } catch (IOException e) {
        // Expected exception.
        String msg = e.getMessage().toLowerCase();
        Asserts.assertTrue(msg.contains("stream") && msg.contains("closed"), "No 'stream closed' in " + msg);
    }
    bean.closeRecording(recId);
}
 
Example 3
Source File: TestStreamClosed.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 {
    FlightRecorderMXBean bean = JmxHelper.getFlighteRecorderMXBean();

    long recId = bean.newRecording();
    bean.startRecording(recId);
    SimpleEventHelper.createEvent(1);
    bean.stopRecording(recId);

    long streamId = bean.openStream(recId, null);
    bean.closeStream(streamId);
    try {
        bean.readStream(streamId);
        Asserts.fail("No exception whean reading closed stream");
    } catch (IOException e) {
        // Expected exception.
        String msg = e.getMessage().toLowerCase();
        Asserts.assertTrue(msg.contains("stream") && msg.contains("closed"), "No 'stream closed' in " + msg);
    }
    bean.closeRecording(recId);
}
 
Example 4
Source File: TestEnoughPermission.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void testStream(FlightRecorderMXBean bean, long recId) throws Exception {
    long streamId = bean.openStream(recId, null);
    byte[] buff = bean.readStream(streamId);
    Asserts.assertNotNull(buff, "Stream data was empty");
    while (buff != null) {
        // TODO: write to file and parse.
        System.out.println("buff.length=" + buff.length);
        buff = bean.readStream(streamId);
    }
    bean.closeStream(streamId);
}
 
Example 5
Source File: TestStreamMultiple.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 {
    FlightRecorderMXBean bean = JmxHelper.getFlighteRecorderMXBean();

    SimpleEventHelper.createEvent(0); // No recordings

    long recIdA = bean.newRecording();

    bean.startRecording(recIdA);
    SimpleEventHelper.createEvent(1); // recA

    long recIdB = bean.newRecording();
    Asserts.assertNotEquals(recIdA, recIdB, "Recording Ids should be unique");
    bean.startRecording(recIdB);
    SimpleEventHelper.createEvent(2); // recA and recB

    bean.stopRecording(recIdA);
    SimpleEventHelper.createEvent(3); // recB

    bean.stopRecording(recIdB);
    SimpleEventHelper.createEvent(4); // No recordings

    // Check recA
    long streamIdA = bean.openStream(recIdA, null);
    List<RecordedEvent> events = JmxHelper.parseStream(streamIdA, bean);
    SimpleEventHelper.verifyContains(events, 1, 2);
    SimpleEventHelper.verifyNotContains(events, 0, 3, 4);
    bean.closeStream(streamIdA);
    // check recB
    long streamIdB = bean.openStream(recIdB, null);
    events = JmxHelper.parseStream(streamIdB, bean);
    SimpleEventHelper.verifyContains(events, 2, 3);
    SimpleEventHelper.verifyNotContains(events, 0, 1, 4);
    bean.closeStream(streamIdB);

    bean.closeRecording(recIdA);
    bean.closeRecording(recIdB);
}
 
Example 6
Source File: TestStream.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void verifyStream(FlightRecorderMXBean bean, long recId, Map<String, String> options) throws IOException, Exception {
    long streamId = bean.openStream(recId, options);

    List<RecordedEvent> events = JmxHelper.parseStream(streamId, bean);
    SimpleEventHelper.verifyContains(events, 1);
    SimpleEventHelper.verifyNotContains(events, 0, 2);
    bean.closeStream(streamId);
}
 
Example 7
Source File: TestEnoughPermission.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void testStream(FlightRecorderMXBean bean, long recId) throws Exception {
    long streamId = bean.openStream(recId, null);
    byte[] buff = bean.readStream(streamId);
    Asserts.assertNotNull(buff, "Stream data was empty");
    while (buff != null) {
        // TODO: write to file and parse.
        System.out.println("buff.length=" + buff.length);
        buff = bean.readStream(streamId);
    }
    bean.closeStream(streamId);
}
 
Example 8
Source File: TestStreamMultiple.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 {
    FlightRecorderMXBean bean = JmxHelper.getFlighteRecorderMXBean();

    SimpleEventHelper.createEvent(0); // No recordings

    long recIdA = bean.newRecording();

    bean.startRecording(recIdA);
    SimpleEventHelper.createEvent(1); // recA

    long recIdB = bean.newRecording();
    Asserts.assertNotEquals(recIdA, recIdB, "Recording Ids should be unique");
    bean.startRecording(recIdB);
    SimpleEventHelper.createEvent(2); // recA and recB

    bean.stopRecording(recIdA);
    SimpleEventHelper.createEvent(3); // recB

    bean.stopRecording(recIdB);
    SimpleEventHelper.createEvent(4); // No recordings

    // Check recA
    long streamIdA = bean.openStream(recIdA, null);
    List<RecordedEvent> events = JmxHelper.parseStream(streamIdA, bean);
    SimpleEventHelper.verifyContains(events, 1, 2);
    SimpleEventHelper.verifyNotContains(events, 0, 3, 4);
    bean.closeStream(streamIdA);
    // check recB
    long streamIdB = bean.openStream(recIdB, null);
    events = JmxHelper.parseStream(streamIdB, bean);
    SimpleEventHelper.verifyContains(events, 2, 3);
    SimpleEventHelper.verifyNotContains(events, 0, 1, 4);
    bean.closeStream(streamIdB);

    bean.closeRecording(recIdA);
    bean.closeRecording(recIdB);
}
 
Example 9
Source File: TestStream.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void verifyStream(FlightRecorderMXBean bean, long recId, Map<String, String> options) throws IOException, Exception {
    long streamId = bean.openStream(recId, options);

    List<RecordedEvent> events = JmxHelper.parseStream(streamId, bean);
    SimpleEventHelper.verifyContains(events, 1);
    SimpleEventHelper.verifyNotContains(events, 0, 2);
    bean.closeStream(streamId);
}
 
Example 10
Source File: TestEnoughPermission.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void testStream(FlightRecorderMXBean bean, long recId) throws Exception {
    long streamId = bean.openStream(recId, null);
    byte[] buff = bean.readStream(streamId);
    Asserts.assertNotNull(buff, "Stream data was empty");
    while (buff != null) {
        // TODO: write to file and parse.
        System.out.println("buff.length=" + buff.length);
        buff = bean.readStream(streamId);
    }
    bean.closeStream(streamId);
}
 
Example 11
Source File: TestStreamMultiple.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();

    SimpleEventHelper.createEvent(0); // No recordings

    long recIdA = bean.newRecording();

    bean.startRecording(recIdA);
    SimpleEventHelper.createEvent(1); // recA

    long recIdB = bean.newRecording();
    Asserts.assertNotEquals(recIdA, recIdB, "Recording Ids should be unique");
    bean.startRecording(recIdB);
    SimpleEventHelper.createEvent(2); // recA and recB

    bean.stopRecording(recIdA);
    SimpleEventHelper.createEvent(3); // recB

    bean.stopRecording(recIdB);
    SimpleEventHelper.createEvent(4); // No recordings

    // Check recA
    long streamIdA = bean.openStream(recIdA, null);
    List<RecordedEvent> events = JmxHelper.parseStream(streamIdA, bean);
    SimpleEventHelper.verifyContains(events, 1, 2);
    SimpleEventHelper.verifyNotContains(events, 0, 3, 4);
    bean.closeStream(streamIdA);
    // check recB
    long streamIdB = bean.openStream(recIdB, null);
    events = JmxHelper.parseStream(streamIdB, bean);
    SimpleEventHelper.verifyContains(events, 2, 3);
    SimpleEventHelper.verifyNotContains(events, 0, 1, 4);
    bean.closeStream(streamIdB);

    bean.closeRecording(recIdA);
    bean.closeRecording(recIdB);
}
 
Example 12
Source File: TestStream.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void verifyStream(FlightRecorderMXBean bean, long recId, Map<String, String> options) throws IOException, Exception {
    long streamId = bean.openStream(recId, options);

    List<RecordedEvent> events = JmxHelper.parseStream(streamId, bean);
    SimpleEventHelper.verifyContains(events, 1);
    SimpleEventHelper.verifyNotContains(events, 0, 2);
    bean.closeStream(streamId);
}