Java Code Examples for jdk.jfr.EventType#getEventType()

The following examples show how to use jdk.jfr.EventType#getEventType() . 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: TestRegistered.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    try {
        EventType.getEventType(NotRegisteredByDefaultEvent.class);
        throw new Exception("Should not be able to get event type from unregistered event type");
    } catch (IllegalStateException ise) {
        // as expected
    }
    EventType registered = EventType.getEventType(RegisteredByDefaultEvent.class);
    boolean registeredWorking = false;
    for (EventType type : FlightRecorder.getFlightRecorder().getEventTypes()) {
        if (registered.getId() == type.getId()) {
            registeredWorking = true;
        }
    }
    if (!registeredWorking) {
        Asserts.fail("Default regsitration is not working, can't validate @NoAutoRegistration");
    }
}
 
Example 2
Source File: TestGetLabel.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    EventType type = EventType.getEventType(CustomEvent.class);

    SettingDescriptor plain = Events.getSetting(type, "plain");
    Asserts.assertNull(plain.getLabel());

    SettingDescriptor annotatedType = Events.getSetting(type, "annotatedType");
    Asserts.assertEquals(AnnotatedSetting.LABEL, annotatedType.getLabel());

    SettingDescriptor newName = Events.getSetting(type, "newName");
    Asserts.assertEquals(newName.getLabel(), "Annotated Method");

    SettingDescriptor overridden = Events.getSetting(type, "overridden");
    Asserts.assertNull(overridden.getLabel());

    SettingDescriptor protectedBase = Events.getSetting(type, "protectedBase");
    Asserts.assertEquals(protectedBase.getLabel(), "Protected Base");

    SettingDescriptor publicBase = Events.getSetting(type, "publicBase");
    Asserts.assertEquals(publicBase.getLabel(), AnnotatedSetting.LABEL);

    SettingDescriptor packageProtectedBase = Events.getSetting(type, "packageProtectedBase");
    Asserts.assertNull(packageProtectedBase.getLabel());

    CustomEvent.assertOnDisk((x, y) -> Objects.equals(x.getLabel(), y.getLabel()) ? 0 : 1);
}
 
Example 3
Source File: TestGetName.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    EventType type = EventType.getEventType(CustomEvent.class);

    // subclass
    Events.getSetting(type, "plain");
    Events.getSetting(type, "annotatedType");
    Events.getSetting(type, "newName");
    Events.getSetting(type, "overridden");
    // base class
    Events.getSetting(type, "overridden");
    Events.getSetting(type, "protectedBase");
    Events.getSetting(type, "publicBase");
    Events.getSetting(type, "packageProtectedBase");

    int defaultNumberOfSettings = 3; // Enabled , Stack Trace, Threshold
    if (type.getSettingDescriptors().size() != 8 + defaultNumberOfSettings) {
        for (SettingDescriptor s : type.getSettingDescriptors()) {
            System.out.println(s.getName());
        }
        throw new Exception("Wrong number of settings");
    }

    CustomEvent.assertOnDisk((x, y) -> x.getName().compareTo(y.getName()));
}
 
Example 4
Source File: TestDescription.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {

        EventType t = EventType.getEventType(DescriptionEvent.class);

        // field description
        AnnotationElement aMax = Events.getAnnotation(t.getField("field"), Description.class);
        String d = (String) aMax.getValue("value");
        Asserts.assertEquals("Field Annotation", d, "Incorrect annotation for field, got '" + d + "'");

        // event description
        d = t.getAnnotation(Description.class).value();
        Asserts.assertEquals("Event Annotation", d, "Incorrect annotation for event, got '" + d + "'");

        // annotation description
        AnnotationElement a = Events.getAnnotationByName(t, AnnotationWithDescription.class.getName());
        Description de = a.getAnnotation(Description.class);
        Asserts.assertEquals("Meta Annotation", de.value(), "Incorrect annotation for event, got '" + de.value() + "'");

        for (SettingDescriptor v: t.getSettingDescriptors()) {
            if (v.getName().equals("dummy")) {
                Description settingDescription = v.getAnnotation(Description.class);
                Asserts.assertEquals(settingDescription.value(), "Setting description", "Incorrect description for setting");
            }
        }
    }
 
