Java Code Examples for jdk.jfr.Configuration#getConfiguration()
The following examples show how to use
jdk.jfr.Configuration#getConfiguration() .
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: TestCreateNative.java From dragonwell8_jdk 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 2
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 3
Source File: TestRecordingInfo.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(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 4
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 5
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 6
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 7
Source File: TestCreateNative.java From TencentKona-8 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 8
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 9
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 10
Source File: EventEmitterAgent.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
private static void agentWork() throws Exception { try (Recording r = new Recording(Configuration.getConfiguration("default"))) { r.enable(EventNames.JavaExceptionThrow); r.setDestination(DUMP_PATH); r.start(); Thread[] threads = new Thread[THREADS]; for (int i = 0; i < THREADS; i++) { threads[i] = new Thread(EventEmitterAgent::emitEvents); threads[i].start(); } for (int i = 0; i < THREADS; i++) { threads[i].join(); } r.stop(); } }
Example 11
Source File: ExecuteHelper.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
public static Path createProfilingRecording() throws Exception { Path file = Files.createTempFile("recording", ".jfr"); // Create a recording with some data try (Recording r = new Recording(Configuration.getConfiguration("profile"))) { r.start(); // Allocation event array = new Object[1000000]; array = null; // Class loading event etc provokeClassLoading(); // GC events System.gc(); // ExecutionSample long t = System.currentTimeMillis(); while (System.currentTimeMillis() - t < 50) { // do nothing } // Other periodic events, i.e CPU load Thread.sleep(1000); r.stop(); r.dump(file); } return file; }
Example 12
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 13
Source File: ExecuteHelper.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public static Path createProfilingRecording() throws Exception { Path file = Utils.createTempFile("profiling-recording", ".jfr"); // Create a recording with some data try (Recording r = new Recording(Configuration.getConfiguration("profile"))) { r.start(); // Allocation event array = new Object[1000000]; array = null; // Class loading event etc provokeClassLoading(); // GC events System.gc(); // ExecutionSample long t = System.currentTimeMillis(); while (System.currentTimeMillis() - t < 50) { // do nothing } // Other periodic events, i.e CPU load Thread.sleep(1000); r.stop(); r.dump(file); } return file; }
Example 14
Source File: ExecuteHelper.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
public static Path createProfilingRecording() throws Exception { Path file = Files.createTempFile("recording", ".jfr"); // Create a recording with some data try (Recording r = new Recording(Configuration.getConfiguration("profile"))) { r.start(); // Allocation event array = new Object[1000000]; array = null; // Class loading event etc provokeClassLoading(); // GC events System.gc(); // ExecutionSample long t = System.currentTimeMillis(); while (System.currentTimeMillis() - t < 50) { // do nothing } // Other periodic events, i.e CPU load Thread.sleep(1000); r.stop(); r.dump(file); } return file; }
Example 15
Source File: TestJcmdDumpGeneratedFilename.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { // Increase the id for a recording for (int i = 0; i < 300; i++) { new Recording(); } try (Recording r = new Recording(Configuration.getConfiguration("default"))) { r.start(); r.stop(); testDumpFilename(); testDumpFilename(r); testDumpDiectory(); testDumpDiectory(r); } }
Example 16
Source File: TestJcmdDumpGeneratedFilename.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { // Increase the id for a recording for (int i = 0; i < 300; i++) { new Recording(); } try (Recording r = new Recording(Configuration.getConfiguration("default"))) { r.start(); r.stop(); testDumpFilename(); testDumpFilename(r); testDumpDiectory(); testDumpDiectory(r); } }
Example 17
Source File: TestDisassemble.java From openjdk-jdk8u 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 18
Source File: ExecuteHelper.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public static Path createProfilingRecording() throws Exception { Path file = Utils.createTempFile("profiling-recording", ".jfr"); // Create a recording with some data try (Recording r = new Recording(Configuration.getConfiguration("profile"))) { r.start(); // Allocation event array = new Object[1000000]; array = null; // Class loading event etc provokeClassLoading(); // GC events System.gc(); // ExecutionSample long t = System.currentTimeMillis(); while (System.currentTimeMillis() - t < 50) { // do nothing } // Other periodic events, i.e CPU load Thread.sleep(1000); r.stop(); r.dump(file); } return file; }
Example 19
Source File: TestUnsupportedVM.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
public static void main(String... args) throws Exception { if (Boolean.getBoolean("prepare-recording")) { Recording r = new Recording(Configuration.getConfiguration("default")); r.start(); r.stop(); r.dump(RECORDING_FILE); r.close(); return; } System.out.println("jdk.jfr.unsupportedvm=" + System.getProperty("jdk.jfr.unsupportedvm")); // Class FlightRecorder if (FlightRecorder.isAvailable()) { throw new AssertionError("JFR should not be available on an unsupported VM"); } if (FlightRecorder.isInitialized()) { throw new AssertionError("JFR should not be initialized on an unsupported VM"); } assertIllegalStateException(() -> FlightRecorder.getFlightRecorder()); assertSwallow(() -> FlightRecorder.addListener(new FlightRecorderListener() {})); assertSwallow(() -> FlightRecorder.removeListener(new FlightRecorderListener() {})); assertSwallow(() -> FlightRecorder.register(MyEvent.class)); assertSwallow(() -> FlightRecorder.unregister(MyEvent.class)); assertSwallow(() -> FlightRecorder.addPeriodicEvent(MyEvent.class, new Runnable() { public void run() {} })); assertSwallow(() -> FlightRecorder.removePeriodicEvent(new Runnable() { public void run() {} })); // Class Configuration if (!Configuration.getConfigurations().isEmpty()) { throw new AssertionError("Configuration files should not exist on an unsupported VM"); } Path jfcFile = Utils.createTempFile("empty", ".jfr"); assertIOException(() -> Configuration.getConfiguration("default")); assertIOException(() -> Configuration.create(jfcFile)); assertIOException(() -> Configuration.create(new FileReader(jfcFile.toFile()))); // Class EventType assertInternalError(() -> EventType.getEventType(MyEvent.class)); // Class EventFactory assertInternalError(() -> EventFactory.create(new ArrayList<>(), new ArrayList<>())); // Create a static event MyEvent myEvent = new MyEvent(); myEvent.begin(); myEvent.end(); myEvent.shouldCommit(); myEvent.commit(); // Trigger class initialization failure for (Class<?> c : APIClasses) { assertNoClassInitFailure(c); } // jdk.jfr.consumer.* // Only run this part of tests if we are on VM // that can produce a recording file if (Files.exists(RECORDING_FILE)) { for(RecordedEvent re : RecordingFile.readAllEvents(RECORDING_FILE)) { System.out.println(re); } } }
Example 20
Source File: TestUnsupportedVM.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
public static void main(String... args) throws Exception { if (Boolean.getBoolean("prepare-recording")) { Recording r = new Recording(Configuration.getConfiguration("default")); r.start(); r.stop(); r.dump(RECORDING_FILE); r.close(); return; } System.out.println("jdk.jfr.unsupportedvm=" + System.getProperty("jdk.jfr.unsupportedvm")); // Class FlightRecorder if (FlightRecorder.isAvailable()) { throw new AssertionError("JFR should not be available on an unsupported VM"); } if (FlightRecorder.isInitialized()) { throw new AssertionError("JFR should not be initialized on an unsupported VM"); } assertIllegalStateException(() -> FlightRecorder.getFlightRecorder()); assertSwallow(() -> FlightRecorder.addListener(new FlightRecorderListener() {})); assertSwallow(() -> FlightRecorder.removeListener(new FlightRecorderListener() {})); assertSwallow(() -> FlightRecorder.register(MyEvent.class)); assertSwallow(() -> FlightRecorder.unregister(MyEvent.class)); assertSwallow(() -> FlightRecorder.addPeriodicEvent(MyEvent.class, new Runnable() { public void run() {} })); assertSwallow(() -> FlightRecorder.removePeriodicEvent(new Runnable() { public void run() {} })); // Class Configuration if (!Configuration.getConfigurations().isEmpty()) { throw new AssertionError("Configuration files should not exist on an unsupported VM"); } Path jfcFile = Files.createTempFile("my", ".jfr"); assertIOException(() -> Configuration.getConfiguration("default")); assertIOException(() -> Configuration.create(jfcFile)); assertIOException(() -> Configuration.create(new FileReader(jfcFile.toFile()))); // Class EventType assertInternalError(() -> EventType.getEventType(MyEvent.class)); // Class EventFactory assertInternalError(() -> EventFactory.create(new ArrayList<>(), new ArrayList<>())); // Create a static event MyEvent myEvent = new MyEvent(); myEvent.begin(); myEvent.end(); myEvent.shouldCommit(); myEvent.commit(); // Trigger class initialization failure for (Class<?> c : APIClasses) { assertNoClassInitFailure(c); } // jdk.jfr.consumer.* // Only run this part of tests if we are on VM // that can produce a recording file if (Files.exists(RECORDING_FILE)) { for(RecordedEvent re : RecordingFile.readAllEvents(RECORDING_FILE)) { System.out.println(re); } } }