# HG changeset patch # User Doug Simon # Date 1427970177 -7200 # Node ID 393ccd88c317455295b183c16b5f96e6388bbec6 # Parent 1efae42be4f4df941896a43207623b913d2daa0c# Parent bb575368ea01aa5066c560a4fbe7d1563e8540bb Merge. diff -r 1efae42be4f4 -r 393ccd88c317 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/debug/BenchmarkCounters.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/debug/BenchmarkCounters.java Thu Apr 02 12:22:12 2015 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/debug/BenchmarkCounters.java Thu Apr 02 12:22:57 2015 +0200 @@ -24,6 +24,7 @@ import java.io.*; import java.util.*; +import java.util.Map.Entry; import java.util.concurrent.*; import java.util.concurrent.atomic.*; @@ -87,6 +88,8 @@ private static final OptionValue BenchmarkDynamicCounters = new OptionValue<>(null); @Option(help = "Use grouping separators for number printing", type = OptionType.Debug) private static final OptionValue DynamicCountersPrintGroupSeparator = new OptionValue<>(true); + @Option(help = "Print in human readable format", type = OptionType.Debug) + private static final OptionValue DynamicCountersHumanReadable = new OptionValue<>(true); //@formatter:on } @@ -168,7 +171,6 @@ } private static synchronized void dumpCounters(PrintStream out, double seconds, long[] counters, boolean staticCounter, String group, int maxRows) { - TreeMap sorted = new TreeMap<>(); // collect the numbers long[] array; @@ -183,14 +185,28 @@ array[i] -= delta[i]; } } + Set> counterEntrySet = counterMap.entrySet(); + if (Options.DynamicCountersHumanReadable.getValue()) { + dumpHumanReadable(out, seconds, staticCounter, group, maxRows, array, counterEntrySet); + } else { + dumpComputerReadable(out, staticCounter, group, array, counterEntrySet); + } + } + + private static String getName(String nameGroup, String group) { + return nameGroup.substring(0, nameGroup.length() - group.length() - 1); + } + + private static void dumpHumanReadable(PrintStream out, double seconds, boolean staticCounter, String group, int maxRows, long[] array, Set> counterEntrySet) { // sort the counters by putting them into a sorted map + TreeMap sorted = new TreeMap<>(); long sum = 0; - for (Map.Entry entry : counterMap.entrySet()) { + for (Map.Entry entry : counterEntrySet) { Counter counter = entry.getValue(); int index = counter.index; if (counter.group.equals(group)) { sum += array[index]; - sorted.put(array[index] * array.length + index, entry.getKey().substring(0, entry.getKey().length() - group.length() - 1)); + sorted.put(array[index] * array.length + index, getName(entry.getKey(), group)); } } @@ -237,6 +253,20 @@ } } + private static void dumpComputerReadable(PrintStream out, boolean staticCounter, String group, long[] array, Set> counterEntrySet) { + String category = staticCounter ? "static counters" : "dynamic counters"; + for (Map.Entry entry : counterEntrySet) { + Counter counter = entry.getValue(); + if (counter.group.equals(group)) { + String name = getName(entry.getKey(), group); + int index = counter.index; + long value = array[index]; + // TODO(je): escape strings + out.printf("%s;%s;%s;%d\n", category, group, name, value); + } + } + } + private static long percentage(long counter, long sum) { return (counter * 200 + 1) / sum / 2; }