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

The following examples show how to use jdk.jfr.EventType#getFields() . 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: TestEventMetadata.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 {
    Set<String> types = new HashSet<>();
    List<EventType> eventTypes = FlightRecorder.getFlightRecorder().getEventTypes();
    Set<String> eventNames= new HashSet<>();
    for (EventType eventType : eventTypes) {
        verifyEventType(eventType);
        verifyValueDesscriptors(eventType.getFields(), types);
        System.out.println();
        String eventName = eventType.getName();
        if (eventNames.contains(eventName)) {
            throw new Exception("Event with name " +eventName+ " already exists");
        }
        eventNames.add(eventName);
        Set<String> fieldNames = new HashSet<>();
        for (ValueDescriptor v : eventType.getFields()) {
            String fieldName = v.getName();
            if (fieldNames.contains(fieldName)) {
                throw new Exception("Field with name " + fieldName +" is already in use in event name " +eventName);
            }
            fieldNames.add(fieldName);
        }
    }
}
 
Example 2
Source File: TestEventMetadata.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 {
    Set<String> types = new HashSet<>();
    List<EventType> eventTypes = FlightRecorder.getFlightRecorder().getEventTypes();
    Set<String> eventNames= new HashSet<>();
    for (EventType eventType : eventTypes) {
        verifyEventType(eventType);
        verifyValueDesscriptors(eventType.getFields(), types);
        System.out.println();
        String eventName = eventType.getName();
        if (eventNames.contains(eventName)) {
            throw new Exception("Event with name " +eventName+ " already exists");
        }
        eventNames.add(eventName);
        Set<String> fieldNames = new HashSet<>();
        for (ValueDescriptor v : eventType.getFields()) {
            String fieldName = v.getName();
            if (fieldNames.contains(fieldName)) {
                throw new Exception("Field with name " + fieldName +" is already in use in event name " +eventName);
            }
            fieldNames.add(fieldName);
        }
    }
}
 
Example 3
Source File: TestEventMetadata.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 {
    Set<String> types = new HashSet<>();
    List<EventType> eventTypes = FlightRecorder.getFlightRecorder().getEventTypes();
    Set<String> eventNames= new HashSet<>();
    for (EventType eventType : eventTypes) {
        verifyEventType(eventType);
        verifyValueDesscriptors(eventType.getFields(), types);
        System.out.println();
        String eventName = eventType.getName();
        if (eventNames.contains(eventName)) {
            throw new Exception("Event with name " +eventName+ " already exists");
        }
        eventNames.add(eventName);
        Set<String> fieldNames = new HashSet<>();
        for (ValueDescriptor v : eventType.getFields()) {
            String fieldName = v.getName();
            if (fieldNames.contains(fieldName)) {
                throw new Exception("Field with name " + fieldName +" is already in use in event name " +eventName);
            }
            fieldNames.add(fieldName);
        }
    }
}
 
Example 4
Source File: EventParser.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
EventParser(TimeConverter timeConverter, EventType type, Parser[] parsers) {
    this.timeConverter = timeConverter;
    this.parsers = parsers;
    this.eventType = type;
    this.hasDuration = type.getField(FIELD_DURATION) != null;
    this.valueDescriptors = type.getFields();
}
 
Example 5
Source File: ParserFactory.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private EventParser createEventParser(EventType eventType) throws IOException {
    List<Parser> parsers = new ArrayList<Parser>();
    for (ValueDescriptor f : eventType.getFields()) {
        parsers.add(createParser(f));
    }
    return new EventParser(timeConverter, eventType, parsers.toArray(new Parser[0]));
}
 
Example 6
Source File: EventHandlerCreator.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static List<FieldInfo> createFieldInfos(Class<? extends Event> eventClass, EventType type) throws Error {
    List<FieldInfo> fieldInfos = new ArrayList<>();
    for (ValueDescriptor v : type.getFields()) {
        // Only value descriptors that are not fields on the event class.
        if (v != TypeLibrary.STACK_TRACE_FIELD && v != TypeLibrary.THREAD_FIELD) {
            String fieldName = PrivateAccess.getInstance().getFieldName(v);
            String fieldDescriptor = ASMToolkit.getDescriptor(v.getTypeName());
            Class<?> c = eventClass;
            String internalName = null;
            while (c != Event.class) {
                try {
                    Field field = c.getDeclaredField(fieldName);
                    if (c == eventClass || !Modifier.isPrivate(field.getModifiers())) {
                        internalName = ASMToolkit.getInternalName(c.getName());
                        break;
                    }
                } catch (NoSuchFieldException | SecurityException e) {
                    // ignore
                }
                c = c.getSuperclass();
            }
            if (internalName != null) {
                fieldInfos.add(new FieldInfo(fieldName, fieldDescriptor, internalName));
            } else {
                throw new InternalError("Could not locate field " + fieldName + " for event type" + type.getName());
            }
        }
    }
    return fieldInfos;
}
 
