jdk.jfr.Recording Java Examples
The following examples show how to use
jdk.jfr.Recording.
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: TestRetransform.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
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 #2
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 #3
Source File: TestRecordedMethodDescriptor.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Throwable { Recording recording = new Recording(); recording.enable(MyEvent.class).withStackTrace(); recording.start(); MyEvent event = new MyEvent(); event.begin(); event.end(); event.commit(); recording.stop(); List<RecordedEvent> recordedEvents = Events.fromRecording(recording); assertEquals(1, recordedEvents.size(), "Expected one event"); RecordedEvent recordedEvent = recordedEvents.get(0); RecordedStackTrace stacktrace = recordedEvent.getStackTrace(); List<RecordedFrame> frames = stacktrace.getFrames(); assertFalse(frames.isEmpty(), "Stacktrace frames was empty"); for (RecordedFrame frame : frames) { analyzeRecordedMethodDescriptor(frame.getMethod()); } assertTrue(isMainMethodDescriptorRecorded, "main() method descriptor has never been recorded"); }
Example #4
Source File: TestCompilerPhase.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { Recording recording = new Recording(); recording.enable(EVENT_NAME); recording.start(); // Provoke compilation Method mtd = TestCompilerPhase.class.getDeclaredMethod(METHOD_NAME, new Class[0]); WhiteBox WB = WhiteBox.getWhiteBox(); if (!WB.enqueueMethodForCompilation(mtd, COMP_LEVEL_FULL_OPTIMIZATION)) { WB.enqueueMethodForCompilation(mtd, COMP_LEVEL_SIMPLE); } Utils.waitForCondition(() -> WB.isMethodCompiled(mtd)); dummyMethod(); recording.stop(); List<RecordedEvent> events = Events.fromRecording(recording); Events.hasEvents(events); for (RecordedEvent event : events) { System.out.println("Event:" + event); Events.assertField(event, "phase").notEmpty(); Events.assertField(event, "compileId").atLeast(0); Events.assertField(event, "phaseLevel").atLeast((short)0).atMost((short)4); Events.assertEventThread(event); } }
Example #5
Source File: TestSerial.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Throwable { WhiteBox.setWriteAllObjectSamples(true); try (Recording r = new Recording()) { r.enable(EventNames.OldObjectSample).withStackTrace().with("cutoff", "infinity"); r.start(); allocateFindMe(); System.gc(); r.stop(); List<RecordedEvent> events = Events.fromRecording(r); System.out.println(events); if (OldObjects.countMatchingEvents(events, FindMe[].class, null, null, -1, "allocateFindMe") == 0) { throw new Exception("Could not find leak with " + FindMe[].class); } } }
Example #6
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 #7
Source File: TestActiveSettingEvent.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
private static void testChangedSetting() throws Exception { EventType type = EventType.getEventType(MyEvent.class); Map<String, String> base = new HashMap<>(); base.put(ACTIVE_SETTING_EVENT_NAME + "#enabled", "true"); try (Recording recording = new Recording()) { recording.setSettings(base); recording.start(); Map<String, String> newS = new HashMap<>(base); newS.put(type.getName() + "#enabled", "true"); newS.put(type.getName() + "#threshold", "11 ns"); recording.setSettings(newS); recording.stop(); List<RecordedEvent> events = Events.fromRecording(recording); Events.hasEvents(events); assertSetting(events, type, "threshold", "0 ns"); // initial value assertSetting(events, type, "enabled", "true"); assertSetting(events, type, "threshold", "11 ns"); // changed value } }
Example #8
Source File: TestSingleRecordedEvent.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Throwable { Recording r = new Recording(); r.start(); // Commit a single event to the recording MyEvent event = new MyEvent(); event.commit(); r.stop(); List<RecordedEvent> events = Events.fromRecording(r); Events.hasEvents(events); // Should be 1 event only Asserts.assertEquals(events.size(), 1); RecordedEvent recordedEvent = events.get(0); // Event description should be the same Asserts.assertEquals(recordedEvent.getEventType().getDescription(), "MyDescription"); }
Example #9
Source File: TestCopyToRunning.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { FlightRecorderMXBean bean = JmxHelper.getFlighteRecorderMXBean(); long recId = bean.newRecording(); bean.startRecording(recId); SimpleEventHelper.createEvent(1); Path path = Paths.get(".", "my.jfr"); bean.copyTo(recId, path.toString()); List<RecordedEvent> events = RecordingFile.readAllEvents(path); Asserts.assertTrue(events.iterator().hasNext(), "No events found"); for (RecordedEvent event : events) { System.out.println("Event:" + event); } Recording recording = getRecording(recId); Asserts.assertEquals(recording.getState(), RecordingState.RUNNING, "Recording not in state running"); bean.stopRecording(recId); Asserts.assertEquals(recording.getState(), RecordingState.STOPPED, "Recording not in state stopped"); bean.closeRecording(recId); Asserts.assertEquals(recording.getState(), RecordingState.CLOSED, "Recording not in state closed"); }
Example #10
Source File: TestSingleRecordedEvent.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Throwable { Recording r = new Recording(); r.start(); // Commit a single event to the recording MyEvent event = new MyEvent(); event.commit(); r.stop(); List<RecordedEvent> events = Events.fromRecording(r); Events.hasEvents(events); // Should be 1 event only Asserts.assertEquals(events.size(), 1); RecordedEvent recordedEvent = events.get(0); // Event description should be the same Asserts.assertEquals(recordedEvent.getEventType().getDescription(), "MyDescription"); }
Example #11
Source File: TestFormatMissingValue.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { try (Recording r = new Recording()) { r.start(); MultiContentTypeEvent m = new MultiContentTypeEvent(); m.commit(); r.stop(); for (RecordedEvent e : Events.fromRecording(r)) { String t = e.toString(); assertContains(t, "a = N/A"); assertContains(t, "c = N/A"); assertContains(t, "e = N/A"); assertContains(t, "g = N/A"); assertContains(t, "h = N/A"); assertContains(t, "j = N/A"); assertNotContains(t, "b = N/A"); assertNotContains(t, "d = N/A"); assertNotContains(t, "f = N/A"); assertNotContains(t, "i = N/A"); } } }
Example #12
Source File: JmxHelper.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public static void verifyEquals(RecordingInfo ri, Recording r) { String destination = r.getDestination() != null ? r.getDestination().toString() : null; long maxAge = r.getMaxAge() != null ? r.getMaxAge().getSeconds() : 0; long duration = r.getDuration() != null ? r.getDuration().getSeconds() : 0; Asserts.assertEquals(destination, ri.getDestination(), "Wrong destination"); Asserts.assertEquals(r.getDumpOnExit(), ri.getDumpOnExit(), "Wrong dumpOnExit"); Asserts.assertEquals(duration, ri.getDuration(), "Wrong duration"); Asserts.assertEquals(r.getId(), ri.getId(), "Wrong id"); Asserts.assertEquals(maxAge, ri.getMaxAge(), "Wrong maxAge"); Asserts.assertEquals(r.getMaxSize(), ri.getMaxSize(), "Wrong maxSize"); Asserts.assertEquals(r.getName(), ri.getName(), "Wrong name"); Asserts.assertEquals(r.getSize(), ri.getSize(), "Wrong size"); Asserts.assertEquals(toEpochMillis(r.getStartTime()), ri.getStartTime(), "Wrong startTime"); Asserts.assertEquals(r.getState().toString(), ri.getState(), "Wrong state"); Asserts.assertEquals(toEpochMillis(r.getStopTime()), ri.getStopTime(), "Wrong stopTime"); verifyMapEquals(r.getSettings(), ri.getSettings()); }
Example #13
Source File: TestDumpState.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
private static void checkEvents(Recording r, List<Integer> expectedIds) throws Exception { Path path = Paths.get(".", String.format("%d.jfr", recordingCounter++)); r.dump(path); Asserts.assertTrue(Files.exists(path), "Recording file does not exist: " + path); int index = 0; for (RecordedEvent event : RecordingFile.readAllEvents(path)) { Events.isEventType(event, SimpleEvent.class.getName()); Integer id = Events.assertField(event, "id").getValue(); System.out.println("Got event with id " + id); Asserts.assertGreaterThan(expectedIds.size(), index, "Too many Events found"); Asserts.assertEquals(id, expectedIds.get(index), "Wrong id at index " + index); ++index; } Asserts.assertEquals(index, expectedIds.size(), "Too few Events found"); }
Example #14
Source File: TestStaticEnable.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { Recording r = new Recording(); MyEvent.enable(r, true); r.start(); MyEvent.create("Hello", 1); r.stop(); List<RecordedEvent> events = Events.fromRecording(r); Events.hasEvents(events); for (RecordedEvent event : events) { System.out.println("Event:" + event); Events.assertField(event, "msg").equal("Hello"); Events.assertField(event, "id").equal(1L); } r.close(); }
Example #15
Source File: FlightRecorderMXBeanImpl.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
private Notification createNotication(Recording recording) { try { Long id = recording.getId(); Object oldValue = changes.get(recording.getId()); Object newValue = getAttribute(ATTRIBUTE_RECORDINGS); if (recording.getState() != RecordingState.CLOSED) { changes.put(id, newValue); } else { changes.remove(id); } return new AttributeChangeNotification(getObjectName(), sequenceNumber.incrementAndGet(), System.currentTimeMillis(), "Recording " + recording.getName() + " is " + recording.getState(), ATTRIBUTE_RECORDINGS, newValue.getClass().getName(), oldValue, newValue); } catch (AttributeNotFoundException | MBeanException | ReflectionException e) { throw new RuntimeException("Could not create notifcation for FlightRecorderMXBean. " + e.getMessage(), e); } }
Example #16
Source File: TestDestReadOnly.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Throwable { Path readOnlyDir = FileHelper.createReadOnlyDir(Paths.get(".", "readonly")); if (!FileHelper.isReadOnlyPath(readOnlyDir)) { System.out.println("Failed to create read-only dir. Running as root?. Test ignored"); return; } Path readOnlyDest = Paths.get(readOnlyDir.toString(), "readonly.jfr"); Recording r = new Recording(); r.enable(EventNames.OSInformation); r.setToDisk(true); verifyException(()->{r.setDestination(readOnlyDest);}, "No exception for setDestination to read-only dir"); System.out.println("r.getDestination() = " + r.getDestination()); // Verify that it works if we set destination to a writable dir. Path dest = Paths.get(".", "my.jfr"); r.setDestination(dest); r.start(); r.stop(); r.close(); 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 in %s%n", events.get(0).getEventType().getName(), dest.toString()); }
Example #17
Source File: TestGetId.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Throwable { Map<Long, Recording> recordings = new HashMap<>(); final int iterations = 100; for (int i = 0; i < iterations; ++i) { Recording newRecording = new Recording(); System.out.println("created: " + newRecording.getId()); Recording oldRecording = recordings.get(newRecording.getId()); Asserts.assertNull(oldRecording, "Duplicate recording ID: " + newRecording.getId()); recordings.put(newRecording.getId(), newRecording); if (i % 3 == 0) { Recording closeRecording = recordings.remove(recordings.keySet().iterator().next()); Asserts.assertNotNull(closeRecording, "Could not find recording in map. Test error."); closeRecording.close(); System.out.println("closed: " + closeRecording.getId()); } } for (Recording r : recordings.values()) { r.close(); } }
Example #18
Source File: TestBiasedLockRevocationEvents.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
static void testSingleRevocation() throws Throwable { class MyLock {}; Recording recording = new Recording(); recording.enable(EventNames.BiasedLockRevocation); recording.start(); Thread biasBreaker = triggerRevocation(1, MyLock.class); recording.stop(); List<RecordedEvent> events = getRevocationEvents(recording, "lockClass", MyLock.class); Asserts.assertEQ(events.size(), 1); RecordedEvent event = events.get(0); Events.assertEventThread(event, biasBreaker); Events.assertEventThread(event, "previousOwner", Thread.currentThread()); RecordedClass lockClass = event.getValue("lockClass"); Asserts.assertEquals(lockClass.getName(), MyLock.class.getName()); validateStackTrace(event.getStackTrace()); }
Example #19
Source File: TestRecordingBase.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public static void testGetSettings() throws Throwable { String eventPath = "my/test/enabledPath"; String settingName = "myTestSetting"; String settingValue = "myTestValue"; Recording r = new Recording(); r.enable(eventPath).with(settingName, settingValue); boolean isEnabledPathFound = false; boolean isSettingFound = false; Map<String, String> settings = r.getSettings(); for (String name : settings.keySet()) { System.out.println("name=" + name + ", value=" + settings.get(name)); if (name.contains(eventPath) && name.contains("#enabled")) { isEnabledPathFound = true; assertEquals("true", settings.get(name), "Wrong value for enabled path: " + name); } if (name.contains(eventPath) && name.contains(settingName)) { isSettingFound = true; assertEquals(settingValue, settings.get(name), "Wrong value for setting: " + name); } } assertTrue(isEnabledPathFound, "Enabled path not found in settings"); assertTrue(isSettingFound, "Test setting not found in settings"); r.close(); }
Example #20
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 #21
Source File: TestRecordingFileReadEventEof.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Throwable { Recording r = new Recording(); r.start(); SimpleEvent t = new SimpleEvent(); t.commit(); r.stop(); RecordingFile file = Events.copyTo(r); r.close(); file.readEvent(); try { file.readEvent(); Asserts.fail("Expected EOFException not thrown"); } catch (EOFException x) { // OK, as expected } }
Example #22
Source File: TestNative.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { System.loadLibrary("TestNative"); FlightRecorder.getFlightRecorder(); recording = new Recording(); recording.setToDisk(true); recording.setDestination(Paths.get(JFR_DUMP)); recording.enable(NATIVE_EVENT).withPeriod(Duration.ofMillis(10)); recording.start(); longTime(); recording.stop(); recording.close(); try (RecordingFile rf = new RecordingFile(Paths.get(JFR_DUMP))) { while (rf.hasMoreEvents()) { RecordedEvent re = rf.readEvent(); if (re.getEventType().getName().equals(NATIVE_EVENT)) { return; } } } throw new Exception("No native samples found"); }
Example #23
Source File: TestCompilerStats.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { 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, "compileCount").atLeast(0); Events.assertField(event, "bailoutCount").atLeast(0); Events.assertField(event, "invalidatedCount").atLeast(0); Events.assertField(event, "osrCompileCount").atLeast(0); Events.assertField(event, "standardCompileCount").atLeast(0); Events.assertField(event, "osrBytesCompiled").atLeast(0L); Events.assertField(event, "standardBytesCompiled").atLeast(0L); Events.assertField(event, "nmetodsSize").atLeast(0L); Events.assertField(event, "nmetodCodeSize").atLeast(0L); Events.assertField(event, "peakTimeSpent").atLeast(0L); Events.assertField(event, "totalTimeSpent").atLeast(0L); } }
Example #24
Source File: TestCreateNative.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public static void main(String... args) throws Exception { JVM jvm = JVM.getJVM(); // Ensure that repeated failures can be handled for (int i = 1; i < 4; i++) { System.out.println("About to try failed initialization, attempt " + i + " out of 3"); assertFailedInitialization(jvm); System.out.println("As expected, initialization failed."); } // Ensure that Flight Recorder can be initialized properly after failures Configuration defConfig = Configuration.getConfiguration("default"); Recording r = new Recording(defConfig); r.start(); r.stop(); r.dump(Paths.get("recording.jfr")); r.close(); }
Example #25
Source File: TestStateScheduleStart.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Throwable { Recording r = new Recording(); CommonHelper.verifyRecordingState(r, RecordingState.NEW); Instant start = Instant.now(); r.scheduleStart(Duration.ofMillis(2000)); System.out.println("Wait for recording to start: " + start); CommonHelper.waitForRecordingState(r, RecordingState.RUNNING); // Duration should be about 2000 ms. // Test servers vary too much in performance to make an accurate check. // We only check that we don't time out after 20 seconds. Instant started = Instant.now(); long millis = Duration.between(start, started).toMillis(); System.out.println("Recording started at " + started + ". Delta millis=" + millis + ", expeced about 2000"); verifyIllegalState(() -> r.start(), "double start()"); r.stop(); CommonHelper.verifyRecordingState(r, RecordingState.STOPPED); r.close(); CommonHelper.verifyRecordingState(r, RecordingState.CLOSED); }
Example #26
Source File: TestDuration.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Throwable { final Duration duration = Duration.ofSeconds(1); Recording r = new Recording(); r.setDuration(duration); Asserts.assertEquals(duration, r.getDuration(), "Wrong get/set duration"); r.start(); Instant afterStart = Instant.now(); CommonHelper.waitForRecordingState(r, RecordingState.STOPPED); Instant afterStop = Instant.now(); Asserts.assertLessThanOrEqual(r.getStopTime(), afterStop, "getStopTime() > afterStop"); long durationMillis = Duration.between(afterStart, r.getStopTime()).toMillis(); // Performance of test servers varies too much to make a strict check of actual duration. // We only check that recording stops before timeout of 20 seconds. System.out.printf("Recording stopped after %d ms, expected above 1000 ms%n", durationMillis); r.close(); }
Example #27
Source File: TestArrayInformation.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { WhiteBox.setWriteAllObjectSamples(true); try (Recording recording = new Recording()) { recording.enable(EventNames.OldObjectSample).withoutStackTrace().with("cutoff", "infinity"); recording.start(); for(int i = 0; i < 25; i++) { leak.add( buildNestedArray(CHAIN_DEPTH)); } recording.stop(); List<RecordedEvent> events = Events.fromRecording(recording); Events.hasEvents(events); verifyObjectArray(events); } }
Example #28
Source File: TestToString.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Throwable { try (Recording recording = new Recording()) { recording.start(); HelloWorldEvent event = new HelloWorldEvent(); event.message = "hello, world"; event.integer = 4711; event.floatValue = 9898; event.doubleValue = 313; event.clazz = HashMap.class; event.characater = '&'; event.byteValue = (byte) 123; event.longValue = 1234567890L; event.shortValue = 64; event.booleanValue = false; event.commit(); recording.stop(); List<RecordedEvent> events = Events.fromRecording(recording); Events.hasEvents(events); RecordedEvent e = events.get(0); String toString = e.toString(); System.out.println(toString); Asserts.assertTrue(toString.contains("hello, world"), "Missing String field value in RecordedEvent#toSting()"); Asserts.assertTrue(toString.contains("4711"), "Missing integer fields value in RecordedEvent#toSting()"); Asserts.assertTrue(toString.contains("313"), "Missing double value in RecordedEvent#toSting()"); Asserts.assertTrue(toString.contains("HashMap"), "Missing class value in RecordedEvent#toSting()"); Asserts.assertTrue(toString.contains("1234567890"), "Missing long value in RecordedEvent#toSting()"); Asserts.assertTrue(toString.contains("&"), "Missing char value in RecordedEvent#toSting()"); Asserts.assertTrue(toString.contains("123"), "Missing byte value in RecordedEvent#toString()"); Asserts.assertTrue(toString.contains("64"), "Missing short value in RecordedEvent#toString()"); Asserts.assertTrue(toString.contains("false"), "Missing boolean value in RecordedEvent#toString()"); Asserts.assertTrue(toString.contains("HelloWorldEvent"), "Missing class name in RecordedEvent#toString()"); } }
Example #29
Source File: TestDestState.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Throwable { Recording r = new Recording(); SimpleEventHelper.enable(r, true); final Path newDest = Paths.get(".", "new.jfr"); r.setDestination(newDest); System.out.println("new dest: " + r.getDestination()); Asserts.assertEquals(newDest, r.getDestination(), "Wrong get/set dest when new"); r.start(); SimpleEventHelper.createEvent(0); Thread.sleep(100); final Path runningDest = Paths.get(".", "running.jfr"); r.setDestination(runningDest); System.out.println("running dest: " + r.getDestination()); Asserts.assertEquals(runningDest, r.getDestination(), "Wrong get/set dest when running"); SimpleEventHelper.createEvent(1); r.stop(); SimpleEventHelper.createEvent(2); // Expect recording to be saved at destination that was set when // the recording was stopped, which is runningDest. Asserts.assertTrue(Files.exists(runningDest), "No recording file: " + runningDest); List<RecordedEvent> events = RecordingFile.readAllEvents(runningDest); Asserts.assertFalse(events.isEmpty(), "No event found"); System.out.printf("Found event %s%n", events.get(0).getEventType().getName()); r.close(); }
Example #30
Source File: TestRecordedEventGetThreadOther.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private static Path postEventAndDumpToFile() throws Throwable { Recording r = new Recording(); r.start(); TestEvent t = new TestEvent(); t.commit(); r.stop(); Path path = Utils.createTempFile("event-thread", ".jfr"); System.out.println("Created path: " + path); r.dump(path); r.close(); return path; }