Java Code Examples for jdk.jfr.Recording#dump()
The following examples show how to use
jdk.jfr.Recording#dump() .
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: Events.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
private static Path makeCopy(Recording recording) throws IOException { Path p = recording.getDestination(); int pid = 0; try { pid = ProcessTools.getProcessId(); } catch (Exception e) { //do nothing, let's use 0 } if (p == null) { File directory = new File("."); // FIXME: Must come up with a way to give human-readable name // this will at least not clash when running parallel. p = new File(directory.getAbsolutePath(), "recording-" + recording.getId() + "-pid" + pid + ".jfr").toPath(); recording.dump(p); } return p; }
Example 2
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 3
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 4
Source File: TestStartStopRecording.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String... args) throws Exception { Configuration defaultConfig = Configuration.getConfiguration("default"); // Memory Recording inMemory = new Recording(defaultConfig); inMemory.setToDisk(false); inMemory.start(); Path memoryFile = Files.createTempFile("memory-recording", ".jfr"); inMemory.dump(memoryFile); assertValid(memoryFile, "Not a valid memory file."); inMemory.stop(); inMemory.close(); // Disk Recording toDisk = new Recording(defaultConfig); toDisk.setToDisk(true); toDisk.start(); toDisk.stop(); Path diskFile = Files.createTempFile("disk-recording", ".jfr"); toDisk.dump(diskFile); assertValid(diskFile, "Not a valid disk file."); toDisk.close(); }
Example 5
Source File: TestJcmdDumpLimited.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
TestRecording(int id, int events) throws IOException, InterruptedException { r = new Recording(); r.start(); for (int i = 0; i < events; i++) { TestEvent event = new TestEvent(); event.id = id; event.number = i; event.commit(); if (i == events / 2) { time = Instant.now(); } } r.stop(); Thread.sleep(1); path = Paths.get("dump-" + id + ".jfr"); r.dump(path); size = (int) Files.size(path); this.id = id; this.now = Instant.now(); }
Example 6
Source File: TestJcmdDumpLimited.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
TestRecording(int id, int events) throws IOException, InterruptedException { r = new Recording(); r.start(); for (int i = 0; i < events; i++) { TestEvent event = new TestEvent(); event.id = id; event.number = i; event.commit(); if (i == events / 2) { time = Instant.now(); } } r.stop(); Thread.sleep(1); path = Paths.get("dump-" + id + ".jfr"); r.dump(path); size = (int) Files.size(path); this.id = id; this.now = Instant.now(); }
Example 7
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 8
Source File: TestReadTwice.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Throwable { Recording r = new Recording(); r.enable(MyEvent.class).withoutStackTrace(); r.start(); // Commit a single event to the recording MyEvent event = new MyEvent(); event.commit(); r.stop(); // Dump the recording to a file Path path = Utils.createTempFile("read-twice", ".jfr"); System.out.println("Dumping to " + path); r.dump(path); r.close(); // Read all events from the file in one go List<RecordedEvent> events = RecordingFile.readAllEvents(path); // Read again the same events one by one RecordingFile rfile = new RecordingFile(path); List<RecordedEvent> events2 = new LinkedList<>(); while (rfile.hasMoreEvents()) { events2.add(rfile.readEvent()); } // Compare sizes Asserts.assertEquals(events.size(), events2.size()); rfile.close(); }
Example 9
Source File: TestUnloadingEventClass.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private static Object getEventType(Recording r, long id, String eventName) throws IOException { Path p = Utils.createTempFile("unloading-event-class-recording-" + id + "_", ".jfr"); r.dump(p); try (RecordingFile rf = new RecordingFile(p)) { for (EventType et : rf.readEventTypes()) { if (et.getName().equals(eventName)) { return et; } } } return null; }
Example 10
Source File: TestReadTwice.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Throwable { Recording r = new Recording(); r.enable(MyEvent.class).withoutStackTrace(); r.start(); // Commit a single event to the recording MyEvent event = new MyEvent(); event.commit(); r.stop(); // Dump the recording to a file Path path = Utils.createTempFile("read-twice", ".jfr"); System.out.println("Dumping to " + path); r.dump(path); r.close(); // Read all events from the file in one go List<RecordedEvent> events = RecordingFile.readAllEvents(path); // Read again the same events one by one RecordingFile rfile = new RecordingFile(path); List<RecordedEvent> events2 = new LinkedList<>(); while (rfile.hasMoreEvents()) { events2.add(rfile.readEvent()); } // Compare sizes Asserts.assertEquals(events.size(), events2.size()); rfile.close(); }
Example 11
Source File: TestUnloadingEventClass.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
private static Object getEventType(Recording r, long id, String eventName) throws IOException { Path p = Files.createTempFile("recording-" + id + "_", ".jfr"); r.dump(p); try (RecordingFile rf = new RecordingFile(p)) { for (EventType et : rf.readEventTypes()) { if (et.getName().equals(eventName)) { return et; } } } return null; }
Example 12
Source File: TestUnloadingEventClass.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private static Object getEventType(Recording r, long id, String eventName) throws IOException { Path p = Utils.createTempFile("unloading-event-class-recording-" + id + "_", ".jfr"); r.dump(p); try (RecordingFile rf = new RecordingFile(p)) { for (EventType et : rf.readEventTypes()) { if (et.getName().equals(eventName)) { return et; } } } return null; }
Example 13
Source File: TestGetSize.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Throwable { Path dest = Paths.get(".", "my.jfr"); Recording r = new Recording(); r.setToDisk(true); r.enable(EventNames.OSInformation); assertEquals(r.getSize(), 0L, "getSize should return 0 before recording starts"); r.start(); r.stop(); r.dump(dest); assertTrue(Files.exists(dest), "TestGetSize recording missing: " + dest); System.out.printf("%s size: %d%n", dest, Files.size(dest)); System.out.printf("r.getSize(): %d%n", r.getSize()); assertEquals(Files.size(dest), r.getSize(), "TestGetSize wrong recording size"); r.close(); }
Example 14
Source File: MainTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private static Path makeCopy(Recording recording) throws IOException { Path p = recording.getDestination(); if (p == null) { File directory = new File("."); ProcessHandle h = ProcessHandle.current(); p = new File(directory.getAbsolutePath(), "recording-" + recording.getId() + "-pid" + h.pid() + ".jfr").toPath(); recording.dump(p); } return p; }
Example 15
Source File: TestGetSize.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Throwable { Path dest = Paths.get(".", "my.jfr"); Recording r = new Recording(); r.setToDisk(true); r.enable(EventNames.OSInformation); assertEquals(r.getSize(), 0L, "getSize should return 0 before recording starts"); r.start(); r.stop(); r.dump(dest); assertTrue(Files.exists(dest), "TestGetSize recording missing: " + dest); System.out.printf("%s size: %d%n", dest, Files.size(dest)); System.out.printf("r.getSize(): %d%n", r.getSize()); assertEquals(Files.size(dest), r.getSize(), "TestGetSize wrong recording size"); r.close(); }
Example 16
Source File: TestRecordedEventGetThreadOther.java From dragonwell8_jdk 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 = Files.createTempFile("recording", ".jfr"); System.out.println("Created path: " + path); r.dump(path); r.close(); return path; }
Example 17
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; }
Example 18
Source File: MainTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
private static Path makeCopy(Recording recording) throws IOException { Path p = recording.getDestination(); if (p == null) { File directory = new File("."); ProcessHandle h = ProcessHandle.current(); p = new File(directory.getAbsolutePath(), "recording-" + recording.getId() + "-pid" + h.pid() + ".jfr").toPath(); recording.dump(p); } return p; }
Example 19
Source File: TestDisassemble.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private static void makeRecordingWithChunks(int count, Path file) throws IOException, ParseException { Recording main = new Recording(Configuration.getConfiguration("default")); main.setToDisk(true); main.start(); for (int i = 0; i < count; i++) { Recording r = new Recording(); r.setToDisk(true); r.start(); r.stop(); r.close(); } main.stop(); main.dump(file); main.close(); }
Example 20
Source File: TestJavaMonitorInflateEvent.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { Recording recording = new Recording(); recording.enable(EVENT_NAME).withThreshold(Duration.ofMillis(0)); final Lock lock = new Lock(); final CountDownLatch latch = new CountDownLatch(1); // create a thread that waits TestThread waitThread = new TestThread(new XRun() { @Override public void xrun() throws Throwable { synchronized (lock) { latch.countDown(); lock.wait(WAIT_TIME); } } }); try { recording.start(); waitThread.start(); latch.await(); synchronized (lock) { lock.notifyAll(); } } finally { waitThread.join(); recording.stop(); } final String thisThreadName = Thread.currentThread().getName(); final String waitThreadName = waitThread.getName(); final String lockClassName = lock.getClass().getName().replace('.', '/'); boolean isAnyFound = false; try { // Find at least one event with the correct monitor class and check the other fields for (RecordedEvent event : Events.fromRecording(recording)) { assertTrue(EVENT_NAME.equals(event.getEventType().getName()), "mismatched event types?"); // Check recorded inflation event is associated with the Lock class used in the test final String recordedMonitorClassName = Events.assertField(event, FIELD_KLASS_NAME).getValue(); if (!lockClassName.equals(recordedMonitorClassName)) { continue; } // Check recorded thread matches one of the threads in the test final String recordedThreadName = event.getThread().getJavaName(); if (!(recordedThreadName.equals(waitThreadName) || recordedThreadName.equals(thisThreadName))) { continue; } Events.assertField(event, FIELD_ADDRESS).notEqual(0L); // unsupported cause in ajdk8 // Events.assertField(event, FIELD_CAUSE).notNull(); isAnyFound = true; break; } assertTrue(isAnyFound, "Expected an inflation event from test"); } catch (Throwable e) { recording.dump(Paths.get("failed.jfr")); throw e; } finally { recording.close(); } }