hotspot/test/gc/g1/plab/lib/LogParser.java
author mchernov
Thu, 03 Mar 2016 16:12:38 +0300
changeset 37061 f4f1c40edfd9
parent 36390 a2d991d1d628
child 37181 0d5e8ae18924
permissions -rw-r--r--
8150183: gc/g1/plab/TestPLABResize.java - previous PLAB size should be less than current Reviewed-by: jmasa, dfazunen
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
35885
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
     1
/*
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
     4
 *
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
     7
 * published by the Free Software Foundation.
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
     8
 *
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    13
 * accompanied this code).
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    14
 *
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    18
 *
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    21
 * questions.
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    22
 */
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    23
package gc.g1.plab.lib;
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    24
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    25
import java.util.EnumMap;
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    26
import java.util.HashMap;
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    27
import java.util.Map;
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    28
import java.util.Optional;
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    29
import java.util.Scanner;
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    30
import java.util.regex.Matcher;
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    31
import java.util.regex.Pattern;
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    32
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    33
/**
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    34
 * LogParser class parses VM output to get PLAB and ConsumptionStats values.
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    35
 *
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    36
 * Typical GC log with PLAB statistics (options - -Xlog:gc=debug,gc+plab=debug) looks like:
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    37
 *
36390
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35885
diff changeset
    38
 * [0.330s][debug][gc,plab  ] GC(0) Young PLAB allocation: allocated: 1825632B, wasted: 29424B, unused: 2320B, used: 1793888B, undo waste: 0B,
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35885
diff changeset
    39
 * [0.330s][debug][gc,plab  ] GC(0) Young other allocation: region end waste: 0B, regions filled: 2, direct allocated: 271520B, failure used: 0B, failure wasted: 0B
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35885
diff changeset
    40
 * [0.330s][debug][gc,plab  ] GC(0) Young sizing: calculated: 358776B, actual: 358776B
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35885
diff changeset
    41
 * [0.330s][debug][gc,plab  ] GC(0) Old PLAB allocation: allocated: 427248B, wasted: 592B, unused: 368584B, used: 58072B, undo waste: 0B,
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35885
diff changeset
    42
 * [0.330s][debug][gc,plab  ] GC(0) Old other allocation: region end waste: 0B, regions filled: 1, direct allocated: 41704B, failure used: 0B, failure wasted: 0B
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35885
diff changeset
    43
 * [0.330s][debug][gc,plab  ] GC(0) Old sizing: calculated: 11608B, actual: 11608B
35885
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    44
 */
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    45
final public class LogParser {
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    46
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    47
    // Name for GC ID field in report.
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    48
    public final static String GC_ID = "gc_id";
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    49
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    50
    /**
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    51
     * Type of parsed log element.
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    52
     */
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    53
    public static enum ReportType {
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    54
        SURVIVOR_STATS,
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    55
        OLD_STATS
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    56
    }
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    57
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    58
    private final String log;
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    59
37061
f4f1c40edfd9 8150183: gc/g1/plab/TestPLABResize.java - previous PLAB size should be less than current
mchernov
parents: 36390
diff changeset
    60
    // Contains Map of PLAB statistics for given log.
f4f1c40edfd9 8150183: gc/g1/plab/TestPLABResize.java - previous PLAB size should be less than current
mchernov
parents: 36390
diff changeset
    61
    private final Map<Long, Map<ReportType, Map<String, Long>>> report;
35885
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    62
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    63
    // GC ID
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    64
    private static final Pattern GC_ID_PATTERN = Pattern.compile("\\[gc,plab\\s*\\] GC\\((\\d+)\\)");
36390
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35885
diff changeset
    65
    // Pattern for extraction pair <name>: <numeric value>
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35885
diff changeset
    66
    private static final Pattern PAIRS_PATTERN = Pattern.compile("\\w* \\w+:\\s+\\d+");
35885
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    67
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    68
    /**
37061
f4f1c40edfd9 8150183: gc/g1/plab/TestPLABResize.java - previous PLAB size should be less than current
mchernov
parents: 36390
diff changeset
    69
     * Construct LogParser object, parse log file with PLAB statistics and store it into report.
35885
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    70
     *
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    71
     * @param log - VM Output
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    72
     */
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    73
    public LogParser(String log) {
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    74
        if (log == null) {
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    75
            throw new IllegalArgumentException("Parameter log should not be null.");
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    76
        }
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    77
        this.log = log;
37061
f4f1c40edfd9 8150183: gc/g1/plab/TestPLABResize.java - previous PLAB size should be less than current
mchernov
parents: 36390
diff changeset
    78
        report = parseLines();
35885
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    79
    }
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    80
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    81
    /**
37061
f4f1c40edfd9 8150183: gc/g1/plab/TestPLABResize.java - previous PLAB size should be less than current
mchernov
parents: 36390
diff changeset
    82
     * @return log which was processed
35885
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    83
     */
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    84
    public String getLog() {
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    85
        return log;
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    86
    }
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    87
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    88
    /**
37061
f4f1c40edfd9 8150183: gc/g1/plab/TestPLABResize.java - previous PLAB size should be less than current
mchernov
parents: 36390
diff changeset
    89
     * Returns the GC log entries for Survivor and Old stats.
f4f1c40edfd9 8150183: gc/g1/plab/TestPLABResize.java - previous PLAB size should be less than current
mchernov
parents: 36390
diff changeset
    90
     * The entries are represented as a map of gcID to the StatMap.
35885
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    91
     *
37061
f4f1c40edfd9 8150183: gc/g1/plab/TestPLABResize.java - previous PLAB size should be less than current
mchernov
parents: 36390
diff changeset
    92
     * @return The log entries for the Survivor and Old stats.
35885
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    93
     */
37061
f4f1c40edfd9 8150183: gc/g1/plab/TestPLABResize.java - previous PLAB size should be less than current
mchernov
parents: 36390
diff changeset
    94
    public Map<Long, Map<ReportType, Map<String, Long>>> getEntries() {
f4f1c40edfd9 8150183: gc/g1/plab/TestPLABResize.java - previous PLAB size should be less than current
mchernov
parents: 36390
diff changeset
    95
        return report;
35885
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    96
    }
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    97
37061
f4f1c40edfd9 8150183: gc/g1/plab/TestPLABResize.java - previous PLAB size should be less than current
mchernov
parents: 36390
diff changeset
    98
    private Map<Long, Map<ReportType, Map<String, Long>>> parseLines() throws NumberFormatException {
35885
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
    99
        Scanner lineScanner = new Scanner(log);
37061
f4f1c40edfd9 8150183: gc/g1/plab/TestPLABResize.java - previous PLAB size should be less than current
mchernov
parents: 36390
diff changeset
   100
        Map<Long, Map<ReportType, Map<String, Long>>> allocationStatistics = new HashMap<>();
35885
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
   101
        Optional<Long> gc_id;
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
   102
        while (lineScanner.hasNextLine()) {
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
   103
            String line = lineScanner.nextLine();
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
   104
            gc_id = getGcId(line);
37061
f4f1c40edfd9 8150183: gc/g1/plab/TestPLABResize.java - previous PLAB size should be less than current
mchernov
parents: 36390
diff changeset
   105
            if (gc_id.isPresent()) {
35885
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
   106
                Matcher matcher = PAIRS_PATTERN.matcher(line);
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
   107
                if (matcher.find()) {
37061
f4f1c40edfd9 8150183: gc/g1/plab/TestPLABResize.java - previous PLAB size should be less than current
mchernov
parents: 36390
diff changeset
   108
                    Map<ReportType, Map<String, Long>> oneReportItem;
35885
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
   109
                    ReportType reportType;
36390
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35885
diff changeset
   110
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35885
diff changeset
   111
                    if (!allocationStatistics.containsKey(gc_id.get())) {
37061
f4f1c40edfd9 8150183: gc/g1/plab/TestPLABResize.java - previous PLAB size should be less than current
mchernov
parents: 36390
diff changeset
   112
                        allocationStatistics.put(gc_id.get(), new EnumMap<>(ReportType.class));
36390
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35885
diff changeset
   113
                    }
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35885
diff changeset
   114
37061
f4f1c40edfd9 8150183: gc/g1/plab/TestPLABResize.java - previous PLAB size should be less than current
mchernov
parents: 36390
diff changeset
   115
                    if (line.contains("Young")) {
35885
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
   116
                        reportType = ReportType.SURVIVOR_STATS;
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
   117
                    } else {
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
   118
                        reportType = ReportType.OLD_STATS;
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
   119
                    }
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
   120
36390
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35885
diff changeset
   121
                    oneReportItem = allocationStatistics.get(gc_id.get());
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35885
diff changeset
   122
                    if (!oneReportItem.containsKey(reportType)) {
37061
f4f1c40edfd9 8150183: gc/g1/plab/TestPLABResize.java - previous PLAB size should be less than current
mchernov
parents: 36390
diff changeset
   123
                        oneReportItem.put(reportType, new HashMap<>());
36390
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35885
diff changeset
   124
                    }
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35885
diff changeset
   125
35885
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
   126
                    // Extract all pairs from log.
36390
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35885
diff changeset
   127
                    Map<String, Long> plabStats = oneReportItem.get(reportType);
35885
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
   128
                    do {
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
   129
                        String pair = matcher.group();
36390
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35885
diff changeset
   130
                        String[] nameValue = pair.replaceAll(": ", ":").split(":");
a2d991d1d628 8141141: Young and Old gen PLAB stats are similar in output with -XX:+PrintPLAB
tschatzl
parents: 35885
diff changeset
   131
                        plabStats.put(nameValue[0].trim(), Long.parseLong(nameValue[1]));
35885
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
   132
                    } while (matcher.find());
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
   133
                }
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
   134
            }
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
   135
        }
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
   136
        return allocationStatistics;
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
   137
    }
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
   138
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
   139
    private Optional<Long> getGcId(String line) {
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
   140
        Matcher number = GC_ID_PATTERN.matcher(line);
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
   141
        if (number.find()) {
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
   142
            return Optional.of(Long.parseLong(number.group(1)));
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
   143
        }
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
   144
        return Optional.empty();
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
   145
    }
6e62be7db2c8 8141278: New tests for PLAB testing
mchernov
parents:
diff changeset
   146
}