Example 5
Source File: TestExperimental.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    EventType t = EventType.getEventType(ExperimentalEvent.class);

    // @Experimental on event
    Experimental e = t.getAnnotation(Experimental.class);
    Asserts.assertTrue(e != null, "Expected @Experimental annotation on event");

    // @Experimental on annotation
    AnnotationElement a = Events.getAnnotationByName(t, ExperimentalAnnotation.class.getName());
    e = a.getAnnotation(Experimental.class);
    Asserts.assertTrue(e != null, "Expected @Experimental on annotation");

    // @Experimental on field
    a = Events.getAnnotation(t.getField("experimentalField"), Experimental.class);
    Asserts.assertTrue(e != null, "Expected @Experimental on field");
}
 
Example 6
Source File: TestGetAnnotation.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    EventType type = EventType.getEventType(CustomEvent.class);

    SettingDescriptor annotatedType = Events.getSetting(type, "annotatedType");
    Label al = annotatedType.getAnnotation(Label.class);
    Asserts.assertNull(al); // we should not inherit annotation from type

    Description ad = annotatedType.getAnnotation(Description.class);
    Asserts.assertNull(ad); // we should not inherit annotation from type

    Timestamp at = annotatedType.getAnnotation(Timestamp.class);
    Asserts.assertNull(at); // we should not inherit annotation from type

    SettingDescriptor newName = Events.getSetting(type, "newName");
    Label nl = newName.getAnnotation(Label.class);
    Asserts.assertEquals(nl.value(), "Annotated Method");

    Description nd = newName.getAnnotation(Description.class);
    Asserts.assertEquals(nd.value(), "Description of an annotated method");

    Timespan nt = newName.getAnnotation(Timespan.class);
    Asserts.assertEquals(nt.value(), Timespan.NANOSECONDS);
}
 
Example 7
Source File: TestRetransform.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    EventType type = EventType.getEventType(TestEvent.class);
    if (type.isEnabled()) {
        Asserts.fail("Expected event to be disabled before recording start");
    }
    Recording r = new Recording();
    r.start();
    if (!type.isEnabled()) {
        Asserts.fail("Expected event to be enabled during recording");
    }
    TestEvent testEvent = new TestEvent();
    testEvent.commit();
    loadEventClassDuringRecording();
    r.stop();
    if (type.isEnabled()) {
        Asserts.fail("Expected event to be disabled after recording stopped");
    }
    Events.hasEvent(r, SimpleEvent.class.getName());
    Events.hasEvent(r, TestEvent.class.getName());
}
 
Example 8
Source File: PlatformRecorder.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public PlatformRecorder() throws Exception {
    repository = Repository.getRepository();
    Logger.log(JFR_SYSTEM, INFO, "Initialized disk repository");
    repository.ensureRepository();
    jvm.createNativeJFR();
    Logger.log(JFR_SYSTEM, INFO, "Created native");
    JDKEvents.initialize();
    Logger.log(JFR_SYSTEM, INFO, "Registered JDK events");
    JDKEvents.addInstrumentation();
    startDiskMonitor();
    SecuritySupport.registerEvent(ActiveRecordingEvent.class);
    activeRecordingEvent = EventType.getEventType(ActiveRecordingEvent.class);
    SecuritySupport.registerEvent(ActiveSettingEvent.class);
    activeSettingEvent = EventType.getEventType(ActiveSettingEvent.class);
    shutdownHook = SecuritySupport.createThreadWitNoPermissions("JFR: Shutdown Hook", new ShutdownHook(this));
    SecuritySupport.setUncaughtExceptionHandler(shutdownHook, new ShutdownHook.ExceptionHandler());
    SecuritySupport.registerShutdownHook(shutdownHook);
    timer = createTimer();
}
 
