jdk.jfr.FlightRecorder Java Examples
The following examples show how to use
jdk.jfr.FlightRecorder.
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: TestStateIdenticalListeners.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Throwable { TestListener testListener = new TestListener(); // Add the same listener twice FlightRecorder.addListener(testListener); FlightRecorder.addListener(testListener); // Start recording Recording recording = new Recording(); recording.start(); recording.stop(); // We expect 4 notifications in total: 1 RUNNING and 1 STOPPED // notification for each listener registration // NOT 2 notifications: we have added the same listener again assertEquals(4, testListener.notificationCount, "Expected 2 notifications, got " + testListener.notificationCount); System.out.println("Test Passed"); recording.close(); }
Example #2
Source File: FlightRecorderMXBeanImpl.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
@Override public long openStream(long id, Map<String, String> options) throws IOException { MBeanUtils.checkControl(); if (!FlightRecorder.isInitialized()) { throw new IllegalArgumentException("No recording available with id " + id); } // Make local copy to prevent concurrent modification Map<String, String> s = options == null ? new HashMap<>() : new HashMap<>(options); Instant starttime = MBeanUtils.parseTimestamp(s.get("startTime"), Instant.MIN); Instant endtime = MBeanUtils.parseTimestamp(s.get("endTime"), Instant.MAX); int blockSize = MBeanUtils.parseBlockSize(s.get("blockSize"), StreamManager.DEFAULT_BLOCK_SIZE); InputStream is = getExistingRecording(id).getStream(starttime, endtime); if (is == null) { throw new IOException("No recording data available"); } return streamHandler.create(is, blockSize).getId(); }
Example #3
Source File: TestAddPeriodicEvent.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
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: TestStateIdenticalListeners.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Throwable { TestListener testListener = new TestListener(); // Add the same listener twice FlightRecorder.addListener(testListener); FlightRecorder.addListener(testListener); // Start recording Recording recording = new Recording(); recording.start(); recording.stop(); // We expect 4 notifications in total: 1 RUNNING and 1 STOPPED // notification for each listener registration // NOT 2 notifications: we have added the same listener again assertEquals(4, testListener.notificationCount, "Expected 2 notifications, got " + testListener.notificationCount); System.out.println("Test Passed"); recording.close(); }
Example #5
Source File: TestSnapshot.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
private static void testStopped() throws IOException { try (Recording r = new Recording()) { r.enable(SimpleEvent.class); r.start(); SimpleEvent se = new SimpleEvent(); se.commit(); r.stop(); try (Recording snapshot = FlightRecorder.getFlightRecorder().takeSnapshot()) { r.close(); FlightRecorderMXBean mxBean = JmxHelper.getFlighteRecorderMXBean(); List<RecordingInfo> recs = mxBean.getRecordings(); JmxHelper.verifyEquals(recs.get(0), snapshot); } } }
Example #6
Source File: TestRecorderInitialized.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String...args) { Listener l1 = new Listener(); FlightRecorder.addListener(l1); Asserts.assertFalse(l1.notified, "Listener shouldn't be notified unless Flight Recorder is initialized"); // initialize Flight Recorder FlightRecorder.getFlightRecorder(); Asserts.assertTrue(l1.notified, "Listener should be notified when Flight Recorder is initialized"); l1.notified = false; Listener l2 = new Listener(); FlightRecorder.addListener(l1); FlightRecorder.addListener(l2); Asserts.assertTrue(l2.notified, "Listener should be notified if Flight Recorder is already initialized"); Asserts.assertTrue(l1.notified, "Only added listnener should be notified, if Flight Recorder is already initialized"); }
Example #7
Source File: TestActiveSettingEvent.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
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 #8
Source File: TestSettingsAvailability.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
private static void testSetting(String eventName, String... settingNames) throws Exception { for (EventType type : FlightRecorder.getFlightRecorder().getEventTypes()) { if (eventName.equals(type.getName())) { Set<String> settings = new HashSet<>(); for (SettingDescriptor sd : type.getSettingDescriptors()) { settings.add(sd.getName()); } for (String settingName : settingNames) { if (!settings.contains(settingName)) { throw new Exception("Missing setting " + settingName + " in " + eventName); } settings.remove(settingName); } if (!settings.isEmpty()) { throw new Exception("Superflous settings " + settings + " in event " + eventName); } } } }
Example #9
Source File: TestListener.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Throwable { MyListener listener1 = new MyListener(); MyListener listener2 = new MyListener(); FlightRecorder.addListener(listener1); FlightRecorder.addListener(listener2); Recording r1 = new Recording(); listener1.verifyState(0, RecordingState.NEW); listener2.verifyState(0, RecordingState.NEW); r1.start(); listener1.verifyState(1, RecordingState.RUNNING); listener2.verifyState(1, RecordingState.RUNNING); FlightRecorder.removeListener(listener1); // listener1 should not get more callbacks. r1.stop(); listener1.verifyState(1, RecordingState.RUNNING); listener2.verifyState(2, RecordingState.STOPPED); r1.close(); listener1.verifyState(1, RecordingState.RUNNING); listener2.verifyState(3, RecordingState.CLOSED); FlightRecorder.removeListener(listener2); }
Example #10
Source File: TestGetDefaultValues.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
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 #11
Source File: MainTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
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 #12
Source File: FlightRecorderMXBeanImpl.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
@Override public long openStream(long id, Map<String, String> options) throws IOException { MBeanUtils.checkControl(); if (!FlightRecorder.isInitialized()) { throw new IllegalArgumentException("No recording available with id " + id); } // Make local copy to prevent concurrent modification Map<String, String> s = options == null ? new HashMap<>() : new HashMap<>(options); Instant starttime = MBeanUtils.parseTimestamp(s.get("startTime"), Instant.MIN); Instant endtime = MBeanUtils.parseTimestamp(s.get("endTime"), Instant.MAX); int blockSize = MBeanUtils.parseBlockSize(s.get("blockSize"), StreamManager.DEFAULT_BLOCK_SIZE); InputStream is = getExistingRecording(id).getStream(starttime, endtime); if (is == null) { throw new IOException("No recording data available"); } return streamHandler.create(is, blockSize).getId(); }
Example #13
Source File: TestUnloadEventClassCount.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Throwable { FlightRecorder.getFlightRecorder(); myClassLoader = createClassLoaderWithEventClass(); System.out.println("MyClassLoader instance created"); long initialCount = JVM.getJVM().getUnloadedEventClassCount(); System.out.println("Initiali unloaded count is " + initialCount); myClassLoader = null; System.out.println("Reference to class loader cleared"); long count = 0; do { System.gc(); System.out.println("GC triggered"); count = JVM.getJVM().getUnloadedEventClassCount(); System.out.println("Unloaded count was " + count); Thread.sleep(1000); // sleep to reduce log } while (count != initialCount + 1); }
Example #14
Source File: TestGetDefaultValues.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
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 #15
Source File: TestSnapshot.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
private static void testStopped() throws IOException { try (Recording r = new Recording()) { r.enable(SimpleEvent.class); r.start(); SimpleEvent se = new SimpleEvent(); se.commit(); r.stop(); try (Recording snapshot = FlightRecorder.getFlightRecorder().takeSnapshot()) { r.close(); FlightRecorderMXBean mxBean = JmxHelper.getFlighteRecorderMXBean(); List<RecordingInfo> recs = mxBean.getRecordings(); JmxHelper.verifyEquals(recs.get(0), snapshot); } } }
Example #16
Source File: TestActiveSettingEvent.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
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 #17
Source File: TestJcmdStartPathToGCRoots.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
private static void assertCutoff(String expected, String errorMessage) throws Exception { List<Recording> recordings = FlightRecorder.getFlightRecorder().getRecordings(); if (recordings.isEmpty()) { throw new Exception("Expected recording to be started"); } if (recordings.size() != 1) { throw new Exception("Expected only one recording"); } String settingName = EventNames.OldObjectSample + "#" + "cutoff"; Recording r = recordings.get(0); String cutoff = r.getSettings().get(settingName); System.out.println(settingName + "=" + cutoff); if (!expected.equals(cutoff)) { throw new Exception(errorMessage); } r.close(); }
Example #18
Source File: TestFlightRecorderListenerRecorderInitialized.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Throwable { FlightRecorder.addListener(new FlightRecorderListener() { @Override public void recorderInitialized(FlightRecorder recorder) { log("Recorder initialized"); Signal.signal(); } }); FlightRecorder.getFlightRecorder(); Signal.waitFor(3, TimeUnit.SECONDS); assertTrue(Signal.signalled, "FlightRecorderListener.recorderInitialized has not been called"); }
Example #19
Source File: TestEventMetadata.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { Set<String> types = new HashSet<>(); List<EventType> eventTypes = FlightRecorder.getFlightRecorder().getEventTypes(); Set<String> eventNames= new HashSet<>(); for (EventType eventType : eventTypes) { verifyEventType(eventType); verifyValueDesscriptors(eventType.getFields(), types); System.out.println(); String eventName = eventType.getName(); if (eventNames.contains(eventName)) { throw new Exception("Event with name " +eventName+ " already exists"); } eventNames.add(eventName); Set<String> fieldNames = new HashSet<>(); for (ValueDescriptor v : eventType.getFields()) { String fieldName = v.getName(); if (fieldNames.contains(fieldName)) { throw new Exception("Field with name " + fieldName +" is already in use in event name " +eventName); } fieldNames.add(fieldName); } } }
Example #20
Source File: TestJcmdStartWithOptions.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
static void testRecordingNotStartedTooEarly() throws Exception { String name = "testRecordingNotStartedTooEarly"; long delay = 2 * 1000; OutputAnalyzer output = JcmdHelper.jcmd("JFR.start", "name=" + name, "delay=" + delay + "ms"); JcmdAsserts.assertRecordingIsScheduled(output, "1", "2 s"); for (Recording r : FlightRecorder.getFlightRecorder().getRecordings()) { if (name.equals(r.getName())) { while(r.getState() != RecordingState.RUNNING) { Thread.sleep(10); } long currentTime = System.currentTimeMillis(); long afterActualStart = currentTime + delay; JcmdAsserts.assertStartTimeGreaterOrEqualThanMBeanValue(name, afterActualStart); JcmdHelper.stopAndCheck(name); return; } } throw new Exception("Could not find recording with name " + name); }
Example #21
Source File: TestStateIdenticalListeners.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Throwable { TestListener testListener = new TestListener(); // Add the same listener twice FlightRecorder.addListener(testListener); FlightRecorder.addListener(testListener); // Start recording Recording recording = new Recording(); recording.start(); recording.stop(); // We expect 4 notifications in total: 1 RUNNING and 1 STOPPED // notification for each listener registration // NOT 2 notifications: we have added the same listener again assertEquals(4, testListener.notificationCount, "Expected 2 notifications, got " + testListener.notificationCount); System.out.println("Test Passed"); recording.close(); }
Example #22
Source File: TestJcmdStartWithOptions.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
static void testRecordingNotStartedTooEarly() throws Exception { String name = "testRecordingNotStartedTooEarly"; long delay = 2 * 1000; OutputAnalyzer output = JcmdHelper.jcmd("JFR.start", "name=" + name, "delay=" + delay + "ms"); JcmdAsserts.assertRecordingIsScheduled(output, "1", "2 s"); for (Recording r : FlightRecorder.getFlightRecorder().getRecordings()) { if (name.equals(r.getName())) { while(r.getState() != RecordingState.RUNNING) { Thread.sleep(10); } long currentTime = System.currentTimeMillis(); long afterActualStart = currentTime + delay; JcmdAsserts.assertStartTimeGreaterOrEqualThanMBeanValue(name, afterActualStart); JcmdHelper.stopAndCheck(name); return; } } throw new Exception("Could not find recording with name " + name); }
Example #23
Source File: TestAddListenerTwice.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
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 #24
Source File: TestSettingsAvailability.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
private static void testSetting(String eventName, String... settingNames) throws Exception { for (EventType type : FlightRecorder.getFlightRecorder().getEventTypes()) { if (eventName.equals(type.getName())) { Set<String> settings = new HashSet<>(); for (SettingDescriptor sd : type.getSettingDescriptors()) { settings.add(sd.getName()); } for (String settingName : settingNames) { if (!settings.contains(settingName)) { throw new Exception("Missing setting " + settingName + " in " + eventName); } settings.remove(settingName); } if (!settings.isEmpty()) { throw new Exception("Superflous settings " + settings + " in event " + eventName); } } } }
Example #25
Source File: TestGetDefaultValues.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
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 #26
Source File: TestRegistered.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { try { EventType.getEventType(NotRegisteredByDefaultEvent.class); throw new Exception("Should not be able to get event type from unregistered event type"); } catch (IllegalStateException ise) { // as expected } EventType registered = EventType.getEventType(RegisteredByDefaultEvent.class); boolean registeredWorking = false; for (EventType type : FlightRecorder.getFlightRecorder().getEventTypes()) { if (registered.getId() == type.getId()) { registeredWorking = true; } } if (!registeredWorking) { Asserts.fail("Default regsitration is not working, can't validate @NoAutoRegistration"); } }
Example #27
Source File: TestListener.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Throwable { MyListener listener1 = new MyListener(); MyListener listener2 = new MyListener(); FlightRecorder.addListener(listener1); FlightRecorder.addListener(listener2); Recording r1 = new Recording(); listener1.verifyState(0, RecordingState.NEW); listener2.verifyState(0, RecordingState.NEW); r1.start(); listener1.verifyState(1, RecordingState.RUNNING); listener2.verifyState(1, RecordingState.RUNNING); FlightRecorder.removeListener(listener1); // listener1 should not get more callbacks. r1.stop(); listener1.verifyState(1, RecordingState.RUNNING); listener2.verifyState(2, RecordingState.STOPPED); r1.close(); listener1.verifyState(1, RecordingState.RUNNING); listener2.verifyState(3, RecordingState.CLOSED); FlightRecorder.removeListener(listener2); }
Example #28
Source File: TestSnapshot.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private static void testEmpty() throws IOException { FlightRecorder recorder = FlightRecorder.getFlightRecorder(); Instant before = Instant.now().minusNanos(1); try (Recording snapshot = recorder.takeSnapshot()) { Instant after = Instant.now().plusNanos(1); Asserts.assertEquals(snapshot.getSize(), 0L); Asserts.assertLessThan(before, snapshot.getStartTime()); Asserts.assertGreaterThan(after, snapshot.getStopTime()); Asserts.assertEquals(snapshot.getStartTime(), snapshot.getStopTime()); Asserts.assertEquals(snapshot.getDuration(), Duration.ZERO); assertStaticOptions(snapshot); Asserts.assertEquals(snapshot.getStream(null, null), null); } }
Example #29
Source File: TestSnapshot.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private static void testEmpty() throws IOException { FlightRecorder recorder = FlightRecorder.getFlightRecorder(); Instant before = Instant.now().minusNanos(1); try (Recording snapshot = recorder.takeSnapshot()) { Instant after = Instant.now().plusNanos(1); Asserts.assertEquals(snapshot.getSize(), 0L); Asserts.assertLessThan(before, snapshot.getStartTime()); Asserts.assertGreaterThan(after, snapshot.getStopTime()); Asserts.assertEquals(snapshot.getStartTime(), snapshot.getStopTime()); Asserts.assertEquals(snapshot.getDuration(), Duration.ZERO); assertStaticOptions(snapshot); Asserts.assertEquals(snapshot.getStream(null, null), null); } }
Example #30
Source File: TestRecorderInitializationCallback.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
@Override public void recorderInitialized(FlightRecorder recorder) { count.incrementAndGet(); System.out.println("recorderInitialized: " + recorder + " count=" + count); // Get the recorder again, should not trigger listener FlightRecorder.getFlightRecorder(); }