828 // FIXME: Should we always include event type? Does it make any sense, except on the custom pages? 829 830 // FIXME: Transform both START_TIME and END_TIME to LIFETIME? 831 // FIXME: Add derived attributes, like a conversion of any THREAD or CLASS attribute? Thread group? 832 /* 833 * Make sure to do the conversions in the right order, so for example a stack trace can be 834 * converted to a top method, which then is converted to a method string. 835 */ 836 return attributes.map(a -> a.equals(JfrAttributes.EVENT_THREAD) ? JdkAttributes.EVENT_THREAD_NAME : a) 837 .flatMap(a -> a.equals(JfrAttributes.EVENT_STACKTRACE) ? Stream.of(JdkAttributes.STACK_TRACE_STRING, 838 JdkAttributes.STACK_TRACE_TOP_METHOD_STRING, JdkAttributes.STACK_TRACE_TOP_CLASS_STRING, 839 JdkAttributes.STACK_TRACE_TOP_PACKAGE, JdkAttributes.STACK_TRACE_BOTTOM_METHOD_STRING) 840 : Stream.of(a)) 841 .map(a -> a.equals(JdkAttributes.COMPILER_METHOD) ? JdkAttributes.COMPILER_METHOD_STRING : a) 842 // FIXME: String or id? 843 .map(a -> a.equals(JdkAttributes.REC_SETTING_FOR) ? JdkAttributes.REC_SETTING_FOR_NAME : a) 844 .map(a -> a.equals(JdkAttributes.CLASS_DEFINING_CLASSLOADER) 845 ? JdkAttributes.CLASS_DEFINING_CLASSLOADER_STRING : a) 846 .map(a -> a.equals(JdkAttributes.CLASS_INITIATING_CLASSLOADER) 847 ? JdkAttributes.CLASS_INITIATING_CLASSLOADER_STRING : a) 848 .filter(a -> a.equals(JfrAttributes.EVENT_TYPE) || (a.getContentType() instanceof RangeContentType) 849 || (a.getContentType().getPersister() != null)) 850 .distinct(); 851 } 852 853 /** 854 * Returns a value for attribute, firstly by trying to find one in the items, secondly by 855 * creating a default value for some known content types. Returns null if the first two cases 856 * fail. 857 * 858 * @param items 859 * @param attribute 860 * @return a value of type V, or null 861 */ 862 @SuppressWarnings("unchecked") 863 private static <V> V findValueForFilter(IItemCollection items, ICanonicalAccessorFactory<V> attribute) { 864 IItem firstItem = ItemCollectionToolkit.stream(items).filter(is -> is.getType().hasAttribute(attribute)) 865 .flatMap(ItemIterableToolkit::stream) 866 .filter(i -> ((IMemberAccessor<V, IItem>) attribute.getAccessor(i.getType())).getMember(i) != null) 867 .findFirst().orElse(null); | 828 // FIXME: Should we always include event type? Does it make any sense, except on the custom pages? 829 830 // FIXME: Transform both START_TIME and END_TIME to LIFETIME? 831 // FIXME: Add derived attributes, like a conversion of any THREAD or CLASS attribute? Thread group? 832 /* 833 * Make sure to do the conversions in the right order, so for example a stack trace can be 834 * converted to a top method, which then is converted to a method string. 835 */ 836 return attributes.map(a -> a.equals(JfrAttributes.EVENT_THREAD) ? JdkAttributes.EVENT_THREAD_NAME : a) 837 .flatMap(a -> a.equals(JfrAttributes.EVENT_STACKTRACE) ? Stream.of(JdkAttributes.STACK_TRACE_STRING, 838 JdkAttributes.STACK_TRACE_TOP_METHOD_STRING, JdkAttributes.STACK_TRACE_TOP_CLASS_STRING, 839 JdkAttributes.STACK_TRACE_TOP_PACKAGE, JdkAttributes.STACK_TRACE_BOTTOM_METHOD_STRING) 840 : Stream.of(a)) 841 .map(a -> a.equals(JdkAttributes.COMPILER_METHOD) ? JdkAttributes.COMPILER_METHOD_STRING : a) 842 // FIXME: String or id? 843 .map(a -> a.equals(JdkAttributes.REC_SETTING_FOR) ? JdkAttributes.REC_SETTING_FOR_NAME : a) 844 .map(a -> a.equals(JdkAttributes.CLASS_DEFINING_CLASSLOADER) 845 ? JdkAttributes.CLASS_DEFINING_CLASSLOADER_STRING : a) 846 .map(a -> a.equals(JdkAttributes.CLASS_INITIATING_CLASSLOADER) 847 ? JdkAttributes.CLASS_INITIATING_CLASSLOADER_STRING : a) 848 .map(a -> a.equals(JdkAttributes.PARENT_CLASSLOADER) 849 ? JdkAttributes.PARENT_CLASSLOADER_STRING : a) 850 .map(a -> a.equals(JdkAttributes.CLASSLOADER) 851 ? JdkAttributes.CLASSLOADER_STRING : a) 852 .filter(a -> a.equals(JfrAttributes.EVENT_TYPE) || (a.getContentType() instanceof RangeContentType) 853 || (a.getContentType().getPersister() != null)) 854 .distinct(); 855 } 856 857 /** 858 * Returns a value for attribute, firstly by trying to find one in the items, secondly by 859 * creating a default value for some known content types. Returns null if the first two cases 860 * fail. 861 * 862 * @param items 863 * @param attribute 864 * @return a value of type V, or null 865 */ 866 @SuppressWarnings("unchecked") 867 private static <V> V findValueForFilter(IItemCollection items, ICanonicalAccessorFactory<V> attribute) { 868 IItem firstItem = ItemCollectionToolkit.stream(items).filter(is -> is.getType().hasAttribute(attribute)) 869 .flatMap(ItemIterableToolkit::stream) 870 .filter(i -> ((IMemberAccessor<V, IItem>) attribute.getAccessor(i.getType())).getMember(i) != null) 871 .findFirst().orElse(null); |