Example 9
Source File: TestValueDescriptorContentType.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Throwable {
    EventType type = EventType.getEventType(AlohaEvent.class);

    // check field annotation on event value
    ValueDescriptor filter = type.getField("greeting");
    Asserts.assertEquals(filter.getContentType(), Hawaiian.class.getName());

    // check field annotation with missing content type
    ValueDescriptor missing = type.getField("missing");
    Asserts.assertEquals(missing.getContentType(), null);

    // check field annotation with annotation but not content type
    ValueDescriptor otherAnnotation = type.getField("otherAnnotation");
    Asserts.assertEquals(otherAnnotation.getContentType(), null);
}
 
Example 10
Source File: TestFieldAnnotations.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    EventType t = EventType.getEventType(FieldAnnotationEvent.class);

    ValueDescriptor field = t.getField("memoryAmount");
    Events.hasAnnotation(field, DataAmount.class);

    field = t.getField("frequency");
    Events.hasAnnotation(field, Frequency.class);

    field = t.getField("memoryAddress");
    Events.hasAnnotation(field, MemoryAddress.class);

    field = t.getField("percentage");
    Events.hasAnnotation(field, Percentage.class);

    field = t.getField("fromThread");
    Events.hasAnnotation(field, TransitionFrom.class);

    field = t.getField("toThread");
    Events.hasAnnotation(field, TransitionTo.class);

    field = t.getField("unsigned");
    Events.hasAnnotation(field, Unsigned.class);

    field = t.getField("timespan");
    Events.assertAnnotation(field, Timespan.class, Timespan.MILLISECONDS);

    field = t.getField("timestamp");
    Events.assertAnnotation(field, Timestamp.class, Timestamp.MILLISECONDS_SINCE_EPOCH);
}
 
Example 11
Source File: TestRelational.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    EventType t = EventType.getEventType(UserEvent.class);
    ValueDescriptor field = t.getField("id");
    AnnotationElement userId = Events.getAnnotation(field, UserId.class);
    Relational r = userId.getAnnotation(Relational.class);
    Asserts.assertTrue(r != null, "Expected relational annotation to have annotation @Relational");
}
 
Example 12
Source File: TestFieldAnnotations.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    EventType t = EventType.getEventType(FieldAnnotationEvent.class);

    ValueDescriptor field = t.getField("memoryAmount");
    Events.hasAnnotation(field, DataAmount.class);

    field = t.getField("frequency");
    Events.hasAnnotation(field, Frequency.class);

    field = t.getField("memoryAddress");
    Events.hasAnnotation(field, MemoryAddress.class);

    field = t.getField("percentage");
    Events.hasAnnotation(field, Percentage.class);

    field = t.getField("fromThread");
    Events.hasAnnotation(field, TransitionFrom.class);

    field = t.getField("toThread");
    Events.hasAnnotation(field, TransitionTo.class);

    field = t.getField("unsigned");
    Events.hasAnnotation(field, Unsigned.class);

    field = t.getField("timespan");
    Events.assertAnnotation(field, Timespan.class, Timespan.MILLISECONDS);

    field = t.getField("timestamp");
    Events.assertAnnotation(field, Timestamp.class, Timestamp.MILLISECONDS_SINCE_EPOCH);
}
 
Example 13
Source File: TestGetDefaultValues.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void testCustomEvent() {
    EventType customizedEventType = EventType.getEventType(EventWithCustomSettings.class);
    Asserts.assertEquals(customizedEventType.getSettingDescriptors().size(), 5, "Wrong number of default values");
    assertDefaultValue(customizedEventType, "setting1", "none");
    assertDefaultValue(customizedEventType, "setting2", "none");
    assertDefaultValue(customizedEventType, "threshold", "100 ms");
    assertDefaultValue(customizedEventType, "stackTrace", "true");
    assertDefaultValue(customizedEventType, "enabled", "false");
}
 
Example 14
Source File: TestStackTrace.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    EventType onEvent = EventType.getEventType(StackTraceOnEvent.class);
    EventType offEvent = EventType.getEventType(StackTraceOffEvent.class);

    String defaultValue = Events.getSetting(onEvent, StackTrace.NAME).getDefaultValue();
    Asserts.assertEquals(defaultValue, "true", "@StackTrace(true) should reault in 'true'");

    defaultValue = Events.getSetting(offEvent, StackTrace.NAME).getDefaultValue();
    Asserts.assertEquals(defaultValue, "false", "@StackTrace(false) should reault in 'false'");
}
 
