Java Code Examples for jdk.jfr.FlightRecorder#addPeriodicEvent()

The following examples show how to use jdk.jfr.FlightRecorder#addPeriodicEvent() . 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: MainTest.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 {
    System.out.println("Starting the test...");
    FlightRecorder.addPeriodicEvent(ModularizedPeriodicEvent.class, () -> {
        ModularizedPeriodicEvent me = new ModularizedPeriodicEvent();
        me.message = HELLO_PERIODIC;
        me.commit();
    });
    Recording r = new Recording();
    r.enable(ModularizedOrdinaryEvent.class).with("filter", "true").withoutStackTrace();
    r.enable(ModularizedPeriodicEvent.class).with("filter", "true").withoutStackTrace();
    r.start();
    ModularizedOrdinaryEvent m = new ModularizedOrdinaryEvent();
    m.message = HELLO_ORDINARY;
    m.commit();
    r.stop();
    List<RecordedEvent> events = fromRecording(r);
    System.out.println(events);
    if (events.size() == 0) {
        throw new RuntimeException("Expected two events");
    }
    assertOrdinaryEvent(events);
    assertPeriodicEvent(events);
    assertMetadata(events);
    System.out.println("Test passed.");
}
 
Example 2
Source File: TestGetDefaultValues.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void testCustomWithPeriod() {
    Runnable hook = new Runnable() {
        @Override
        public void run() {
        }
    };
    EventType customEventType = EventType.getEventType(EventWithCustomSettings.class);
    FlightRecorder.addPeriodicEvent(EventWithCustomSettings.class, hook);
    Asserts.assertEquals(customEventType.getSettingDescriptors().size(), 4, "Wrong number of settings");
    assertDefaultValue(customEventType, "period", "10 s");
    assertDefaultValue(customEventType, "enabled", "false");
    assertDefaultValue(customEventType, "setting1", "none");
    assertDefaultValue(customEventType, "setting2", "none");

    FlightRecorder.removePeriodicEvent(hook);
    Asserts.assertEquals(customEventType.getSettingDescriptors().size(), 5, "Wrong number of settings");
    assertDefaultValue(customEventType, "threshold", "100 ms");
    assertDefaultValue(customEventType, "stackTrace", "true");
    assertDefaultValue(customEventType, "enabled", "false");
    assertDefaultValue(customEventType, "setting1", "none");
    assertDefaultValue(customEventType, "setting2", "none");

}
 
Example 3
Source File: TestAddPeriodicEvent.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private void doTest(long eventDuration, int numOfEvents) throws Exception {
    latch = new CountDownLatch(numOfEvents);
    MyHook hook = new MyHook();

    Recording r = new Recording();
    r.enable(MyEvent.class).withPeriod(Duration.ofMillis(eventDuration));
    r.start();

    FlightRecorder.addPeriodicEvent(MyEvent.class, hook);

    latch.await();

    assertTrue(FlightRecorder.removePeriodicEvent(hook));
    assertFalse(FlightRecorder.removePeriodicEvent(hook));

    r.stop();
    r.close();
}
 
Example 4
Source File: MainTest.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 {
    System.out.println("Starting the test...");
    FlightRecorder.addPeriodicEvent(ModularizedPeriodicEvent.class, () -> {
        ModularizedPeriodicEvent me = new ModularizedPeriodicEvent();
        me.message = HELLO_PERIODIC;
        me.commit();
    });
    Recording r = new Recording();
    r.enable(ModularizedOrdinaryEvent.class).with("filter", "true").withoutStackTrace();
    r.enable(ModularizedPeriodicEvent.class).with("filter", "true").withoutStackTrace();
    r.start();
    ModularizedOrdinaryEvent m = new ModularizedOrdinaryEvent();
    m.message = HELLO_ORDINARY;
    m.commit();
    r.stop();
    List<RecordedEvent> events = fromRecording(r);
    System.out.println(events);
    if (events.size() == 0) {
        throw new RuntimeException("Expected two events");
    }
    assertOrdinaryEvent(events);
    assertPeriodicEvent(events);
    assertMetadata(events);
    System.out.println("Test passed.");
}
 
