Java Code Examples for jdk.jfr.Recording#disable()
The following examples show how to use
jdk.jfr.Recording#disable() .
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: TestLoadEventAfterStart.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Throwable { Recording r = new Recording(); r.start(); ClassLoader classLoader = TestLoadEventAfterStart.class.getClassLoader(); Class<? extends Event> eventClass = classLoader.loadClass("jdk.testlibrary.jfr.SimpleEvent").asSubclass(Event.class); r.enable(eventClass).withThreshold(Duration.ofMillis(0)).withoutStackTrace(); createEvent(eventClass, 1); r.disable(eventClass); createEvent(eventClass, 2); r.enable(eventClass).withThreshold(Duration.ofMillis(0)).withoutStackTrace(); createEvent(eventClass, 3); r.stop(); verifyEvents(r, 1, 3); }
Example 2
Source File: TestRecordingEnableDisable.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
private static void updateSettings(Recording r) { int operationIndex = rand.nextInt(4); switch (operationIndex) { case 0: SimpleEventHelper.enable(r, true); break; case 1: SimpleEventHelper.enable(r, false); break; case 2: r.enable(EVENT_PATH).withoutStackTrace(); break; case 3: r.disable(EVENT_PATH); break; default: Asserts.fail("Wrong operataionIndex. Test error"); } }
Example 3
Source File: TestRecordingEnableDisable.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
private static void updateSettings(Recording r) { int operationIndex = rand.nextInt(4); switch (operationIndex) { case 0: SimpleEventHelper.enable(r, true); break; case 1: SimpleEventHelper.enable(r, false); break; case 2: r.enable(EVENT_PATH).withoutStackTrace(); break; case 3: r.disable(EVENT_PATH); break; default: Asserts.fail("Wrong operataionIndex. Test error"); } }
Example 4
Source File: TestStaticEnable.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public static void enable(Recording r, boolean isEnabled) { if (isEnabled) { r.enable(MyEvent.class).withThreshold(Duration.ofMillis(0)).withoutStackTrace(); } else { r.disable(MyEvent.class); } }
Example 5
Source File: TestEnableDisable.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { List<MyEvent> expectedEvents = new ArrayList<>(); Recording r = new Recording(); r.start(); createEvent(expectedEvents, true); // id=0 Custom event classes are enabled by default. r.disable(MyEvent.class); createEvent(expectedEvents, false); // id=1 r.enable(MyEvent.class); createEvent(expectedEvents, true); // id=2 // enable/disable by event setting name String eventSettingName = String.valueOf(EventType.getEventType(MyEvent.class).getId()); System.out.println("eventSettingName=" + eventSettingName); r.disable(eventSettingName); createEvent(expectedEvents, false); // id=3 r.enable(eventSettingName); createEvent(expectedEvents, true); r.stop(); createEvent(expectedEvents, false); Iterator<MyEvent> expectedIterator = expectedEvents.iterator(); for (RecordedEvent event : Events.fromRecording(r)) { System.out.println("event.id=" + Events.assertField(event, "id").getValue()); Asserts.assertTrue(expectedIterator.hasNext(), "Found more events than expected"); Events.assertField(event, "id").equal(expectedIterator.next().id); } Asserts.assertFalse(expectedIterator.hasNext(), "Did not find all expected events."); r.close(); }
Example 6
Source File: TestStaticEnable.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public static void enable(Recording r, boolean isEnabled) { if (isEnabled) { r.enable(MyEvent.class).withThreshold(Duration.ofMillis(0)).withoutStackTrace(); } else { r.disable(MyEvent.class); } }
Example 7
Source File: SimpleEventHelper.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public static void enable(Recording r, boolean isEnabled) { if (isEnabled) { r.enable(SimpleEvent.class).withThreshold(Duration.ofMillis(0)).withoutStackTrace(); } else { r.disable(SimpleEvent.class); } }
Example 8
Source File: TestReEnableMultiple.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private static void updateSettings(Recording r) { boolean doEnable = rand.nextInt(3) == 0; // Disable 2 of 3, since event // is enabled by union of // recordings. boolean doMyEvent = rand.nextInt(2) == 0; if (doMyEvent) { SimpleEventHelper.enable(r, doEnable); } else { if (doEnable) { r.enable(EVENT_PATH).withoutStackTrace(); } else { r.disable(EVENT_PATH); } } }
Example 9
Source File: SimpleEventHelper.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
public static void enable(Recording r, boolean isEnabled) { if (isEnabled) { r.enable(SimpleEvent.class).withThreshold(Duration.ofMillis(0)).withoutStackTrace(); } else { r.disable(SimpleEvent.class); } }
Example 10
Source File: TestIsEnabled.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { assertDisabled("Event enabled with no recording"); Recording r = new Recording(); assertDisabled("Event enabled at new Recording()"); r.enable(SimpleEvent.class); assertDisabled("Event enabled before r.start()"); r.start(); // enable/disable by class assertEnabled("Event not enabled after r.start()"); r.disable(SimpleEvent.class); assertDisabled("Event enabled after r.disable()"); r.enable(SimpleEvent.class); assertEnabled("Event disabled afer r.enable()"); // enable/disable by event setting name String eventSettingName = String.valueOf(EventType.getEventType(SimpleEvent.class).getId()); System.out.println("eventSettingName=" + eventSettingName); r.disable(eventSettingName); assertDisabled("Event enabled after r.disable(name)"); r.enable(eventSettingName); assertEnabled("Event disabled after r.enable(name)"); r.stop(); assertDisabled("Event enabled after r.stop()"); r.close(); assertDisabled("Event enabled after r.close()"); }
Example 11
Source File: SimpleEventHelper.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public static void enable(Recording r, boolean isEnabled) { if (isEnabled) { r.enable(SimpleEvent.class).withThreshold(Duration.ofMillis(0)).withoutStackTrace(); } else { r.disable(SimpleEvent.class); } }
Example 12
Source File: TestStaticEnable.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
public static void enable(Recording r, boolean isEnabled) { if (isEnabled) { r.enable(MyEvent.class).withThreshold(Duration.ofMillis(0)).withoutStackTrace(); } else { r.disable(MyEvent.class); } }
Example 13
Source File: TestReEnableMultiple.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
private static void updateSettings(Recording r) { boolean doEnable = rand.nextInt(3) == 0; // Disable 2 of 3, since event // is enabled by union of // recordings. boolean doMyEvent = rand.nextInt(2) == 0; if (doMyEvent) { SimpleEventHelper.enable(r, doEnable); } else { if (doEnable) { r.enable(EVENT_PATH).withoutStackTrace(); } else { r.disable(EVENT_PATH); } } }
Example 14
Source File: TestReEnableMultiple.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private static void updateSettings(Recording r) { boolean doEnable = rand.nextInt(3) == 0; // Disable 2 of 3, since event // is enabled by union of // recordings. boolean doMyEvent = rand.nextInt(2) == 0; if (doMyEvent) { SimpleEventHelper.enable(r, doEnable); } else { if (doEnable) { r.enable(EVENT_PATH).withoutStackTrace(); } else { r.disable(EVENT_PATH); } } }
Example 15
Source File: TestGetSettings.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Throwable { final long minThresholdNanos = 1000000; final String dummyEventPath = "mydummy/event/path"; final String myEventSettingName = String.valueOf(EventType.getEventType(MyEvent.class).getId()); System.out.println("myEventSettingName=" + myEventSettingName); // Settings should be merged to include the most number of events (minimum threshold). Recording r1 = new Recording(); r1.enable(MyEvent.class).withThreshold(Duration.ofNanos(minThresholdNanos * 3)); r1.enable(MyEvent.class).withThreshold(Duration.ofNanos(minThresholdNanos * 2)); r1.enable(dummyEventPath).withThreshold(Duration.ofNanos(minThresholdNanos)); r1.start(); ExpectedSetting[] expectedR1 = { new ExpectedSetting(myEventSettingName, "enabled", "true"), new ExpectedSetting(myEventSettingName, "threshold", Long.toString(minThresholdNanos * 2) + " ns"), new ExpectedSetting(dummyEventPath, "enabled", "true"), new ExpectedSetting(dummyEventPath, "threshold", Long.toString(minThresholdNanos) + " ns"), }; verifySettings(r1.getSettings(), expectedR1); // Start another recording. Recorder settings should be merged from both recordings. Recording r2 = new Recording(); r2.enable(MyEvent.class).withThreshold(Duration.ofNanos(minThresholdNanos)); r2.disable(dummyEventPath); r2.start(); ExpectedSetting[] expectedR2 = { new ExpectedSetting(myEventSettingName, "enabled", "true"), new ExpectedSetting(myEventSettingName, "threshold", Long.toString(minThresholdNanos) + " ns"), new ExpectedSetting(dummyEventPath, "enabled", "false") }; verifySettings(r1.getSettings(), expectedR1); verifySettings(r2.getSettings(), expectedR2); // Stop first recording. Recorder should use settings from r2. r1.stop(); verifySettings(r2.getSettings(), expectedR2); r2.stop(); r1.close(); r2.close(); }
Example 16
Source File: TestIsEnabledMultiple.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
private static void assertEnabled(RecState recStateA, RecState recStateB, EnableState enableStateA, EnableState enableStateB) { Recording a = new Recording(); Recording b = new Recording(); assertEnablement(false); // no recording running if (enableStateA == EnableState.Disabled) { a.disable(MyEvent.class); } if (enableStateA == EnableState.Enabled) { a.enable(MyEvent.class); } if (enableStateB == EnableState.Disabled) { b.disable(MyEvent.class); } if (enableStateB == EnableState.Enabled) { b.enable(MyEvent.class); } if ( enableStateA == EnableState.Disabled && recStateA == RecState.Running) { if ( enableStateB == EnableState.Disabled && recStateB == RecState.Running) { System.out.println(); } } if (recStateA == RecState.Running) { a.start(); } if (recStateB == RecState.Running) { b.start(); } System.out.println("Recording a is " + a.getState() + ". Event is " + enableStateA); System.out.println("Recording b is " + b.getState() + ". Event is " + enableStateB); // an event is enabled if at least one recording is running // and the event is on by default or has been enabled. boolean aEnabled = recStateA == RecState.Running && enableStateA == EnableState.Enabled; boolean bEnabled = recStateB == RecState.Running && enableStateB == EnableState.Enabled; boolean enabled = aEnabled || bEnabled; System.out.println("Expected enablement: " + enabled); System.out.println(); assertEnablement(enabled); if (recStateA == RecState.Running) { a.stop(); } if (recStateB == RecState.Running) { b.stop(); } assertEnablement(false); // no recording running a.close(); b.close(); }
Example 17
Source File: TestReEnableName.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
private static void testRecordingWithEnabledEvent(String eventname, boolean enabled) throws Exception { System.out.println("Testing enabled=" + enabled + " for " + eventname); final Path pathDisabled = Paths.get(".", "disabled.txt").toAbsolutePath(); final Path pathEnabled = Paths.get(".", "enabled.txt").toAbsolutePath(); Recording r = new Recording(); if (enabled) { r.enable(eventname).withoutThreshold().withoutStackTrace(); } else { r.disable(eventname).withoutThreshold().withoutStackTrace(); } r.start(); // We should only get events for pathEnabled, not for pathDisabled. int countExpectedEvents = 0; for (int i = 0; i < 10; ++i) { if (enabled) { Files.write(pathEnabled, "E".getBytes()); ++countExpectedEvents; r.disable(eventname); } else { Files.write(pathDisabled, "D".getBytes()); r.enable(eventname); } enabled = !enabled; } r.stop(); int countFoundEvents = 0; for (RecordedEvent event : Events.fromRecording(r)) { System.out.printf("Event %s%n", event); Asserts.assertEquals(eventname, event.getEventType().getName(), "Wrong event type"); String path = Events.assertField(event, "path").getValue(); System.out.println(path); if (pathEnabled.toString().equals(path)) { ++countFoundEvents; } } Asserts.assertGreaterThanOrEqual(countFoundEvents, countExpectedEvents, "Too few events found"); r.close(); }
Example 18
Source File: TestIsEnabledMultiple.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
private static void assertEnabled(RecState recStateA, RecState recStateB, EnableState enableStateA, EnableState enableStateB) { Recording a = new Recording(); Recording b = new Recording(); assertEnablement(false); // no recording running if (enableStateA == EnableState.Disabled) { a.disable(MyEvent.class); } if (enableStateA == EnableState.Enabled) { a.enable(MyEvent.class); } if (enableStateB == EnableState.Disabled) { b.disable(MyEvent.class); } if (enableStateB == EnableState.Enabled) { b.enable(MyEvent.class); } if ( enableStateA == EnableState.Disabled && recStateA == RecState.Running) { if ( enableStateB == EnableState.Disabled && recStateB == RecState.Running) { System.out.println(); } } if (recStateA == RecState.Running) { a.start(); } if (recStateB == RecState.Running) { b.start(); } System.out.println("Recording a is " + a.getState() + ". Event is " + enableStateA); System.out.println("Recording b is " + b.getState() + ". Event is " + enableStateB); // an event is enabled if at least one recording is running // and the event is on by default or has been enabled. boolean aEnabled = recStateA == RecState.Running && enableStateA == EnableState.Enabled; boolean bEnabled = recStateB == RecState.Running && enableStateB == EnableState.Enabled; boolean enabled = aEnabled || bEnabled; System.out.println("Expected enablement: " + enabled); System.out.println(); assertEnablement(enabled); if (recStateA == RecState.Running) { a.stop(); } if (recStateB == RecState.Running) { b.stop(); } assertEnablement(false); // no recording running a.close(); b.close(); }
Example 19
Source File: TestReEnableName.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
private static void testRecordingWithEnabledEvent(String eventname, boolean enabled) throws Exception { System.out.println("Testing enabled=" + enabled + " for " + eventname); final Path pathDisabled = Paths.get(".", "disabled.txt").toAbsolutePath(); final Path pathEnabled = Paths.get(".", "enabled.txt").toAbsolutePath(); Recording r = new Recording(); if (enabled) { r.enable(eventname).withoutThreshold().withoutStackTrace(); } else { r.disable(eventname).withoutThreshold().withoutStackTrace(); } r.start(); // We should only get events for pathEnabled, not for pathDisabled. int countExpectedEvents = 0; for (int i = 0; i < 10; ++i) { if (enabled) { Files.write(pathEnabled, "E".getBytes()); ++countExpectedEvents; r.disable(eventname); } else { Files.write(pathDisabled, "D".getBytes()); r.enable(eventname); } enabled = !enabled; } r.stop(); int countFoundEvents = 0; for (RecordedEvent event : Events.fromRecording(r)) { System.out.printf("Event %s%n", event); Asserts.assertEquals(eventname, event.getEventType().getName(), "Wrong event type"); String path = Events.assertField(event, "path").getValue(); System.out.println(path); if (pathEnabled.toString().equals(path)) { ++countFoundEvents; } } Asserts.assertGreaterThanOrEqual(countFoundEvents, countExpectedEvents, "Too few events found"); r.close(); }
Example 20
Source File: TestShouldCommit.java From dragonwell8_jdk with GNU General Public License v2.0 | 2 votes |
public static void main(String[] args) throws Exception { Recording rA = new Recording(); verifyShouldCommitFalse(); // No active recordings rA.start(); rA.enable(MyEvent.class).withoutThreshold(); // recA=all verifyShouldCommitTrue(); setThreshold(rA, 100); // recA=100 verifyThreshold(100); setThreshold(rA, 200); // recA=200 verifyThreshold(200); Recording rB = new Recording(); verifyThreshold(200); // recA=200, recB=not started rB.start(); verifyThreshold(200); // recA=200, recB=not specified, settings from recA is used. setThreshold(rB, 100); // recA=200, recB=100 verifyThreshold(100); setThreshold(rB, 300); // recA=200, recB=300 verifyThreshold(200); rA.disable(MyEvent.class); // recA=disabled, recB=300 verifyThreshold(300); rB.disable(MyEvent.class); // recA=disabled, recB=disabled verifyShouldCommitFalse(); setThreshold(rA, 200); // recA=200, recB=disabled verifyThreshold(200); rB.enable(MyEvent.class).withoutThreshold(); // recA=200, recB=all verifyShouldCommitTrue(); setThreshold(rB, 100); // recA=200, recB=100 verifyThreshold(100); rB.stop(); // recA=200, recB=stopped verifyThreshold(200); rA.stop(); // recA=stopped, recB=stopped verifyShouldCommitFalse(); rA.close(); rB.close(); verifyShouldCommitFalse(); }