Package com.tagtraum.perf.gcviewer.util

Examples of com.tagtraum.perf.gcviewer.util.ParseInformation


     */
    @Test
    public void setMemorySimplePreUsed_heap_postUsed_heap() throws ParseException {
        String line = "   [Eden: 1000K(2000K)->0B(3000K) Survivors: 1024B->4000K Heap: 5000K(16M)->6000K(16M)]";
       
        ParseInformation pos = new ParseInformation(0);
        pos.setIndex(line.indexOf("Heap:") + "Heap:".length() + 1);
       
        GCEvent event = new GCEvent();
        dataReader.setMemoryExtended(event, line, pos);
       
        assertEquals("heap before", 5000, event.getPreUsed());
View Full Code Here


     */
    @Test
    public void setMemorySimplePreUsed_postUsed_heap() throws ParseException {
        String line = "   [ 8192K->8128K(64M)]";
       
        ParseInformation pos = new ParseInformation(0);
        pos.setIndex(line.indexOf("[") + 1);
       
        GCEvent event = new GCEvent();
        dataReader.setMemoryExtended(event, line, pos);
       
        assertEquals("heap before", 8192, event.getPreUsed());
View Full Code Here

     */
    @Test
    public void setMemorySimplePreHeap_postHeap() throws ParseException {
        String line = "   [Eden: 1000K(2000K)->0B(3000K) Survivors: 1024B->4000K Heap: 5000K(16M)->6000K(16M)]";
       
        ParseInformation pos = new ParseInformation(0);
        pos.setIndex(line.indexOf("Survivors:") + "Survivors:".length() + 1);
       
        GCEvent event = new GCEvent();
        dataReader.setMemoryExtended(event, line, pos);
       
        assertEquals("heap before", 1, event.getPreUsed());
View Full Code Here

     */
    @Test
    public void setExtendedMemoryFloatingPointPreEden_postEden() throws ParseException {
        String line = "   [Eden: 118.5M(118.0M)->128.4K(112.0M) Survivors: 10.0M->16.0M Heap: 548.6M(640.0M)->440.6M(640.0M)]";
       
        ParseInformation pos = new ParseInformation(0);
        pos.setIndex(line.indexOf("Eden:") + "Eden:".length() + 1);
       
        GCEvent event = new GCEvent();
        dataReader.setMemoryExtended(event, line, pos);
       
        assertEquals("heap before", 121344, event.getPreUsed());
View Full Code Here

     * @param line line to be parsed (from the beginning)
     * @throws ParseException is thrown to report any problems the parser runs into
     * @see #setMemoryAndPauses(GCEvent, String, ParseInformation)
     */
    protected void setMemoryAndPauses(GCEvent event, String line) throws ParseException {
        setMemoryAndPauses(event, line, new ParseInformation(0));
    }
View Full Code Here

        try (BufferedReader in = this.in) {
            GCModel model = new GCModel();
            // TODO what is this for?
            model.setFormat(GCModel.Format.SUN_X_LOG_GC);
            String line;
            ParseInformation parsePosition = new ParseInformation(0);
            Matcher gcPauseMatcher = PATTERN_GC_PAUSE.matcher("");
            Matcher linesMixedMatcher = PATTERN_LINES_MIXED.matcher("");
            Matcher ergonomicsMatcher = PATTERN_G1_ERGONOMICS.matcher("");
            GCEvent gcEvent = null;
            int lineNumber = 0;
            String beginningOfLine = null;

            while ((line = in.readLine()) != null) {
                ++lineNumber;
                parsePosition.setLineNumber(lineNumber);
                parsePosition.setIndex(0);
                if ("".equals(line)) {
                    continue;
                }
                try {
                    // filter out lines that don't need to be parsed
                    if (startsWith(line, EXCLUDE_STRINGS, false)) {
                        continue;
                    }
                    else if (line.indexOf(APPLICATION_TIME) > 0) {
                        continue;
                    }
                    else if (startsWith(line, LOG_INFORMATION_STRINGS, false)) {
                        LOG.info(line);
                        continue;
                    }
                   
                    // remove G1 ergonomics pieces
                    if (line.indexOf(G1_ERGONOMICS) >= 0) {
                        ergonomicsMatcher.reset(line);
                        if (ergonomicsMatcher.matches()) {
                            String firstMatch = (ergonomicsMatcher.group(1));
                            if (firstMatch.length() > 0 && line.indexOf(SOFT_REFERENCE) < 0) {
                                beginningOfLine = firstMatch;
                            }
                            continue;
                        }
                    }

                    // if a new timestamp occurs in the middle of a line, that should be treated as a new line
                    // -> the rest of the old line appears on the next line
                    linesMixedMatcher.reset(line);
                    if (linesMixedMatcher.matches()) {
                        if (line.indexOf("concurrent") > 0) {
                            // 1st pattern (complete concurrent collection follows)
                          beginningOfLine = linesMixedMatcher.group(1);
                          model.add(parseLine(linesMixedMatcher.group(2), parsePosition));
                          parsePosition.setIndex(0);
                          continue; // rest of collection is on the next line, so continue there
                        }
                        else if (line.indexOf(SOFT_REFERENCE) > 0 && line.indexOf(Type.FULL_GC.getName()) > 0) {
                            // for Full GCs, SoftReference entries are treated as unknown detail events
                            // -> parseLine can do this
                        }
                        else if (line.endsWith("secs]")) {
                            // all other patterns: some timestamps follow that are part of a concurrent collection
                            // but the rest of the line is the rest of the same collection
                            StringBuilder realLine = new StringBuilder();
                            realLine.append(linesMixedMatcher.group(1));
                            int toSpaceIndex = line.indexOf(TO_SPACE_OVERFLOW);
                            int initialMarkIndex = line.indexOf(INITIAL_MARK);
                            if (toSpaceIndex > 0 && realLine.length() < toSpaceIndex) {
                                realLine.append(" ").append(TO_SPACE_OVERFLOW);
                            }
                            if (initialMarkIndex > 0 && realLine.length() < initialMarkIndex) {
                                realLine.append(" ").append(INITIAL_MARK);
                            }
                            realLine.append(line.substring(line.lastIndexOf(",")));
                            line = realLine.toString();
                        }
                        else {
                            throw new ParseException("unexpected mixed line", line, parsePosition);
                        }
                    }
                    else if (beginningOfLine != null) {
                        // filter output of -XX:+PrintReferencePolicy away
                        if (line.indexOf(SOFT_REFERENCE) >= 0) {
                            line = line.substring(line.lastIndexOf(","));
                        }
                       
                        // not detailed log but mixed line
                        line = beginningOfLine + line;
                        beginningOfLine = null;
                    }
                   
                    if (line.endsWith(MARK_STACK_IS_FULL)) {
                        // "Mark stack is full" message is treated as part of the event name
                        beginningOfLine = line;
                        continue;
                    }
                    else if (isPrintTenuringDistribution(line)) {
                        beginningOfLine = line;
                        continue;
                    }
                   
                    // the following case is special for -XX:+PrintGCDetails and must be treated
                    // different from the other cases occurring in G1 standard mode
                    // 0.356: [GC pause (young), 0.00219944 secs] -> GC_PAUSE pattern but GC_MEMORY_PAUSE
                    //   event (has extensive details)
                    // all other GC types are the same as in standard G1 mode.
                    gcPauseMatcher.reset(line);
                    if (gcPauseMatcher.matches()) {
                        ExtendedType type = extractTypeFromParsedString(gcPauseMatcher.group(GC_PAUSE_GROUP_TYPE));

                        if (type != null && type.getPattern().compareTo(GcPattern.GC_MEMORY_PAUSE) == 0) {
                            // detailed G1 events start with GC_MEMORY pattern, but are of type GC_MEMORY_PAUSE

                            gcEvent = new G1GcEvent();
                            Date datestamp = parseDatestamp(gcPauseMatcher.group(GC_PAUSE_GROUP_DATESTAMP), parsePosition);
                            gcEvent.setDateStamp(datestamp);
                            double timestamp = 0;
                            if (gcPauseMatcher.group(GC_PAUSE_GROUP_TIMESTAMP) == null) {
                                timestamp = getTimestamp(line, parsePosition, datestamp);
                            }
                            else {
                                timestamp = NumberParser.parseDouble(gcPauseMatcher.group(GC_PAUSE_GROUP_TIMESTAMP));
                            }
                            gcEvent.setTimestamp(timestamp);
                            gcEvent.setExtendedType(type);
                            gcEvent.setPause(NumberParser.parseDouble(gcPauseMatcher.group(GC_PAUSE_GROUP_PAUSE)));
                           
                            // now parse the details of this event
                            lineNumber = parseDetails(in, model, parsePosition, lineNumber, gcEvent, beginningOfLine);
                            beginningOfLine = null;
                            continue;
                        }
                        else {
                            // real GC_PAUSE events like some concurrent events
                            model.add(parseLine(line, parsePosition));
                        }
                    }
                    else if (line.indexOf(Type.FULL_GC.getName()) > 0) {
                        // since jdk 1.8 full gc events in G1 have detailed heap sizing information on the next line
                        GCEvent fullGcEvent = (GCEvent) parseLine(line, parsePosition);
                        if (!in.markSupported()) {
                            LOG.warning("input stream does not support marking!");
                        }
                        else {
                            in.mark(200);
                            try {
                                line = in.readLine();
                                if (line != null && line.trim().startsWith("[Eden")) {
                                    parseMemoryDetails(fullGcEvent, line, parsePosition);
                                }
                                else {
                                    // push last read line back into stream - it is the next event to be parsed
                                    in.reset();
                                }
                            }
                            catch (IOException e) {
                                throw new ParseException("problem resetting stream (" + e.toString() + ")", line, parsePosition);
                            }
                        }
                        model.add(fullGcEvent);
                    }
                    else if (line.indexOf(HEAP_SIZING_START) >= 0) {
                        // the next few lines will be the sizing of the heap
                        lineNumber = skipLinesRespectingConcurrentEvents(in, model, parsePosition, lineNumber, HEAP_STRINGS);
                        continue;
                    }
                    else if (hasIncompleteConcurrentEvent(line, parsePosition)) {
                        parseIncompleteConcurrentEvent(model, model.getLastEventAdded(), line, parsePosition);
                    }
                    else {
                        model.add(parseLine(line, parsePosition));
                    }
                }
                catch (Exception pe) {
                    if (LOG.isLoggable(Level.WARNING)) LOG.log(Level.WARNING, pe.toString());
                    if (LOG.isLoggable(Level.FINE)) LOG.log(Level.FINE, pe.toString(), pe);
                }
                parsePosition.setIndex(0);
            }
            return model;
        }
        finally {
            if (LOG.isLoggable(Level.INFO)) {
View Full Code Here

            Deque<String> beginningOfLine = new LinkedList<String>();
            int lineNumber = 0;
            boolean lastLineWasScavengeBeforeRemark = false;
            boolean lineSkippedForScavengeBeforeRemark = false;
            boolean printTenuringDistributionOn = false;
            ParseInformation parsePosition = new ParseInformation(0);

            while ((line = in.readLine()) != null) {
                ++lineNumber;
                parsePosition.setLineNumber(lineNumber);
                if ("".equals(line)) {
                    continue;
                }
                try {
                    printTenuringDistributionOn = false;
                    // filter out lines that don't need to be parsed
                    if (startsWith(line, EXCLUDE_STRINGS, false)) {
                        continue;
                    }
                    else if (line.indexOf(APPLICATION_TIME) > 0) {
                        // -XX:+PrintGCApplicationConcurrentTime
                        // when it occurs including timestamp (since about jdk1.7.0_50) it should still be ignored
                        continue;
                    }
                    else if (startsWith(line, LOG_INFORMATION_STRINGS, false)) {
                        LOG.info(line);
                        continue;
                    }
                   
                    if (line.indexOf(CMS_ABORT_PRECLEAN) >= 0) {
                        // line contains like " CMS: abort preclean due to time "
                        // -> remove the text
                        int indexOfStart = line.indexOf(CMS_ABORT_PRECLEAN);
                        StringBuilder sb = new StringBuilder(line);
                        sb.replace(indexOfStart, indexOfStart + CMS_ABORT_PRECLEAN.length(), "");
                        line = sb.toString();
                    }
                    if (line.indexOf(PRINT_CMS_STATISTICS_ITERATIONS) > 0) {
                        // -XX:PrintCmsStatistics -> filter text that the parser doesn't know
                        printCmsStatisticsIterationsMatcher.reset(line);
                        if (!printCmsStatisticsIterationsMatcher.matches()) {
                            LOG.severe("printCmsStatisticsIterationsMatcher did not match for line " + lineNumber + ": '" + line + "'");
                            continue;
                        }
                       
                        line = printCmsStatisticsIterationsMatcher.group(PRINT_CMS_STATISTICS_ITERATIONS_GROUP_BEFORE)
                                + printCmsStatisticsIterationsMatcher.group(PRINT_CMS_STATISTICS_ITERATIONS_GROUP_AFTER);
                    }
                    if (line.indexOf(PRINT_CMS_STATISTICS_SURVIVOR) > 0) {
                        String currentBeginning = "";
                        if (beginningOfLine.size() > 0) {
                            // if -XX:PrintCmsStatistics=2 is combined with -XX:+CMSScavengeBeforeRemark
                            // then a remark line is broken into three parts, which have to be glued together
                            currentBeginning = beginningOfLine.removeFirst();
                        }
                        beginningOfLine.addFirst(currentBeginning + line.substring(0, line.indexOf(PRINT_CMS_STATISTICS_SURVIVOR)));
                        continue;
                    }
                    if (line.indexOf(PRINT_TENURING_DISTRIBUTION) > 0) {
                        printTenuringDistributionMatcher.reset(line);
                        if (!printTenuringDistributionMatcher.matches()) {
                            LOG.severe("printDistributionMatcher did not match for line " + lineNumber + ": '" + line + "'");
                            continue;
                        }
                       
                        line = printTenuringDistributionMatcher.group(PRINT_TENURING_DISTRIBUTION_PATTERN_GROUP_BEFORE)
                                    + printTenuringDistributionMatcher.group(PRINT_TENURING_DISTRIBUTION_PATTERN_GROUP_AFTER);
                    }
                    if (line.indexOf(PRINT_REFERENCE_GC_INDICATOR) > 0) {
                        line = filterAwayReferenceGc(line);
                    }
                    if (lineHasPrintFlsStatistics(line)) {
                        handlePrintFlsStatistics(line, beginningOfLine);
                        continue;
                    }

                    if (isCmsScavengeBeforeRemark(line)) {
                        // This is the case, when option -XX:+CMSScavengeBeforeRemark is used.
                        // we have two events in the first line -> split it
                        // if this option is combined with -XX:+PrintTenuringDistribution, the
                        // first event is also distributed over more than one line
                        int startOf2ndEvent = line.indexOf("]", line.indexOf(EVENT_YG_OCCUPANCY)) + 1;
                        beginningOfLine.addFirst(line.substring(0, startOf2ndEvent));
                        if (!isPrintTenuringDistribution(line)) {
                            if (line.indexOf(SCAVENGE_BEFORE_REMARK) >= 0) {
                                // jdk1.5 scavenge before remark: just after another separate event occurs
                                startOf2ndEvent = line.indexOf(SCAVENGE_BEFORE_REMARK) + SCAVENGE_BEFORE_REMARK.length();
                            }
                            model.add(parseLine(line.substring(startOf2ndEvent), parsePosition));
                            parsePosition.setIndex(0);
                        }
                        else {
                            beginningOfLine.addFirst(line.substring(startOf2ndEvent));
                        }
                       
                        lastLineWasScavengeBeforeRemark = true;
                        continue;
                    }
                    int unloadingClassIndex = line.indexOf(UNLOADING_CLASS);
                    if (unloadingClassIndex > 0) {
                        beginningOfLine.addFirst(line.substring(0, unloadingClassIndex));
                        continue;
                    }
                    else if (isPrintTenuringDistribution(line)) {
                        // this is the case, when e.g. -XX:+PrintTenuringDistribution is used
                        // where we want to skip "Desired survivor..." and "- age..." lines
                        beginningOfLine.addFirst(line);
                        continue;
                    }
                    else if (line.indexOf(ADAPTIVE_PATTERN) >= 0) {
                        if (line.indexOf("Times") > 0) {
                            // -XX:+PrintAdaptiveSizePolicy -XX:-UseAdaptiveSizePolicy
                            printAdaptiveSizePolicyMatcher.reset(line);
                            if (!printAdaptiveSizePolicyMatcher.matches()) {
                                LOG.severe("printAdaptiveSizePolicyMatcher did not match for line " + lineNumber + ": '" + line + "'");
                                continue;
                            }
                           
                            model.add(parseLine(
                                    printAdaptiveSizePolicyMatcher.group(PRINT_ADAPTIVE_SIZE_GROUP_BEFORE)
                                        + printAdaptiveSizePolicyMatcher.group(PRINT_ADAPTIVE_SIZE_GROUP_AFTER),
                                    parsePosition));
                            parsePosition.setIndex(0);
                        }
                        else {
                            // -XX:+PrintAdaptiveSizePolicy
                            adaptiveSizePolicyMatcher.reset(line);
                            if (!adaptiveSizePolicyMatcher.matches()) {
                                LOG.severe("adaptiveSizePolicyMatcher did not match for line " + lineNumber + ": '" + line + "'");
                                continue;
                            }
                            beginningOfLine.addFirst(adaptiveSizePolicyMatcher.group(1));
                            lineNumber = skipLines(in, parsePosition, lineNumber, ADAPTIVE_SIZE_POLICY_STRINGS);
                        }
                        continue;
                    }
                    else if (beginningOfLine.size() > 0) {
                        // -XX:+CMSScavengeBeforeRemark combined with -XX:+PrintTenuringDistribution
                        // is the only case where beginningOfLine.size() > 1
                        printTenuringDistributionOn = beginningOfLine.size() == 2;
                        if (gcLogType == GcLogType.SUN1_5
                                && lastLineWasScavengeBeforeRemark
                                && ! lineSkippedForScavengeBeforeRemark) {
                           
                            // -XX:+CMSScavengeBeforeRemark inserts a pause on its own line between
                            // the first and the second part of the enclosing remark event. Probably
                            // that is the duration of the Scavenge-Before-Remark event; this information
                            // will be dropped to reduce complexity of the parser at the cost of
                            // some accuracy in that case.
                            lineSkippedForScavengeBeforeRemark = true;
                            continue;
                        }
                        else {
                            line = beginningOfLine.removeFirst() + line;
                        }
                    }
                    else if (line.indexOf(HEAP_SIZING_START) >= 0) {
                        // the next few lines will be the sizing of the heap
                        lineNumber = skipLines(in, parsePosition, lineNumber, HEAP_STRINGS);
                        continue;
                    }

                    if (isMixedLine(line, mixedLineMatcher)) {
                        // if PrintTenuringDistribution is used and a line is mixed,
                        // beginningOfLine may already contain a value, which must be preserved
                        String firstPartOfBeginningOfLine = beginningOfLine.pollFirst();
                        if (firstPartOfBeginningOfLine == null) {
                            firstPartOfBeginningOfLine = "";
                        }
                        beginningOfLine.addFirst(firstPartOfBeginningOfLine + mixedLineMatcher.group(LINES_MIXED_STARTOFLINE_GROUP));
                       
                        model.add(parseLine(mixedLineMatcher.group(LINES_MIXED_ENDOFLINE_GROUP), parsePosition));
                        parsePosition.setIndex(0);
                        continue;
                    }
                   
                    AbstractGCEvent<?> gcEvent = parseLine(line, parsePosition);
                    
                    if (lastLineWasScavengeBeforeRemark && !printTenuringDistributionOn) {
                         // according to http://mail.openjdk.java.net/pipermail/hotspot-gc-use/2012-August/001297.html
                         // the pause time reported for cms-remark includes the scavenge-before-remark time
                         // so it has to be corrected to show only the time spent in remark event
                         lastLineWasScavengeBeforeRemark = false;
                         lineSkippedForScavengeBeforeRemark = false;
                         AbstractGCEvent<?> scavengeBeforeRemarkEvent = model.get(model.size() - 1);
                         AbstractGCEvent<?> remarkEvent = gcEvent;
                         remarkEvent.setPause(remarkEvent.getPause() - scavengeBeforeRemarkEvent.getPause());
                     }
                    
                     model.add(gcEvent);
                }
                catch (Exception pe) {
                    if (LOG.isLoggable(Level.WARNING)) LOG.warning(pe.toString());
                    if (LOG.isLoggable(Level.FINE)) LOG.log(Level.FINE, pe.getMessage(), pe);
                    beginningOfLine.clear();
                }
                // reset ParsePosition
                parsePosition.setIndex(0);
            }
            return model;
        }
        finally {
            if (LOG.isLoggable(Level.INFO)) LOG.info("Done reading.");
View Full Code Here

TOP

Related Classes of com.tagtraum.perf.gcviewer.util.ParseInformation

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.