Example 5
Source File: TestGetDefaultValues.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static void testCustomWithPeriod() {
    Runnable hook = new Runnable() {
        @Override
        public void run() {
        }
    };
    EventType customEventType = EventType.getEventType(EventWithCustomSettings.class);
    FlightRecorder.addPeriodicEvent(EventWithCustomSettings.class, hook);
    Asserts.assertEquals(customEventType.getSettingDescriptors().size(), 4, "Wrong number of settings");
    assertDefaultValue(customEventType, "period", "10 s");
    assertDefaultValue(customEventType, "enabled", "false");
    assertDefaultValue(customEventType, "setting1", "none");
    assertDefaultValue(customEventType, "setting2", "none");

    FlightRecorder.removePeriodicEvent(hook);
    Asserts.assertEquals(customEventType.getSettingDescriptors().size(), 5, "Wrong number of settings");
    assertDefaultValue(customEventType, "threshold", "100 ms");
    assertDefaultValue(customEventType, "stackTrace", "true");
    assertDefaultValue(customEventType, "enabled", "false");
    assertDefaultValue(customEventType, "setting1", "none");
    assertDefaultValue(customEventType, "setting2", "none");

}
 
Example 6
Source File: TestAddPeriodicEvent.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private void doTest(long eventDuration, int numOfEvents) throws Exception {
    latch = new CountDownLatch(numOfEvents);
    MyHook hook = new MyHook();

    Recording r = new Recording();
    r.enable(MyEvent.class).withPeriod(Duration.ofMillis(eventDuration));
    r.start();

    FlightRecorder.addPeriodicEvent(MyEvent.class, hook);

    latch.await();

    assertTrue(FlightRecorder.removePeriodicEvent(hook));
    assertFalse(FlightRecorder.removePeriodicEvent(hook));

    r.stop();
    r.close();
}
 
Example 7
Source File: MainTest.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 {
    System.out.println("Starting the test...");
    FlightRecorder.addPeriodicEvent(ModularizedPeriodicEvent.class, () -> {
        ModularizedPeriodicEvent me = new ModularizedPeriodicEvent();
        me.message = HELLO_PERIODIC;
        me.commit();
    });
    Recording r = new Recording();
    r.enable(ModularizedOrdinaryEvent.class).with("filter", "true").withoutStackTrace();
    r.enable(ModularizedPeriodicEvent.class).with("filter", "true").withoutStackTrace();
    r.start();
    ModularizedOrdinaryEvent m = new ModularizedOrdinaryEvent();
    m.message = HELLO_ORDINARY;
    m.commit();
    r.stop();
    List<RecordedEvent> events = fromRecording(r);
    System.out.println(events);
    if (events.size() == 0) {
        throw new RuntimeException("Expected two events");
    }
    assertOrdinaryEvent(events);
    assertPeriodicEvent(events);
    assertMetadata(events);
    System.out.println("Test passed.");
}
 
Example 8
Source File: TestGetDefaultValues.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static void testCustomWithPeriod() {
    Runnable hook = new Runnable() {
        @Override
        public void run() {
        }
    };
    EventType customEventType = EventType.getEventType(EventWithCustomSettings.class);
    FlightRecorder.addPeriodicEvent(EventWithCustomSettings.class, hook);
    Asserts.assertEquals(customEventType.getSettingDescriptors().size(), 4, "Wrong number of settings");
    assertDefaultValue(customEventType, "period", "10 s");
    assertDefaultValue(customEventType, "enabled", "false");
    assertDefaultValue(customEventType, "setting1", "none");
    assertDefaultValue(customEventType, "setting2", "none");

    FlightRecorder.removePeriodicEvent(hook);
    Asserts.assertEquals(customEventType.getSettingDescriptors().size(), 5, "Wrong number of settings");
    assertDefaultValue(customEventType, "threshold", "100 ms");
    assertDefaultValue(customEventType, "stackTrace", "true");
    assertDefaultValue(customEventType, "enabled", "false");
    assertDefaultValue(customEventType, "setting1", "none");
    assertDefaultValue(customEventType, "setting2", "none");

}
 
