jdk.jfr.Category Java Examples

The following examples show how to use jdk.jfr.Category. 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: TestDynamicAnnotations.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void testEventFactoryExample() throws IOException {
     List<ValueDescriptor> fields = new ArrayList<>();
     List<AnnotationElement> messageAnnotations = Collections.singletonList(new AnnotationElement(Label.class, "Message"));
     fields.add(new ValueDescriptor(String.class, "message", messageAnnotations));
     List<AnnotationElement> numberAnnotations = Collections.singletonList(new AnnotationElement(Label.class, "Number"));
     fields.add(new ValueDescriptor(int.class, "number", numberAnnotations));

     String[] category = { "Example", "Getting Started" };
     List<AnnotationElement> eventAnnotations = new ArrayList<>();
     eventAnnotations.add(new AnnotationElement(Name.class, "com.example.HelloWorld"));
     eventAnnotations.add(new AnnotationElement(Label.class, "Hello World"));
     eventAnnotations.add(new AnnotationElement(Description.class, "Helps programmer getting started"));
     eventAnnotations.add(new AnnotationElement(Category.class, category));

     EventFactory f = EventFactory.create(eventAnnotations, fields);

     Event event = f.newEvent();
     event.set(0, "hello, world!");
     event.set(1, 4711);
     event.commit();
}
 
Example #2
Source File: TestDynamicAnnotations.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void testEventFactoryExample() throws IOException {
     List<ValueDescriptor> fields = new ArrayList<>();
     List<AnnotationElement> messageAnnotations = Collections.singletonList(new AnnotationElement(Label.class, "Message"));
     fields.add(new ValueDescriptor(String.class, "message", messageAnnotations));
     List<AnnotationElement> numberAnnotations = Collections.singletonList(new AnnotationElement(Label.class, "Number"));
     fields.add(new ValueDescriptor(int.class, "number", numberAnnotations));

     String[] category = { "Example", "Getting Started" };
     List<AnnotationElement> eventAnnotations = new ArrayList<>();
     eventAnnotations.add(new AnnotationElement(Name.class, "com.example.HelloWorld"));
     eventAnnotations.add(new AnnotationElement(Label.class, "Hello World"));
     eventAnnotations.add(new AnnotationElement(Description.class, "Helps programmer getting started"));
     eventAnnotations.add(new AnnotationElement(Category.class, category));

     EventFactory f = EventFactory.create(eventAnnotations, fields);

     Event event = f.newEvent();
     event.set(0, "hello, world!");
     event.set(1, 4711);
     event.commit();
}
 
Example #3
Source File: TestDynamicAnnotations.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void testEventFactoryExample() throws IOException {
     List<ValueDescriptor> fields = new ArrayList<>();
     List<AnnotationElement> messageAnnotations = Collections.singletonList(new AnnotationElement(Label.class, "Message"));
     fields.add(new ValueDescriptor(String.class, "message", messageAnnotations));
     List<AnnotationElement> numberAnnotations = Collections.singletonList(new AnnotationElement(Label.class, "Number"));
     fields.add(new ValueDescriptor(int.class, "number", numberAnnotations));

     String[] category = { "Example", "Getting Started" };
     List<AnnotationElement> eventAnnotations = new ArrayList<>();
     eventAnnotations.add(new AnnotationElement(Name.class, "com.example.HelloWorld"));
     eventAnnotations.add(new AnnotationElement(Label.class, "Hello World"));
     eventAnnotations.add(new AnnotationElement(Description.class, "Helps programmer getting started"));
     eventAnnotations.add(new AnnotationElement(Category.class, category));

     EventFactory f = EventFactory.create(eventAnnotations, fields);

     Event event = f.newEvent();
     event.set(0, "hello, world!");
     event.set(1, 4711);
     event.commit();
}
 
Example #4
Source File: TraceHandler.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private Type createType(Attributes attributes, boolean eventType, long typeId, boolean contantPool) {
    String labelAttribute = ATTRIBUTE_LABEL;
    String id = attributes.getValue(ATTRIBUTE_ID);
    String path = attributes.getValue(ATTRIBUTE_PATH);
    String builtInType = attributes.getValue(ATTRIBUTE_BUILTIN_TYPE);
    String jvmType = attributes.getValue(ATTRIBUTE_JVM_TYPE);

    String typeName = makeTypeName(id, path);
    Type t;
    if (eventType) {
        t = new PlatformEventType(typeName, typeId, false, true);
    } else {
        t = new Type(typeName, null, typeId, contantPool);
    }
    typedef.put(id, typeName);
    if (contantPool) {
        labelAttribute = ATTRIBUTE_HR_NAME; // not "label" for some reason?
        if (builtInType != null) {
            typedef.put(builtInType, typeName);
        }
        if (jvmType != null) {
            typedef.put(jvmType, typeName);
        }
    }
    ArrayList<AnnotationElement> aes = new ArrayList<>();
    if (path != null) {
        aes.add(new AnnotationElement(Category.class, makeCategory(path)));
    }
    String label = attributes.getValue(labelAttribute);
    if (label != null) {
        aes.add(new AnnotationElement(Label.class, label));
    }
    String description = attributes.getValue(ATTRIBUTE_DESCRIPTION);
    if (description != null) {
        aes.add(new AnnotationElement(Description.class, description));
    }
    aes.trimToSize();
    t.setAnnotations(aes);
    return t;
}
 
Example #5
Source File: TestGetAnnotation.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 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 #6
Source File: TestGetAnnotation.java    From TencentKona-8 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 #7
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 #8
Source File: TestCategory.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 t = EventType.getEventType(CategoryEvent.class);
    String[] categoryNames = t.getAnnotation(Category.class).value();
    Asserts.assertTrue(Arrays.equals(categoryNames, new String[] { "Hello", "World" }), "Incorrect value for @Category");
}
 
Example #9
Source File: TestCategory.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 t = EventType.getEventType(CategoryEvent.class);
    String[] categoryNames = t.getAnnotation(Category.class).value();
    Asserts.assertTrue(Arrays.equals(categoryNames, new String[] { "Hello", "World" }), "Incorrect value for @Category");
}
 
Example #10
Source File: TestCategory.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 t = EventType.getEventType(CategoryEvent.class);
    String[] categoryNames = t.getAnnotation(Category.class).value();
    Asserts.assertTrue(Arrays.equals(categoryNames, new String[] { "Hello", "World" }), "Incorrect value for @Category");
}