Java Code Examples for jdk.jfr.Recording#start()
The following examples show how to use
jdk.jfr.Recording#start() .
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: TestDisabledEvents.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Throwable { File tmp = File.createTempFile("TestDisabledEvents", ".tmp", new File(".")); tmp.deleteOnExit(); Recording recording = new Recording(); recording.disable(IOEvent.EVENT_FILE_READ); recording.disable(IOEvent.EVENT_FILE_WRITE); recording.start(); useRandomAccessFile(tmp); useFileStreams(tmp); useFileChannel(tmp); recording.stop(); for (RecordedEvent event : Events.fromRecording(recording)) { final String eventName = event.getEventType().getName(); System.out.println("Got eventName:" + eventName); assertNotEquals(eventName, IOEvent.EVENT_FILE_READ, "Got disabled read event"); assertNotEquals(eventName, IOEvent.EVENT_FILE_WRITE, "Got disabled write event"); } }
Example 2
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 3
Source File: TestDumpLongPath.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(); final String eventPath = EventNames.OSInformation; r.enable(eventPath); r.start(); r.stop(); Path dir = FileHelper.createLongDir(Paths.get(".")); Path path = Paths.get(dir.toString(), "my.jfr"); r.dump(path); r.close(); Asserts.assertTrue(Files.exists(path), "Recording file does not exist: " + path); List<RecordedEvent> events = RecordingFile.readAllEvents(path); Asserts.assertFalse(events.isEmpty(), "No events found"); String foundEventPath = events.get(0).getEventType().getName(); System.out.printf("Found event: %s%n", foundEventPath); Asserts.assertEquals(foundEventPath, eventPath, "Wrong event"); }
Example 4
Source File: TestCodeCacheFull.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
private static void testWithBlobType(BlobType btype, long availableSize) throws Exception { Recording r = new Recording(); r.enable(EventNames.CodeCacheFull); r.start(); WhiteBox.getWhiteBox().allocateCodeBlob(availableSize, btype.id); r.stop(); List<RecordedEvent> events = Events.fromRecording(r); Events.hasEvents(events); RecordedEvent event = events.get(0); String codeBlobType = Events.assertField(event, "codeBlobType").notNull().getValue(); BlobType blobType = blobTypeFromName(codeBlobType); Asserts.assertTrue(blobType.allowTypeWhenOverflow(blobType), "Unexpected overflow BlobType " + blobType.id); Events.assertField(event, "entryCount").atLeast(0); Events.assertField(event, "methodCount").atLeast(0); Events.assertEventThread(event); Events.assertField(event, "fullCount").atLeast(0); Events.assertField(event, "startAddress").notEqual(0L); Events.assertField(event, "commitedTopAddress").notEqual(0L); Events.assertField(event, "reservedTopAddress").notEqual(0L); }
Example 5
Source File: TestClinitRegistration.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { // Test basic registration with or without auto registration assertClinitRegister(AutoRegisteredEvent.class, true, false); assertClinitRegister(NotAutoRegisterededEvent.class, false, false); assertClinitRegister(AutoRegisteredUserClinit.class, true, true); assertClinitRegister(NotAutoRegisteredUserClinit.class, false, true); // Test complex <clinit> assertClinitRegister(ComplexClInit.class, true, true); // Test hierarchy assertClinitRegister(DerivedClinit.class, true, true); if (!isClinitExecuted(Base.class)) { Asserts.fail("Expected <clinit> of base class to be executed"); } // Test committed event in <clinit> Recording r = new Recording(); r.start(); r.enable(EventInClinit.class); triggerClinit(EventInClinit.class); r.stop(); hasEvent(r, EventInClinit.class.getName()); }
Example 6
Source File: TestG1EvacMemoryStatsEvent.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public static void runTest(String event_name) throws Exception { Recording recording = new Recording(); // activate the event we are interested in and start recording recording.enable(event_name); recording.start(); // Setting NewSize and MaxNewSize will limit eden, so // allocating 1024 5k byte arrays should trigger at // least one Young GC. for (int i = 0; i < 1024; i++) { bytes = new byte[5 * 1024]; } recording.stop(); // Verify recording List<RecordedEvent> all = Events.fromRecording(recording); for (RecordedEvent e : all) { Events.assertField(e, "statistics.gcId").above(0); } recording.close(); }
Example 7
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 8
Source File: TestThreadSleepEvent.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Throwable { Recording recording = new Recording(); recording.enable(EVENT_NAME).withThreshold(Duration.ofMillis(0)); recording.start(); Thread.sleep(SLEEP_TIME_MS); recording.stop(); List<RecordedEvent> events = Events.fromRecording(recording); boolean isAnyFound = false; for (RecordedEvent event : events) { if (event.getThread().getJavaThreadId() == Thread.currentThread().getId()) { System.out.println("Event:" + event); isAnyFound = true; Events.assertField(event, "time").equal(SLEEP_TIME_MS); } } assertTrue(isAnyFound, "No matching events found"); }
Example 9
Source File: TestCPUInformation.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Throwable { 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, "hwThreads").atLeast(1); Events.assertField(event, "cores").atLeast(1); Events.assertField(event, "sockets").atLeast(1); Events.assertField(event, "cpu").containsAny("Intel", "AMD", "Unknown x86", "sparc", "ARM", "PPC", "PowerPC", "AArch64", "s390"); Events.assertField(event, "description").containsAny("Intel", "AMD", "Unknown x86", "SPARC", "ARM", "PPC", "PowerPC", "AArch64", "zArch"); } }
Example 10
Source File: TestDumpReadOnly.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Throwable { Path readOnlyDir = FileHelper.createReadOnlyDir(Paths.get(".", "readonlydir")); if (!FileHelper.isReadOnlyPath(readOnlyDir)) { System.out.println("Failed to create read-only path. Maybe running a root? Test skipped"); return; } Recording r = new Recording(); r.enable(OS_INFORMATION); r.start(); r.stop(); Path path = Paths.get(readOnlyDir.toString(), "my.jfr"); verifyException(()->{r.dump(path);}, "No Exception when dumping read-only dir"); r.close(); }
Example 11
Source File: TestJcmdDump.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { // Create a stopped recording in the repository to complicate things Recording r = new Recording(); r.start(); StoppedEvent de = new StoppedEvent(); de.commit(); r.stop(); // The implementation of JFR.dump touch code that can't be executed using the // Java API. It is therefore important to try all combinations. The // implementation is non-trivial and depends on the combination for (String name : names) { for (boolean disk : booleanValues) { try (Recording r1 = new Recording(); Recording r2 = new Recording()) { System.out.println(); System.out.println(); System.out.println("Starting recordings with disk=" + disk); r1.setToDisk(disk); // To complicate things, only enable OldObjectSample for one recording r1.enable(EventNames.OldObjectSample).withoutStackTrace(); r1.setName("r1"); r2.setToDisk(disk); r2.setName("r2"); r1.start(); r2.start(); // Expect no path to GC roots jfrDump(Boolean.FALSE, name, disk, rootCount -> rootCount == 0); // Expect path to GC roots jfrDump(null, name, disk, rootCount -> rootCount == 0); // Expect at least one path to a GC root jfrDump(Boolean.TRUE, name, disk, rootCount -> rootCount > 0); } } } r.close(); // release recording data from the stopped recording }
Example 12
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 13
Source File: GCYoungGenerationConfigurationEventTester.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
public void run() throws Exception { Recording recording = new Recording(); recording.enable(EventNames.YoungGenerationConfiguration); recording.start(); recording.stop(); List<RecordedEvent> events = Events.fromRecording(recording); assertGreaterThanOrEqual(events.size(), 1, "Expected at least 1 event"); EventVerifier v = createVerifier(events.get(0)); v.verify(); }
Example 14
Source File: TestClassLoadEvent.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Throwable { Recording recording = new Recording(); recording.enable(EVENT_NAME).withThreshold(Duration.ofMillis(0)); TestClassLoader cl = new TestClassLoader(); recording.start(); cl.loadClass(TEST_CLASS_NAME); recording.stop(); List<RecordedEvent> events = Events.fromRecording(recording); boolean isLoaded = false; for (RecordedEvent event : events) { RecordedClass loadedClass = event.getValue("loadedClass"); if (SEARCH_CLASS_NAME.equals(loadedClass.getName())) { System.out.println(event); //neither package nor module events are available at 8 //Events.assertClassPackage(loadedClass, SEARCH_PACKAGE_NAME); //Events.assertClassModule(loadedClass, SEARCH_MODULE_NAME); RecordedClassLoader initiatingClassLoader = event.getValue("initiatingClassLoader"); Asserts.assertEquals(cl.getClass().getName(), initiatingClassLoader.getType().getName(), "Expected type " + cl.getClass().getName() + ", got type " + initiatingClassLoader.getType().getName()); RecordedClassLoader definingClassLoader = loadedClass.getClassLoader(); Asserts.assertEquals(BOOT_CLASS_LOADER_NAME, definingClassLoader.getName(), "Expected boot loader to be the defining class loader"); Asserts.assertNull(definingClassLoader.getType(), "boot loader should not have a type"); isLoaded = true; } } Asserts.assertTrue(isLoaded, "No class load event found for class " + SEARCH_CLASS_NAME); }
Example 15
Source File: TestGCConfigurationEventWithDefaultPauseTarget.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { Recording recording = new Recording(); recording.enable(EventNames.GCConfiguration); recording.start(); recording.stop(); List<RecordedEvent> events = Events.fromRecording(recording); assertGreaterThanOrEqual(events.size(), 1, "Expected at least 1 event"); DefaultGCConfigurationVerifier verifier = new DefaultGCConfigurationVerifier(events.get(0)); verifier.verify(); }
Example 16
Source File: TestAllocOutsideTLAB.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { Recording recording = new Recording(); recording.enable(EVENT_NAME).withThreshold(Duration.ofMillis(0)); recording.start(); for (int i = 0; i < OBJECTS_TO_ALLOCATE; ++i) { tmp = new byte[OBJECT_SIZE - BYTE_ARRAY_OVERHEAD]; } recording.stop(); int countEvents = 0; for (RecordedEvent event : Events.fromRecording(recording)) { if (!EVENT_NAME.equals(event.getEventType().getName())) { continue; } System.out.println("Event:" + event); long allocationSize = Events.assertField(event, "allocationSize").atLeast(1L).getValue(); String className = Events.assertField(event, "objectClass.name").notEmpty().getValue(); boolean isMyEvent = Thread.currentThread().getId() == event.getThread().getJavaThreadId() && className.equals(BYTE_ARRAY_CLASS_NAME) && (allocationSize == OBJECT_SIZE || allocationSize == OBJECT_SIZE_ALT); if (isMyEvent) { ++countEvents; } } int minCount = (int) floor(OBJECTS_TO_ALLOCATE * 0.80); assertGreaterThanOrEqual(countEvents, minCount, "Too few tlab objects allocated"); assertLessThanOrEqual(countEvents, OBJECTS_TO_ALLOCATE, "Too many tlab objects allocated"); }
Example 17
Source File: TestState.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(); CommonHelper.verifyRecordingState(r, RecordingState.NEW); r.scheduleStart(Duration.ofHours(2)); CommonHelper.verifyRecordingState(r, RecordingState.DELAYED); r.start(); CommonHelper.verifyRecordingState(r, RecordingState.RUNNING); r.stop(); CommonHelper.verifyRecordingState(r, RecordingState.STOPPED); r.close(); CommonHelper.verifyRecordingState(r, RecordingState.CLOSED); }
Example 18
Source File: TestSettingsControl.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(MyCustomSettingEvent.class).with("mySetting", "myvalue"); r.start(); MyCustomSettingEvent e = new MyCustomSettingEvent(); e.commit(); r.stop(); r.close(); assertTrue(MySettingsControl.setWasCalled, "SettingControl.setValue was not called"); }
Example 19
Source File: TestFileStreamEvents.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Throwable { File tmp = File.createTempFile("TestFileStreamEvents", ".tmp", new File(".")); tmp.deleteOnExit(); Recording recording = new Recording(); List<IOEvent> expectedEvents = new ArrayList<>(); try(FileOutputStream fos = new FileOutputStream(tmp); FileInputStream fis = new FileInputStream(tmp);) { recording.enable(IOEvent.EVENT_FILE_READ).withThreshold(Duration.ofMillis(0)); recording.enable(IOEvent.EVENT_FILE_WRITE).withThreshold(Duration.ofMillis(0)); recording.start(); int writeByte = 47; byte[] writeBuf = {11, 12, 13, 14}; // Write fos.write(writeByte); expectedEvents.add(IOEvent.createFileWriteEvent(1, tmp)); fos.write(writeBuf); expectedEvents.add(IOEvent.createFileWriteEvent(writeBuf.length, tmp)); fos.write(writeBuf, 0, 2); expectedEvents.add(IOEvent.createFileWriteEvent(2, tmp)); // Read int readByte = fis.read(); assertEquals(readByte, writeByte, "Wrong byte read"); expectedEvents.add(IOEvent.createFileReadEvent(1, tmp)); byte[] readBuf = new byte[writeBuf.length]; long size = fis.read(readBuf); assertEquals(size, (long)writeBuf.length, "Wrong size when reading byte[]"); expectedEvents.add(IOEvent.createFileReadEvent(size, tmp)); size = fis.read(readBuf, 0, 2); assertEquals(size, 2L, "Wrong size when reading 2 bytes"); expectedEvents.add(IOEvent.createFileReadEvent(size, tmp)); // We are at EOF. Read more and verify we get size -1. size = fis.read(readBuf); assertEquals(size, -1L, "Size should be -1 at EOF"); expectedEvents.add(IOEvent.createFileReadEvent(size, tmp)); recording.stop(); List<RecordedEvent> events = Events.fromRecording(recording); IOHelper.verifyEqualsInOrder(events, expectedEvents); } }
Example 20
Source File: TestLargeJavaEvent512k.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
public static void main(String... args) throws Exception { final String name = "MyLargeJavaEvent512k"; // name of synthetically generated event final String fieldNamePrefix = "myfield"; final int numberOfFields = 64; // 64*8k = 512k event size final Map<String, Object> eventMap = new HashMap<>(); final int numberOfThreads = 10; // 10 threads will run the test final int numberOfEventsPerThread = 50; // each thread will generate 50 events List<ValueDescriptor> fields = new ArrayList<>(); for (int i = 0; i < numberOfFields; ++i) { String fieldName = fieldNamePrefix + i; eventMap.put(fieldName, largeString()); fields.add(new ValueDescriptor(String.class, fieldName)); } EventTypePrototype prototype = new EventTypePrototype(name,Collections.emptyList(), fields); EventFactory ef = EventFactory.create(prototype.getAnnotations(), prototype.getFields()); Recording r = new Recording(); r.enable(prototype.getName()).withThreshold(Duration.ofNanos(0)).withoutStackTrace(); r.start(); Thread.UncaughtExceptionHandler eh = (t, e) -> TestLargeJavaEvent512k.setError(); Stressor.execute(numberOfThreads, eh, () -> { for (int n = 0; n < numberOfEventsPerThread; ++n) { try { Event event = ef.newEvent(); setEventValues(event, ef, prototype, eventMap); event.commit(); Thread.sleep(1); } catch (Exception ex) { throw new RuntimeException(ex); } } }); r.stop(); try { if (hasError()) { throw new RuntimeException("One (or several) of the threads had an exception/error, test failed"); } verifyEvents(r, numberOfThreads, numberOfEventsPerThread, eventMap); } finally { r.close(); } }