Example 9
Source File: TestAddPeriodicEvent.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private void doTest(long eventDuration, int numOfEvents) throws Exception {
    latch = new CountDownLatch(numOfEvents);
    MyHook hook = new MyHook();

    Recording r = new Recording();
    r.enable(MyEvent.class).withPeriod(Duration.ofMillis(eventDuration));
    r.start();

    FlightRecorder.addPeriodicEvent(MyEvent.class, hook);

    latch.await();

    assertTrue(FlightRecorder.removePeriodicEvent(hook));
    assertFalse(FlightRecorder.removePeriodicEvent(hook));

    r.stop();
    r.close();
}
 
Example 10
Source File: JDKEvents.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public synchronized static void initialize() {
    try {
        if (initializationTriggered == false) {
            for (Class<?> eventClass : eventClasses) {
                SecuritySupport.registerEvent((Class<? extends Event>) eventClass);
            }
            initializationTriggered = true;
            FlightRecorder.addPeriodicEvent(ExceptionStatisticsEvent.class, emitExceptionStatistics);
        }
    } catch (Exception e) {
        Logger.log(LogTag.JFR_SYSTEM, LogLevel.WARN, "Could not initialize JDK events. " + e.getMessage());
    }
}
 
Example 11
Source File: TestChunkPeriod.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 {
    FlightRecorder.addPeriodicEvent(SimpleEvent.class, () -> {
        SimpleEvent  pe = new SimpleEvent();
        pe.commit();
    });
    testBeginChunk();
    testEndChunk();
    testEveryChunk();
}
 
Example 12
Source File: TestPeriodicEventsSameHook.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 {
    MyHook hook = new MyHook();
    FlightRecorder.addPeriodicEvent(MyEvent.class, hook);
    try {
        FlightRecorder.addPeriodicEvent(MyEvent.class, hook);
        throw new Exception("Expected IllegalArgumentException when adding same hook twice");
    } catch (IllegalArgumentException iae) {
        if (!iae.getMessage().equals("Hook has already been added")) {
            throw new Exception("Expected IllegalArgumentException with message 'Hook has already been added'");
        }
    }
}
 
Example 13
Source File: TestChunkPeriod.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 {
    FlightRecorder.addPeriodicEvent(SimpleEvent.class, () -> {
        SimpleEvent  pe = new SimpleEvent();
        pe.commit();
    });
    testBeginChunk();
    testEndChunk();
    testEveryChunk();
}
 
Example 14
Source File: TestPeriodicEventsSameHook.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 {
    MyHook hook = new MyHook();
    FlightRecorder.addPeriodicEvent(MyEvent.class, hook);
    try {
        FlightRecorder.addPeriodicEvent(MyEvent.class, hook);
        throw new Exception("Expected IllegalArgumentException when adding same hook twice");
    } catch (IllegalArgumentException iae) {
        if (!iae.getMessage().equals("Hook has already been added")) {
            throw new Exception("Expected IllegalArgumentException with message 'Hook has already been added'");
        }
    }
}
 
Example 15
Source File: TestChunkPeriod.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 {
    FlightRecorder.addPeriodicEvent(SimpleEvent.class, () -> {
        SimpleEvent  pe = new SimpleEvent();
        pe.commit();
    });
    testBeginChunk();
    testEndChunk();
    testEveryChunk();
}
 
Example 16
Source File: TestPeriodicEventsSameHook.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 {
    MyHook hook = new MyHook();
    FlightRecorder.addPeriodicEvent(MyEvent.class, hook);
    try {
        FlightRecorder.addPeriodicEvent(MyEvent.class, hook);
        throw new Exception("Expected IllegalArgumentException when adding same hook twice");
    } catch (IllegalArgumentException iae) {
        if (!iae.getMessage().equals("Hook has already been added")) {
            throw new Exception("Expected IllegalArgumentException with message 'Hook has already been added'");
        }
    }
}