Example 15
Source File: TestContentType.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        EventType t = EventType.getEventType(SunnyDay.class);
        AnnotationElement aMax = Events.getAnnotation(t.getField("max"), Temperature.class);
        ContentType cMax = aMax.getAnnotation(ContentType.class);
        if (cMax == null) {
            throw new Exception("Expected Temperature annotation for field 'max' to have meta annotation ContentType");
        }
        AnnotationElement aHours = Events.getAnnotation(t.getField("hours"), Timespan.class);
        ContentType cHours = aHours.getAnnotation(ContentType.class);
        Asserts.assertTrue(cHours != null, "Expected Timespan annotation for field 'hours' to have meta annotation ContentType");
    }
 
Example 16
Source File: TestGetSettings.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Throwable {
    EventType eventType = EventType.getEventType(EventWithCustomSettings.class);
    List<SettingDescriptor> settings = eventType.getSettingDescriptors();
    Asserts.assertEquals(settings.size(), 5, "Wrong number of settings");

    // test immutability
    try {
        settings.add(settings.get(0));
        Asserts.fail("Should not be able to modify list returned by getSettings()");
    } catch (UnsupportedOperationException uoe) {
        // OK, as expected
    }
}
 
Example 17
Source File: TestGetAnnotation.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Throwable {
    EventType type = EventType.getEventType(MyEvent.class);

    Label label = type.getAnnotation(Label.class);
    if (label == null) {
        Asserts.fail("Annotation label was null");
    }
    Asserts.assertEquals(label.value(), "myLabel", "Wrong value for annotation label");

    Category category = type.getAnnotation(Category.class);
    if (category == null) {
        Asserts.fail("Annotation @Description was null");
    }

    Asserts.assertTrue(Arrays.equals(category.value(), new String[] {"Stuff"}), "Wrong value for annotation enabled");

    Description description = type.getAnnotation(Description.class);
    if (description != null) {
        Asserts.fail("Annotation description should be null");
    }

    try {
        type.getAnnotation(null);
        Asserts.fail("No exception when getAnnotation(null)");
    } catch(Exception e) {
        // Expected exception
    }
}
 
Example 18
Source File: TestThreshold.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    EventType thresholdEvent = EventType.getEventType(PeriodicEvent.class);
    String defaultValue = Events.getSetting(thresholdEvent,Threshold.NAME).getDefaultValue();
    Asserts.assertEquals(defaultValue, "23 s", "@Threshold(\"23 s\") Should result in threshold '23 s'");
}
 
Example 19
Source File: TestPeriod.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    EventType periodicEvent = EventType.getEventType(PeriodicEvent.class);
    String defaultValue = Events.getSetting(periodicEvent, Period.NAME).getDefaultValue();
    Asserts.assertEQ(defaultValue, "47 s", "Incorrect default value for period");
}
 
Example 20
Source File: TestEnabled.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    EventType trueEvent = EventType.getEventType(EnabledTrueEvent.class);
    EventType falseEvent = EventType.getEventType(EnabledFalseEvent.class);

    Recording r = new Recording();

    Asserts.assertFalse(trueEvent.isEnabled(), "@Enabled(true) event should be diabled before recording start");
    Asserts.assertFalse(falseEvent.isEnabled(), "@Enabled(false) event should be diabled before recording start");

    r.start();

    Asserts.assertTrue(trueEvent.isEnabled(), "@Enabled(true) event should to be enabled during recording");
    Asserts.assertFalse(falseEvent.isEnabled(), "@Enabled(true) event should to be disabled during recording");

    r.stop();

    Asserts.assertFalse(trueEvent.isEnabled(), "@Enabled(true) event should be diabled after recording stop");
    Asserts.assertFalse(falseEvent.isEnabled(), "@Enabled(false) event should to be diabled after recording stop");

    r.close();
}