Example 7
Source File: EventParser.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
EventParser(TimeConverter timeConverter, EventType type, Parser[] parsers) {
    this.timeConverter = timeConverter;
    this.parsers = parsers;
    this.eventType = type;
    this.hasDuration = type.getField(FIELD_DURATION) != null;
    this.valueDescriptors = type.getFields();
}
 
Example 8
Source File: ParserFactory.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private EventParser createEventParser(EventType eventType) throws IOException {
    List<Parser> parsers = new ArrayList<Parser>();
    for (ValueDescriptor f : eventType.getFields()) {
        parsers.add(createParser(f));
    }
    return new EventParser(timeConverter, eventType, parsers.toArray(new Parser[0]));
}
 
Example 9
Source File: EventHandlerCreator.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static List<FieldInfo> createFieldInfos(Class<? extends Event> eventClass, EventType type) throws Error {
    List<FieldInfo> fieldInfos = new ArrayList<>();
    for (ValueDescriptor v : type.getFields()) {
        // Only value descriptors that are not fields on the event class.
        if (v != TypeLibrary.STACK_TRACE_FIELD && v != TypeLibrary.THREAD_FIELD) {
            String fieldName = PrivateAccess.getInstance().getFieldName(v);
            String fieldDescriptor = ASMToolkit.getDescriptor(v.getTypeName());
            Class<?> c = eventClass;
            String internalName = null;
            while (c != Event.class) {
                try {
                    Field field = c.getDeclaredField(fieldName);
                    if (c == eventClass || !Modifier.isPrivate(field.getModifiers())) {
                        internalName = ASMToolkit.getInternalName(c.getName());
                        break;
                    }
                } catch (NoSuchFieldException | SecurityException e) {
                    // ignore
                }
                c = c.getSuperclass();
            }
            if (internalName != null) {
                fieldInfos.add(new FieldInfo(fieldName, fieldDescriptor, internalName));
            } else {
                throw new InternalError("Could not locate field " + fieldName + " for event type" + type.getName());
            }
        }
    }
    return fieldInfos;
}
 
Example 10
Source File: EventParser.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
EventParser(TimeConverter timeConverter, EventType type, Parser[] parsers) {
    this.timeConverter = timeConverter;
    this.parsers = parsers;
    this.eventType = type;
    this.hasDuration = type.getField(FIELD_DURATION) != null;
    this.valueDescriptors = type.getFields();
}
 
Example 11
Source File: ParserFactory.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private EventParser createEventParser(EventType eventType) throws IOException {
    List<Parser> parsers = new ArrayList<Parser>();
    for (ValueDescriptor f : eventType.getFields()) {
        parsers.add(createParser(f));
    }
    return new EventParser(timeConverter, eventType, parsers.toArray(new Parser[0]));
}
 
Example 12
Source File: EventHandlerCreator.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static List<FieldInfo> createFieldInfos(Class<? extends Event> eventClass, EventType type) throws Error {
    List<FieldInfo> fieldInfos = new ArrayList<>();
    for (ValueDescriptor v : type.getFields()) {
        // Only value descriptors that are not fields on the event class.
        if (v != TypeLibrary.STACK_TRACE_FIELD && v != TypeLibrary.THREAD_FIELD) {
            String fieldName = PrivateAccess.getInstance().getFieldName(v);
            String fieldDescriptor = ASMToolkit.getDescriptor(v.getTypeName());
            Class<?> c = eventClass;
            String internalName = null;
            while (c != Event.class) {
                try {
                    Field field = c.getDeclaredField(fieldName);
                    if (c == eventClass || !Modifier.isPrivate(field.getModifiers())) {
                        internalName = ASMToolkit.getInternalName(c.getName());
                        break;
                    }
                } catch (NoSuchFieldException | SecurityException e) {
                    // ignore
                }
                c = c.getSuperclass();
            }
            if (internalName != null) {
                fieldInfos.add(new FieldInfo(fieldName, fieldDescriptor, internalName));
            } else {
                throw new InternalError("Could not locate field " + fieldName + " for event type" + type.getName());
            }
        }
    }
    return fieldInfos;
}