# HG changeset patch # User Doug Simon # Date 1376942640 -7200 # Node ID d335c16d2fe7f6d381536089e9c4c1894c34d99c # Parent 5a7644d5fe207e5b65da7de4b75cf264c0363957 replaced PerThreadDebugValues, SummarizeDebugValues and SummarisePerPhase options with DebugValueSummary option omit printing of scopes without any non-zero nested debug values diff -r 5a7644d5fe20 -r d335c16d2fe7 graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalDebugConfig.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalDebugConfig.java Mon Aug 19 22:01:07 2013 +0200 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalDebugConfig.java Mon Aug 19 22:04:00 2013 +0200 @@ -48,12 +48,12 @@ public static final OptionValue Log = new OptionValue<>(null); @Option(help = "Filters debug scope output by method name/pattern") public static final OptionValue MethodFilter = new OptionValue<>(null); - @Option(help = "") - public static final OptionValue PerThreadDebugValues = new OptionValue<>(false); - @Option(help = "") - public static final OptionValue SummarizeDebugValues = new OptionValue<>(false); - @Option(help = "") - public static final OptionValue SummarizePerPhase = new OptionValue<>(false); + @Option(help = "How to print metric and timing values:%n" + + "Name - aggregate by unqualified name%n" + + "Thread - aggregate by qualified name and thread%n" + + "Complete - aggregate by qualified name%n" + + "Partial - aggregate by partially qualified name (e.g., A.B.C.D.Counter and X.Y.Z.D.Counter will be merged to D.Counter)") + public static final OptionValue DebugValueSummary = new OptionValue<>("Complete"); @Option(help = "Send Graal IR to dump handlers on error") public static final OptionValue DumpOnError = new OptionValue<>(false); @Option(help = "Enable expensive assertions") diff -r 5a7644d5fe20 -r d335c16d2fe7 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java Mon Aug 19 22:01:07 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java Mon Aug 19 22:04:00 2013 +0200 @@ -446,29 +446,42 @@ ArrayList sortedValues = new ArrayList<>(debugValues); Collections.sort(sortedValues); - if (SummarizeDebugValues.getValue()) { - printSummary(topLevelMaps, sortedValues); - } else if (PerThreadDebugValues.getValue()) { - for (DebugValueMap map : topLevelMaps) { - TTY.println("Showing the results for thread: " + map.getName()); - map.group(); - map.normalize(); - printMap(map, sortedValues, 0); + String summary = DebugValueSummary.getValue(); + if (summary == null) { + summary = "Scope"; + } + switch (summary) { + case "PartialScope": { + DebugValueMap globalMap = new DebugValueMap("Global"); + for (DebugValueMap map : topLevelMaps) { + flattenChildren(map, globalMap); + } + globalMap.normalize(); + printMap(new DebugValueScope(null, globalMap), sortedValues); + break; } - } else { - DebugValueMap globalMap = new DebugValueMap("Global"); - for (DebugValueMap map : topLevelMaps) { - if (SummarizePerPhase.getValue()) { - flattenChildren(map, globalMap); - } else { + case "Thread": + for (DebugValueMap map : topLevelMaps) { + TTY.println("Showing the results for thread: " + map.getName()); + map.group(); + map.normalize(); + printMap(new DebugValueScope(null, map), sortedValues); + } + break; + case "Name": + printSummary(topLevelMaps, sortedValues); + break; + case "Scope": // fall through + default: { + DebugValueMap globalMap = new DebugValueMap("Global"); + for (DebugValueMap map : topLevelMaps) { globalMap.addChild(map); } + globalMap.group(); + globalMap.normalize(); + printMap(new DebugValueScope(null, globalMap), sortedValues); + break; } - if (!SummarizePerPhase.getValue()) { - globalMap.group(); - } - globalMap.normalize(); - printMap(globalMap, sortedValues, 0); } } } @@ -501,7 +514,7 @@ long total = collectTotal(topLevelMaps, index); result.setCurrentValue(index, total); } - printMap(result, debugValues, 0); + printMap(new DebugValueScope(null, result), debugValues); } static long collectTotal(DebugValue value) { @@ -526,21 +539,48 @@ return total; } - private static void printMap(DebugValueMap map, List debugValues, int level) { + /** + * Tracks the scope when printing a {@link DebugValueMap}, allowing "empty" scopes to be + * omitted. An empty scope is one in which there are no (nested) non-zero debug values. + */ + static class DebugValueScope { + + final DebugValueScope parent; + final int level; + final DebugValueMap map; + private boolean printed; - printIndent(level); - TTY.println("%s", map.getName()); + public DebugValueScope(DebugValueScope parent, DebugValueMap map) { + this.parent = parent; + this.map = map; + this.level = parent == null ? 0 : parent.level + 1; + } + + public void print() { + if (!printed) { + printed = true; + if (parent != null) { + parent.print(); + } + printIndent(level); + TTY.println("%s", map.getName()); + } + } + } + + private static void printMap(DebugValueScope scope, List debugValues) { for (DebugValue value : debugValues) { - long l = map.getCurrentValue(value.getIndex()); + long l = scope.map.getCurrentValue(value.getIndex()); if (l != 0) { - printIndent(level + 1); + scope.print(); + printIndent(scope.level + 1); TTY.println(value.getName() + "=" + value.toString(l)); } } - for (DebugValueMap child : map.getChildren()) { - printMap(child, debugValues, level + 1); + for (DebugValueMap child : scope.map.getChildren()) { + printMap(new DebugValueScope(scope, child), debugValues); } }