Search in sources :

Example 1 with ThreadSnapshotFilter

use of org.gridkit.jvmtool.stacktrace.analytics.ThreadSnapshotFilter in project jvm-tools by aragozin.

the class CategorizerParser method loadCategories.

public static void loadCategories(Reader source, SimpleCategorizer categorizer, boolean shortNames, final BasicFilterFactory factory) throws IOException {
    final Map<String, ThreadSnapshotFilter> filters = new LinkedHashMap<String, ThreadSnapshotFilter>();
    @SuppressWarnings("serial") Properties props = new Properties() {

        @Override
        public synchronized Object put(Object key, Object value) {
            String skey = (String) key;
            String svalue = (String) value;
            if (!skey.endsWith("._")) {
                ThreadSnapshotFilter filter = TraceFilterPredicateParser.parseFilter(svalue, factory);
                filters.put(skey, filter);
            }
            return super.put(key, value);
        }
    };
    props.load(source);
    for (String cat : filters.keySet()) {
        String name = cat;
        if (!shortNames) {
            String desc = props.getProperty(name + "._");
            if (desc != null) {
                name = desc;
            }
        }
        categorizer.addCategory(name, filters.get(cat));
    }
}
Also used : Properties(java.util.Properties) ThreadSnapshotFilter(org.gridkit.jvmtool.stacktrace.analytics.ThreadSnapshotFilter) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with ThreadSnapshotFilter

use of org.gridkit.jvmtool.stacktrace.analytics.ThreadSnapshotFilter in project jvm-tools by aragozin.

the class ThreadDumpSource method getFilteredReader.

public EventReader<ThreadSnapshotEvent> getFilteredReader() {
    if (traceFilter == null && traceTrim == null && threadName == null && timeRange == null) {
        return getUnclassifiedReader();
    } else {
        EventReader<ThreadSnapshotEvent> reader = getUnclassifiedReader();
        if (threadName != null) {
            reader = reader.morph(new ThreadNameFilter(threadName));
        }
        if (timeRange != null) {
            String[] lh = timeRange.split("[-]");
            if (lh.length != 2) {
                host.fail("Invalid time range '" + timeRange + "'", "Valid format yyyy.MM.dd_HH:mm:ss-yyyy.MM.dd_HH:mm:ss hours and higher parts can be ommited");
            }
            TimeRangeChecker checker = new TimeRangeChecker(lh[0], lh[1], timeZone);
            reader = reader.morph(new TimeFilter(checker));
        }
        try {
            CachingFilterFactory factory = new CachingFilterFactory();
            if (traceFilter != null) {
                ThreadSnapshotFilter ts = TraceFilterPredicateParser.parseFilter(traceFilter, factory);
                reader = reader.morph(new ThreadEventFilter(ts));
            }
            if (traceTrim != null) {
                final PositionalStackMatcher mt = TraceFilterPredicateParser.parsePositionMatcher(traceTrim, factory);
                reader = reader.morph(new TrimProxy() {

                    @Override
                    public ThreadSnapshotEvent morph(ThreadSnapshotEvent event) {
                        int n = mt.matchNext(event, 0);
                        if (n >= 0) {
                            trimPoint = n;
                            return super.morph(event);
                        } else {
                            return null;
                        }
                    }
                });
            }
            return reader;
        } catch (ParserException e) {
            throw host.fail("Failed to parse trace filter - " + e.getMessage() + " at " + e.getOffset() + " [" + e.getParseText() + "]");
        }
    }
}
Also used : ParserException(org.gridkit.jvmtool.stacktrace.analytics.ParserException) TimeRangeChecker(org.gridkit.jvmtool.stacktrace.analytics.TimeRangeChecker) ThreadSnapshotFilter(org.gridkit.jvmtool.stacktrace.analytics.ThreadSnapshotFilter) ThreadSnapshotEvent(org.gridkit.jvmtool.codec.stacktrace.ThreadSnapshotEvent) ThreadEventFilter(org.gridkit.jvmtool.stacktrace.analytics.ThreadEventFilter) PositionalStackMatcher(org.gridkit.jvmtool.stacktrace.analytics.PositionalStackMatcher) CachingFilterFactory(org.gridkit.jvmtool.stacktrace.analytics.CachingFilterFactory)

Aggregations

ThreadSnapshotFilter (org.gridkit.jvmtool.stacktrace.analytics.ThreadSnapshotFilter)2 LinkedHashMap (java.util.LinkedHashMap)1 Properties (java.util.Properties)1 ThreadSnapshotEvent (org.gridkit.jvmtool.codec.stacktrace.ThreadSnapshotEvent)1 CachingFilterFactory (org.gridkit.jvmtool.stacktrace.analytics.CachingFilterFactory)1 ParserException (org.gridkit.jvmtool.stacktrace.analytics.ParserException)1 PositionalStackMatcher (org.gridkit.jvmtool.stacktrace.analytics.PositionalStackMatcher)1 ThreadEventFilter (org.gridkit.jvmtool.stacktrace.analytics.ThreadEventFilter)1 TimeRangeChecker (org.gridkit.jvmtool.stacktrace.analytics.TimeRangeChecker)1