jdk.jfr.consumer.RecordingFile Java Examples
The following examples show how to use
jdk.jfr.consumer.RecordingFile.
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: TestDumpInvalid.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.enable(EventNames.OSInformation); r.start(); r.stop(); verifyNullPointer(()->{r.dump(null);}, "No NullPointerException"); Path pathNotExists = Paths.get(".", "dirNotExists", "my.jfr"); verifyFileNotFound(()->{r.dump(pathNotExists);}, "No Exception with missing dir"); Path pathEmpty = Paths.get(""); verifyFileNotFound(()->{r.dump(pathEmpty);}, "No Exception with empty path"); Path pathDir = Paths.get(".", "newdir"); Files.createDirectory(pathDir); verifyFileNotFound(()->{r.dump(pathDir);}, "No Exception with dir"); // Verify that copyTo() works after all failed attempts. Path pathOk = Paths.get(".", "newdir", "my.jfr"); r.dump(pathOk); Asserts.assertTrue(Files.exists(pathOk), "Recording file does not exist: " + pathOk); Asserts.assertFalse(RecordingFile.readAllEvents(pathOk).isEmpty(), "No events found"); r.close(); }
Example #2
Source File: TestGetStream.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
private static void assertContainsId(Recording r, String interval, Instant start, Instant end, Integer... ids) throws IOException { List<Integer> idList = new ArrayList<>(Arrays.asList(ids)); long time = System.currentTimeMillis(); String fileName = idList.stream().map(x -> x.toString()).collect(Collectors.joining("_", "recording-get-stream_" + time + "_", ".jfr")); Path file = Paths.get(fileName); try (InputStream is = r.getStream(start, end)) { Files.copy(is, file, StandardCopyOption.REPLACE_EXISTING); } try (RecordingFile rf = new RecordingFile(file)) { while (rf.hasMoreEvents()) { RecordedEvent event = rf.readEvent(); Integer id = event.getValue("id"); Asserts.assertTrue(idList.contains(id), "Unexpected id " + id + " found in interval " + interval); idList.remove(id); } Asserts.assertTrue(idList.isEmpty(), "Expected events with ids " + idList); } }
Example #3
Source File: PromotionFailedEvent.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public static void test(String testName, String[] vmFlags) throws Throwable { String jfr_file = testName + ".jfr"; if (!ExecuteOOMApp.execute(EVENT_SETTINGS_FILE, jfr_file, vmFlags, BYTES_TO_ALLOCATE)) { System.out.println("OOM happened in the other thread(not test thread). Skip test."); // Skip test, process terminates due to the OOME error in the different thread return; } // This test can not always trigger the expected event. // Test is ok even if no events found. List<RecordedEvent> events = RecordingFile.readAllEvents(Paths.get(jfr_file)); for (RecordedEvent event : events) { System.out.println("Event: " + event); long smallestSize = Events.assertField(event, "promotionFailed.smallestSize").atLeast(1L).getValue(); long firstSize = Events.assertField(event, "promotionFailed.firstSize").atLeast(smallestSize).getValue(); long totalSize = Events.assertField(event, "promotionFailed.totalSize").atLeast(firstSize).getValue(); long objectCount = Events.assertField(event, "promotionFailed.objectCount").atLeast(1L).getValue(); Asserts.assertLessThanOrEqual(smallestSize * objectCount, totalSize, "smallestSize * objectCount <= totalSize"); } }
Example #4
Source File: TestRecordingFile.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
private static void testIterate(Path valid, Path broken) throws Exception { try (RecordingFile validFile = new RecordingFile(valid)) { for (int i = 0; i < EVENT_COUNT; i++) { if (!validFile.hasMoreEvents()) { throw new Exception("Not all events available"); } RecordedEvent r = validFile.readEvent(); if (r == null) { throw new Exception("Missing event"); } if (!r.getEventType().getName().contains(TEST_CLASS_BASE)) { throw new Exception("Incorrect event in recording file " + r); } } if (validFile.hasMoreEvents()) { throw new Exception("Should not be more than " + EVENT_COUNT + " in recording"); } } try (RecordingFile brokenFile = new RecordingFile(broken)) { brokenFile.readEvent(); throw new Exception("Expected IOException for broken recording"); } catch (IOException ise) { // OK } }
Example #5
Source File: TestDumpState.java From TencentKona-8 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 #6
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 #7
Source File: TestSummary.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Throwable { Path f = ExecuteHelper.createProfilingRecording().toAbsolutePath(); String file = f.toAbsolutePath().toString(); OutputAnalyzer output = ExecuteHelper.jfr("summary"); output.shouldContain("missing file"); output = ExecuteHelper.jfr("summary", "--wrongOption", file); output.shouldContain("too many arguments"); output = ExecuteHelper.jfr("summary", file); try (RecordingFile rf = new RecordingFile(f)) { for (EventType t : rf.readEventTypes()) { output.shouldContain(t.getName()); } } output.shouldContain("Version"); }
Example #8
Source File: PromotionFailedEvent.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
public static void test(String testName, String[] vmFlags) throws Throwable { String jfr_file = testName + ".jfr"; if (!ExecuteOOMApp.execute(EVENT_SETTINGS_FILE, jfr_file, vmFlags, BYTES_TO_ALLOCATE)) { System.out.println("OOM happened in the other thread(not test thread). Skip test."); // Skip test, process terminates due to the OOME error in the different thread return; } // This test can not always trigger the expected event. // Test is ok even if no events found. List<RecordedEvent> events = RecordingFile.readAllEvents(Paths.get(jfr_file)); for (RecordedEvent event : events) { System.out.println("Event: " + event); long smallestSize = Events.assertField(event, "promotionFailed.smallestSize").atLeast(1L).getValue(); long firstSize = Events.assertField(event, "promotionFailed.firstSize").atLeast(smallestSize).getValue(); long totalSize = Events.assertField(event, "promotionFailed.totalSize").atLeast(firstSize).getValue(); long objectCount = Events.assertField(event, "promotionFailed.objectCount").atLeast(1L).getValue(); Asserts.assertLessThanOrEqual(smallestSize * objectCount, totalSize, "smallestSize * objectCount <= totalSize"); } }
Example #9
Source File: XMLWriter.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public void print(Path source) throws IOException { try (RecordingFile es = new RecordingFile(source)) { println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); println("<recording>"); indent(); printIndent(); println("<events>"); indent(); while (es.hasMoreEvents()) { printEvent(es.readEvent()); flush(); } retract(); printIndent(); println("</events>"); retract(); println("</recording>"); flush(); } }
Example #10
Source File: TestDestToDiskTrue.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
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 #11
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 #12
Source File: TestCMSConcurrentModeFailureEvent.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { String[] vmFlags = {"-Xmx128m", "-XX:MaxTenuringThreshold=0", "-XX:+UseConcMarkSweepGC", "-XX:+UnlockExperimentalVMOptions", "-XX:-UseFastUnorderedTimeStamps"}; if (!ExecuteOOMApp.execute(EVENT_SETTINGS_FILE, JFR_FILE, vmFlags, BYTES_TO_ALLOCATE)) { System.out.println("OOM happened in the other thread(not test thread). Skip test."); // Skip test, process terminates due to the OOME error in the different thread return; } Optional<RecordedEvent> event = RecordingFile.readAllEvents(Paths.get(JFR_FILE)).stream().findFirst(); if (event.isPresent()) { Asserts.assertEquals(EVENT_NAME, event.get().getEventType().getName(), "Wrong event type"); } else { // No event received. Check if test did trigger the event. boolean isEventTriggered = fileContainsString("testCMSGC.log", "concurrent mode failure"); System.out.println("isEventTriggered=" +isEventTriggered); Asserts.assertFalse(isEventTriggered, "Event found in log, but not in JFR"); } }
Example #13
Source File: TestMetadata.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Throwable { Path f = ExecuteHelper.createProfilingRecording().toAbsolutePath(); String file = f.toAbsolutePath().toString(); OutputAnalyzer output = ExecuteHelper.jfr("metadata"); output.shouldContain("missing file"); output = ExecuteHelper.jfr("metadata", "--wrongOption", file); output.shouldContain("unknown option --wrongOption"); output = ExecuteHelper.jfr("metadata", file); try (RecordingFile rf = new RecordingFile(f)) { for (EventType t : rf.readEventTypes()) { String name = t.getName(); name = name.substring(name.lastIndexOf(".") + 1); output.shouldContain(name); } } }
Example #14
Source File: TestRecordingFile.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
private static void testReadEventTypes(Path valid, Path broken) throws Exception { try (RecordingFile validFile = new RecordingFile(valid)) { List<EventType> types = validFile.readEventTypes(); if (types.size() < EVENT_COUNT) { throw new Exception("Expected at least " + EVENT_COUNT + " event type but got " + types.toString()); } int counter = 0; for (Class<?> testClass : Arrays.asList(TestEvent1.class, TestEvent2.class, TestEvent3.class)) { for (EventType t : types) { if (t.getName().equals(testClass.getName())) { counter++; } } } if (counter != 3) { throw new Exception("Returned incorrect event types"); } } try (RecordingFile brokenFile = new RecordingFile(broken)) { brokenFile.readEventTypes(); throw new Exception("Expected IOException when getting Event Types from broken recording"); } catch (IOException ise) { // OK } }
Example #15
Source File: TestCMSConcurrentModeFailureEvent.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { String[] vmFlags = {"-Xmx128m", "-XX:MaxTenuringThreshold=0", "-Xloggc:testCMSGC.log", "-verbose:gc", "-XX:+UseConcMarkSweepGC", "-XX:+UnlockExperimentalVMOptions", "-XX:-UseFastUnorderedTimeStamps"}; if (!ExecuteOOMApp.execute(EVENT_SETTINGS_FILE, JFR_FILE, vmFlags, BYTES_TO_ALLOCATE)) { System.out.println("OOM happened in the other thread(not test thread). Skip test."); // Skip test, process terminates due to the OOME error in the different thread return; } Optional<RecordedEvent> event = RecordingFile.readAllEvents(Paths.get(JFR_FILE)).stream().findFirst(); if (event.isPresent()) { Asserts.assertEquals(EVENT_NAME, event.get().getEventType().getName(), "Wrong event type"); } else { // No event received. Check if test did trigger the event. boolean isEventTriggered = fileContainsString("testCMSGC.log", "concurrent mode failure"); System.out.println("isEventTriggered=" +isEventTriggered); Asserts.assertFalse(isEventTriggered, "Event found in log, but not in JFR"); } }
Example #16
Source File: TestRecordedEventGetThreadOther.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Throwable { Thread.currentThread().setName("MyMainThread"); PostingThread thread = new PostingThread(); thread.start(); thread.join(); System.out.println("testing dump in file " + dumpFilePath); List<RecordedEvent> events = RecordingFile.readAllEvents(dumpFilePath); Asserts.assertEquals(events.size(), 1); RecordedEvent event = events.get(0); RecordedThread recordedThread = event.getThread(); Asserts.assertNotNull(recordedThread); Asserts.assertEquals(recordedThread.getJavaName(), MY_THREAD_NAME); Asserts.assertEquals(recordedThread.getJavaThreadId(), expectedThreadId); Asserts.assertNotNull(recordedThread.getId()); Asserts.assertEquals(recordedThread.getOSName(), MY_THREAD_NAME); }
Example #17
Source File: TestRecordingFileReadEventEof.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(); 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 #18
Source File: TestNative.java From dragonwell8_jdk 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 #19
Source File: TestEvacuationFailedEvent.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { String[] vmFlags = {"-XX:+UnlockExperimentalVMOptions", "-XX:-UseFastUnorderedTimeStamps", "-Xmx64m", "-Xmn60m", "-XX:-UseDynamicNumberOfGCThreads", "-XX:ParallelGCThreads=3", "-XX:MaxTenuringThreshold=0", "-verbose:gc", "-XX:+UseG1GC"}; if (!ExecuteOOMApp.execute(EVENT_SETTINGS_FILE, JFR_FILE, vmFlags, BYTES_TO_ALLOCATE)) { System.out.println("OOM happened in the other thread(not test thread). Skip test."); // Skip test, process terminates due to the OOME error in the different thread return; } List<RecordedEvent> events = RecordingFile.readAllEvents(Paths.get(JFR_FILE)); Events.hasEvents(events); for (RecordedEvent event : events) { long objectCount = Events.assertField(event, "evacuationFailed.objectCount").atLeast(1L).getValue(); long smallestSize = Events.assertField(event, "evacuationFailed.smallestSize").atLeast(1L).getValue(); long firstSize = Events.assertField(event, "evacuationFailed.firstSize").atLeast(smallestSize).getValue(); long totalSize = Events.assertField(event, "evacuationFailed.totalSize").atLeast(firstSize).getValue(); Asserts.assertLessThanOrEqual(smallestSize * objectCount, totalSize, "smallestSize * objectCount <= totalSize"); } }
Example #20
Source File: TestDumpState.java From dragonwell8_jdk 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 #21
Source File: TestAssemble.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
private static long countEventInRecording(Path file) throws IOException { Integer lastId = -1; try (RecordingFile rf = new RecordingFile(file)) { long count = 0; while (rf.hasMoreEvents()) { RecordedEvent re = rf.readEvent(); if (re.getEventType().getName().equals("Correlation")) { Integer id = re.getValue("id"); if (id < lastId) { Asserts.fail("Expected chunk number to increase"); } lastId = id; } count++; } return count; } }
Example #22
Source File: CommonHelper.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
private synchronized static RecordedEvent getTimeStampCounterEvent() throws IOException, Exception { if (timeStampCounterEvent == null) { try (Recording r = new Recording()) { r.enable(EventNames.CPUTimeStampCounter); r.start(); r.stop(); Path p = Utils.createTempFile("timestamo", ".jfr"); r.dump(p); List<RecordedEvent> events = RecordingFile.readAllEvents(p); Files.deleteIfExists(p); if (events.isEmpty()) { throw new Exception("Could not locate CPUTimeStampCounter event"); } timeStampCounterEvent = events.get(0); } } return timeStampCounterEvent; }
Example #23
Source File: TestReconstruct.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
private static long countEventInRecording(Path file) throws IOException { Integer lastId = -1; try (RecordingFile rf = new RecordingFile(file)) { long count = 0; while (rf.hasMoreEvents()) { RecordedEvent re = rf.readEvent(); if (re.getEventType().getName().equals("Correlation")) { Integer id = re.getValue("id"); if (id < lastId) { Asserts.fail("Expected chunk number to increase"); } lastId = id; } count++; } return count; } }
Example #24
Source File: TestDestFileExist.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Throwable { Path dest = Paths.get(".", "my.jfr"); System.out.println("dest=" + dest); Files.write(dest, "Dummy data".getBytes()); assertTrue(Files.exists(dest), "Test error: Failed to create file"); System.out.println("file size before recording:" + Files.size(dest)); Recording r = new Recording(); r.enable(EventNames.OSInformation); r.setDestination(dest); r.start(); r.stop(); List<RecordedEvent> events = RecordingFile.readAllEvents(dest); Asserts.assertFalse(events.isEmpty(), "No events found"); System.out.println(events.iterator().next()); r.close(); }
Example #25
Source File: JFRSecurityTestSuite.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
private static void checkRecording() throws Throwable { boolean myEvent3Found = false; try (RecordingFile rf = new RecordingFile(recFilePath)) { while (rf.hasMoreEvents()) { RecordedEvent event = rf.readEvent(); if (event.getEventType().getName().equals( "JFRSecurityTestSuite$MyEvent3")) { if (DEBUG) { System.out.println("Recording of MyEvent3 event:"); System.out.println(event); } myEvent3Found = true; break; } } } if (!myEvent3Found) { throw new Exception("MyEvent3 event was expected in JFR recording"); } }
Example #26
Source File: TestDestWithDuration.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Throwable { Path dest = Paths.get(".", "my.jfr"); Recording r = new Recording(); SimpleEventHelper.enable(r, true); r.setDestination(dest); r.start(); SimpleEventHelper.createEvent(1); // Waiting for recording to auto close after duration r.setDuration(Duration.ofSeconds(1)); System.out.println("Waiting for recording to auto close after duration"); CommonHelper.waitForRecordingState(r, RecordingState.CLOSED); System.out.println("recording state = " + r.getState()); Asserts.assertEquals(r.getState(), RecordingState.CLOSED, "Recording not closed"); Asserts.assertTrue(Files.exists(dest), "No recording file: " + dest); System.out.printf("Recording file size=%d%n", Files.size(dest)); Asserts.assertNotEquals(Files.size(dest), 0L, "File length 0. Should at least be some bytes"); 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()); }
Example #27
Source File: CustomEvent.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public static void assertOnDisk(Comparator<SettingDescriptor> c) throws Exception { EventType in = EventType.getEventType(CustomEvent.class); Path p = Paths.get("custom.jfr"); try (Recording r = new Recording()) { r.start(); r.stop(); r.dump(p); } try (RecordingFile f = new RecordingFile(p)) { for (EventType out : f.readEventTypes()) { if (out.getName().equals(CustomEvent.class.getName())) { if (out.getSettingDescriptors().size() != in.getSettingDescriptors().size()) { throw new Exception("Number of settings doesn't match"); } for (SettingDescriptor os : out.getSettingDescriptors()) { SettingDescriptor is = Events.getSetting(in, os.getName()); if (c.compare(os, is) != 0) { throw new Exception("Setting with name " + is.getName() + " doesn't match"); } } return; } } } throw new Exception("Could not event type with name " + CustomEvent.class.getName()); }
Example #28
Source File: TestCMSConcurrentModeFailureEvent.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { String[] vmFlags = {"-Xmx128m", "-XX:MaxTenuringThreshold=0", "-Xloggc:testCMSGC.log", "-verbose:gc", "-XX:+UseConcMarkSweepGC", "-XX:+UnlockExperimentalVMOptions", "-XX:-UseFastUnorderedTimeStamps"}; if (!ExecuteOOMApp.execute(EVENT_SETTINGS_FILE, JFR_FILE, vmFlags, BYTES_TO_ALLOCATE)) { System.out.println("OOM happened in the other thread(not test thread). Skip test."); // Skip test, process terminates due to the OOME error in the different thread return; } Optional<RecordedEvent> event = RecordingFile.readAllEvents(Paths.get(JFR_FILE)).stream().findFirst(); if (event.isPresent()) { Asserts.assertEquals(EVENT_NAME, event.get().getEventType().getName(), "Wrong event type"); } else { // No event received. Check if test did trigger the event. boolean isEventTriggered = fileContainsString("testCMSGC.log", "concurrent mode failure"); System.out.println("isEventTriggered=" +isEventTriggered); Asserts.assertFalse(isEventTriggered, "Event found in log, but not in JFR"); } }
Example #29
Source File: TestSummary.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { Path f = ExecuteHelper.createProfilingRecording().toAbsolutePath(); String file = f.toAbsolutePath().toString(); OutputAnalyzer output = ExecuteHelper.run("summary"); output.shouldContain("Missing file"); output = ExecuteHelper.run("summary", "--wrongOption", file); output.shouldContain("Too many arguments"); output = ExecuteHelper.run("summary", file); try (RecordingFile rf = new RecordingFile(f)) { for (EventType t : rf.readEventTypes()) { output.shouldContain(t.getName()); } } output.shouldContain("Version"); }
Example #30
Source File: TestDumpInvalid.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.enable(EventNames.OSInformation); r.start(); r.stop(); verifyNullPointer(()->{r.dump(null);}, "No NullPointerException"); Path pathNotExists = Paths.get(".", "dirNotExists", "my.jfr"); verifyFileNotFound(()->{r.dump(pathNotExists);}, "No Exception with missing dir"); Path pathEmpty = Paths.get(""); verifyFileNotFound(()->{r.dump(pathEmpty);}, "No Exception with empty path"); Path pathDir = Paths.get(".", "newdir"); Files.createDirectory(pathDir); verifyFileNotFound(()->{r.dump(pathDir);}, "No Exception with dir"); // Verify that copyTo() works after all failed attempts. Path pathOk = Paths.get(".", "newdir", "my.jfr"); r.dump(pathOk); Asserts.assertTrue(Files.exists(pathOk), "Recording file does not exist: " + pathOk); Asserts.assertFalse(RecordingFile.readAllEvents(pathOk).isEmpty(), "No events found"); r.close(); }