Java Code Examples for jdk.jfr.Recording#setToDisk()
The following examples show how to use
jdk.jfr.Recording#setToDisk() .
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: TestDestToDiskTrue.java From TencentKona-8 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 2
Source File: TestRecordingInfo.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(Configuration.getConfiguration("profile")); recording.setDestination(Paths.get(".", "my.jfr")); recording.setDumpOnExit(true); recording.setDuration(Duration.ofSeconds(60)); recording.setMaxAge(Duration.ofHours(1)); recording.setMaxSize(123456789); recording.setName("myName"); recording.enable("java.exception_throw").with("threashold", "2 s"); recording.setToDisk(true); recording.start(); CommonHelper.verifyRecordingState(recording, RecordingState.RUNNING); // Wait until running FlightRecorderMXBean bean = JmxHelper.getFlighteRecorderMXBean(); RecordingInfo info = JmxHelper.verifyExists(recording.getId(), bean.getRecordings()); System.out.println(JmxHelper.asString(recording)); System.out.println(JmxHelper.asString(info)); JmxHelper.verifyEquals(info, recording); recording.stop(); recording.close(); }
Example 3
Source File: TestSplit.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
private static void makeRecordingWithChunks(int count, Path file) throws IOException, ParseException { Recording main = new Recording(Configuration.getConfiguration("default")); // default config disable all events, so ... main.enable(EventNames.JVMInformation); 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 4
Source File: TestStartStopRecording.java From TencentKona-8 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 = Utils.createTempFile("start-stop-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 = Utils.createTempFile("start-stop-disk-recording", ".jfr"); toDisk.dump(diskFile); assertValid(diskFile, "Not a valid disk file."); toDisk.close(); }
Example 5
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 6
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 7
Source File: TestDestFileReadOnly.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Throwable { Path dest = FileHelper.createReadOnlyFile(Paths.get(".", "readonly.txt")); System.out.println("dest=" + dest.toFile().getAbsolutePath()); if (!FileHelper.isReadOnlyPath(dest)) { System.out.println("Failed to create a read-only file. Test ignored."); return; } Recording r = new Recording(); r.setToDisk(true); try { r.setDestination(dest); Asserts.fail("No exception when destination is read-only"); } catch (IOException e) { // Expected exception } r.close(); }
Example 8
Source File: TestStartStopRecording.java From openjdk-jdk8u 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 = Utils.createTempFile("start-stop-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 = Utils.createTempFile("start-stop-disk-recording", ".jfr"); toDisk.dump(diskFile); assertValid(diskFile, "Not a valid disk file."); toDisk.close(); }
Example 9
Source File: TestNative.java From TencentKona-8 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 10
Source File: TestRecordingFile.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private static void testReadEventTypeWithUnregistration(boolean disk, boolean background) throws Exception { FlightRecorder.register(Event1.class); FlightRecorder.register(Event2.class); FlightRecorder.register(Event3.class); Recording backgrundRecording = new Recording(); if (disk) { backgrundRecording.setToDisk(disk); } if (background) { backgrundRecording.start(); } recordAndVerify(disk, background,new int[] {1,2, 3}, new int[] {}); FlightRecorder.unregister(Event2.class); recordAndVerify(disk, background, new int[] {1, 3}, new int[] {2}); FlightRecorder.unregister(Event1.class); FlightRecorder.register(Event2.class); recordAndVerify(disk,background, new int[] {2, 3}, new int[] {1}); FlightRecorder.unregister(Event3.class); FlightRecorder.register(Event3.class); FlightRecorder.unregister(Event2.class); FlightRecorder.unregister(Event3.class); FlightRecorder.register(Event1.class); FlightRecorder.unregister(Event1.class); FlightRecorder.register(Event1.class); FlightRecorder.register(Event2.class); recordAndVerify(disk, background,new int[] {1, 2}, new int[] {3}); if (background) { backgrundRecording.close(); } }
Example 11
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 12
Source File: TestRecordingBase.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
public static void testSetGetToDisk() throws Throwable { Recording r = new Recording(); r.setToDisk(true); assertTrue(r.isToDisk(), "Wrong set/get isToDisk true"); r.setToDisk(false); assertFalse(r.isToDisk(), "Wrong set/get isToDisk false"); r.close(); }
Example 13
Source File: TestDestLongPath.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Throwable { Path dir = FileHelper.createLongDir(Paths.get(".")); Path dest = Paths.get(dir.toString(), "my.jfr"); Recording r = new Recording(); r.enable(EventNames.OSInformation); r.setToDisk(true); 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%n", events.get(0).getEventType().getName()); }
Example 14
Source File: TestRecordingFile.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private static void testReadEventTypeWithUnregistration(boolean disk, boolean background) throws Exception { FlightRecorder.register(Event1.class); FlightRecorder.register(Event2.class); FlightRecorder.register(Event3.class); Recording backgrundRecording = new Recording(); if (disk) { backgrundRecording.setToDisk(disk); } if (background) { backgrundRecording.start(); } recordAndVerify(disk, background,new int[] {1,2, 3}, new int[] {}); FlightRecorder.unregister(Event2.class); recordAndVerify(disk, background, new int[] {1, 3}, new int[] {2}); FlightRecorder.unregister(Event1.class); FlightRecorder.register(Event2.class); recordAndVerify(disk,background, new int[] {2, 3}, new int[] {1}); FlightRecorder.unregister(Event3.class); FlightRecorder.register(Event3.class); FlightRecorder.unregister(Event2.class); FlightRecorder.unregister(Event3.class); FlightRecorder.register(Event1.class); FlightRecorder.unregister(Event1.class); FlightRecorder.register(Event1.class); FlightRecorder.register(Event2.class); recordAndVerify(disk, background,new int[] {1, 2}, new int[] {3}); if (background) { backgrundRecording.close(); } }
Example 15
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 16
Source File: TestDestInvalid.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Throwable { Recording r = new Recording(); r.enable(EventNames.OSInformation); r.setToDisk(true); Asserts.assertNull(r.getDestination(), "dest not null by default"); // Set destination to empty path (same as curr dir, not a file) verifyException(()->{r.setDestination(Paths.get(""));}, "No exception for setDestination(\"\")", IOException.class); System.out.println("1 destination: " + r.getDestination()); Asserts.assertNull(r.getDestination(), "default dest not null after failed setDest"); // Set dest to a valid path. This should be kept when a new setDest fails. Path dest = Paths.get(".", "my.jfr"); r.setDestination(dest); System.out.println("2 destination: " + r.getDestination()); Asserts.assertEquals(dest, r.getDestination(), "Wrong get/set dest"); // Null is allowed for setDestination() r.setDestination(null); System.out.println("3 destination: " + r.getDestination()); Asserts.assertNull(r.getDestination(), "dest not null after setDest(null)"); // Reset dest to correct value and make ssure it is not overwritten r.setDestination(dest); System.out.println("4 destination: " + r.getDestination()); Asserts.assertEquals(dest, r.getDestination(), "Wrong get/set dest"); // Set destination to an existing dir. Old dest is saved. verifyException(()->{r.setDestination(Paths.get("."));}, "No exception for setDestination(.)", IOException.class); System.out.println("5 destination: " + r.getDestination()); Asserts.assertEquals(dest, r.getDestination(), "Wrong get/set dest"); // Set destination to a non-existing dir. Old dest is saved. verifyException(()->{r.setDestination(Paths.get(".", "missingdir", "my.jfr"));}, "No exception for setDestination(dirNotExists)", IOException.class); System.out.println("6 destination: " + r.getDestination()); Asserts.assertEquals(dest, r.getDestination(), "Wrong get/set dest"); // Verify that it works with the old setDest value. 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: TestDestInvalid.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Throwable { Recording r = new Recording(); r.enable(EventNames.OSInformation); r.setToDisk(true); Asserts.assertNull(r.getDestination(), "dest not null by default"); // Set destination to empty path (same as curr dir, not a file) verifyException(()->{r.setDestination(Paths.get(""));}, "No exception for setDestination(\"\")", IOException.class); System.out.println("1 destination: " + r.getDestination()); Asserts.assertNull(r.getDestination(), "default dest not null after failed setDest"); // Set dest to a valid path. This should be kept when a new setDest fails. Path dest = Paths.get(".", "my.jfr"); r.setDestination(dest); System.out.println("2 destination: " + r.getDestination()); Asserts.assertEquals(dest, r.getDestination(), "Wrong get/set dest"); // Null is allowed for setDestination() r.setDestination(null); System.out.println("3 destination: " + r.getDestination()); Asserts.assertNull(r.getDestination(), "dest not null after setDest(null)"); // Reset dest to correct value and make ssure it is not overwritten r.setDestination(dest); System.out.println("4 destination: " + r.getDestination()); Asserts.assertEquals(dest, r.getDestination(), "Wrong get/set dest"); // Set destination to an existing dir. Old dest is saved. verifyException(()->{r.setDestination(Paths.get("."));}, "No exception for setDestination(.)", IOException.class); System.out.println("5 destination: " + r.getDestination()); Asserts.assertEquals(dest, r.getDestination(), "Wrong get/set dest"); // Set destination to a non-existing dir. Old dest is saved. verifyException(()->{r.setDestination(Paths.get(".", "missingdir", "my.jfr"));}, "No exception for setDestination(dirNotExists)", IOException.class); System.out.println("6 destination: " + r.getDestination()); Asserts.assertEquals(dest, r.getDestination(), "Wrong get/set dest"); // Verify that it works with the old setDest value. 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 18
Source File: TestActiveRecordingEvent.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
private static void testWithPath(Path path) throws Throwable { Recording recording = new Recording(); recording.enable(ACTIVE_RECORDING_EVENT_NAME); recording.setDuration(REC_DURATION); recording.setMaxSize(MAX_SIZE); recording.setMaxAge(MAX_AGE); recording.setName(REC_NAME); if (path != null) { recording.setToDisk(true); recording.setDestination(path); } long tsBeforeStart = Instant.now().toEpochMilli(); recording.start(); recording.stop(); long tsAfterStop = Instant.now().toEpochMilli(); List<RecordedEvent> events = Events.fromRecording(recording); Events.hasEvents(events); RecordedEvent ev = events.get(0); // Duration must be kept in milliseconds assertEquals(REC_DURATION.toMillis(), ev.getValue("recordingDuration")); assertEquals(MAX_SIZE, ev.getValue("maxSize")); // maxAge must be kept in milliseconds assertEquals(MAX_AGE.toMillis(), ev.getValue("maxAge")); EventType evType = ev.getEventType(); ValueDescriptor durationField = evType.getField("recordingDuration"); assertEquals(durationField.getAnnotation(Timespan.class).value(), Timespan.MILLISECONDS); if (path == null) { assertNull(ev.getValue("destination")); } else { assertEquals(path.toAbsolutePath().toString(), ev.getValue("destination").toString()); } ValueDescriptor recordingStartField = evType.getField("recordingStart"); assertEquals(recordingStartField.getAnnotation(Timestamp.class).value(), Timestamp.MILLISECONDS_SINCE_EPOCH); long tsRecordingStart = ev.getValue("recordingStart"); assertTrue(tsBeforeStart <= tsRecordingStart); assertTrue(tsAfterStop >= tsRecordingStart); assertEquals(recording.getId(), ev.getValue("id")); ValueDescriptor maxAgeField = evType.getField("maxAge"); assertEquals(maxAgeField.getAnnotation(Timespan.class).value(), Timespan.MILLISECONDS); }
Example 19
Source File: TestGetEventTypes.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Throwable { Recording r1 = new Recording(); r1.setToDisk(true); MyEvent myEvent = new MyEvent(); EventType t = EventType.getEventType(MyEvent.class); System.out.println(t.getName()); boolean isMyEventFound = false; for (EventType eventType : FlightRecorder.getFlightRecorder().getEventTypes()) { System.out.println(": eventType: " + eventType.getName()); r1.enable(eventType.getName()); if (eventType.getName().equals(MyEvent.class.getName())) { isMyEventFound = true; } } assertTrue(isMyEventFound, "EventType for MyEvent not found"); r1.start(); myEvent.begin(); myEvent.end(); myEvent.commit(); r1.stop(); Set<String> eventTypeNames = new HashSet<String>(); for (EventType et : FlightRecorder.getFlightRecorder().getEventTypes()) { assertFalse(eventTypeNames.contains(et.getName()), "EventType returned twice: " + et.getName()); eventTypeNames.add(et.getName()); } isMyEventFound = false; for (RecordedEvent event : Events.fromRecording(r1)) { final String name = event.getEventType().getName(); System.out.println("event.getEventType: " + name); assertTrue(eventTypeNames.contains(name), "Missing EventType: " + name); if (name.equals(MyEvent.class.getName())) { isMyEventFound = true; } } r1.close(); assertTrue(isMyEventFound, "Event for MyEvent not found"); }
Example 20
Source File: TestDestInvalid.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Throwable { Recording r = new Recording(); r.enable(EventNames.OSInformation); r.setToDisk(true); Asserts.assertNull(r.getDestination(), "dest not null by default"); // Set destination to empty path (same as curr dir, not a file) verifyException(()->{r.setDestination(Paths.get(""));}, "No exception for setDestination(\"\")", IOException.class); System.out.println("1 destination: " + r.getDestination()); Asserts.assertNull(r.getDestination(), "default dest not null after failed setDest"); // Set dest to a valid path. This should be kept when a new setDest fails. Path dest = Paths.get(".", "my.jfr"); r.setDestination(dest); System.out.println("2 destination: " + r.getDestination()); Asserts.assertEquals(dest, r.getDestination(), "Wrong get/set dest"); // Null is allowed for setDestination() r.setDestination(null); System.out.println("3 destination: " + r.getDestination()); Asserts.assertNull(r.getDestination(), "dest not null after setDest(null)"); // Reset dest to correct value and make ssure it is not overwritten r.setDestination(dest); System.out.println("4 destination: " + r.getDestination()); Asserts.assertEquals(dest, r.getDestination(), "Wrong get/set dest"); // Set destination to an existing dir. Old dest is saved. verifyException(()->{r.setDestination(Paths.get("."));}, "No exception for setDestination(.)", IOException.class); System.out.println("5 destination: " + r.getDestination()); Asserts.assertEquals(dest, r.getDestination(), "Wrong get/set dest"); // Set destination to a non-existing dir. Old dest is saved. verifyException(()->{r.setDestination(Paths.get(".", "missingdir", "my.jfr"));}, "No exception for setDestination(dirNotExists)", IOException.class); System.out.println("6 destination: " + r.getDestination()); Asserts.assertEquals(dest, r.getDestination(), "Wrong get/set dest"); // Verify that it works with the old setDest value. 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()); }