# HG changeset patch # User Lukas Stadler # Date 1366723280 -7200 # Node ID c4561d60fd9aa8afeced637d539780d7a2618e8f # Parent 435bb9425124e673b904f9edb8c01dc0767f0c93 add grouping to dynamic counters diff -r 435bb9425124 -r c4561d60fd9a graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/debug/DynamicCounterNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/debug/DynamicCounterNode.java Tue Apr 23 15:19:53 2013 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/debug/DynamicCounterNode.java Tue Apr 23 15:21:20 2013 +0200 @@ -45,20 +45,24 @@ private static final int MAX_COUNTERS = 10 * 1024; private static final long[] COUNTERS = new long[MAX_COUNTERS]; + private static final long[] STATIC_COUNTERS = new long[MAX_COUNTERS]; + private static final String[] GROUPS = new String[MAX_COUNTERS]; private static final HashMap INDEXES = new HashMap<>(); public static String excludedClassPrefix = null; public static boolean enabled = false; private final String name; + private final String group; private final long increment; private final boolean addContext; - public DynamicCounterNode(String name, long increment, boolean addContext) { + public DynamicCounterNode(String name, String group, long increment, boolean addContext) { super(StampFactory.forVoid()); if (!enabled) { throw new GraalInternalError("dynamic counters not enabled"); } this.name = name; + this.group = group; this.increment = increment; this.addContext = addContext; } @@ -90,29 +94,51 @@ } public static synchronized void dump(PrintStream out, double seconds) { + for (String group : new HashSet<>(Arrays.asList(GROUPS))) { + dumpCounters(out, seconds, true, group); + dumpCounters(out, seconds, false, group); + } + out.println("============================"); + + clear(); + } + + private static void dumpCounters(PrintStream out, double seconds, boolean staticCounter, String group) { TreeMap sorted = new TreeMap<>(); + long[] array = staticCounter ? STATIC_COUNTERS : COUNTERS; long sum = 0; - for (int i = 0; i < MAX_COUNTERS; i++) { - sum += COUNTERS[i]; - } - long cutoff = sum / 1000; - int cnt = 0; for (Map.Entry entry : INDEXES.entrySet()) { - if (COUNTERS[entry.getValue()] > cutoff) { - sorted.put(COUNTERS[entry.getValue()] * MAX_COUNTERS + cnt++, entry.getKey()); + int index = entry.getValue(); + if (GROUPS[index].equals(group)) { + sum += array[index]; + sorted.put(array[index] * MAX_COUNTERS + index, entry.getKey()); } } - out.println("=========== dynamic counters, time = " + seconds + " s"); - for (Map.Entry entry : sorted.entrySet()) { - long counter = entry.getKey() / MAX_COUNTERS; - out.println((int) (counter / seconds) + "/s \t" + (counter * 100 / sum) + "% \t" + entry.getValue()); + long cutoff = sum / 1000; + long sum2 = 0; + if (staticCounter) { + out.println("=========== " + group + " static counters: "); + for (Map.Entry entry : sorted.entrySet()) { + long counter = entry.getKey() / MAX_COUNTERS; + sum2 += counter; + if (sum2 >= cutoff) { + out.println(counter + " \t" + ((counter * 200 + 1) / sum / 2) + "% \t" + entry.getValue()); + } + } + out.println(sum + ": total"); + } else { + out.println("=========== " + group + " dynamic counters, time = " + seconds + " s"); + for (Map.Entry entry : sorted.entrySet()) { + long counter = entry.getKey() / MAX_COUNTERS; + sum2 += counter; + if (sum2 >= cutoff) { + out.println((int) (counter / seconds) + "/s \t" + ((counter * 200 + 1) / sum / 2) + "% \t" + entry.getValue()); + } + } + out.println((int) (sum / seconds) + "/s: total"); } - out.println((int) (sum / seconds) + "/s: total"); - out.println("============================"); - - clear(); } public static void clear() { @@ -120,13 +146,15 @@ } @Override - public void lower(LoweringTool tool) { + public void lower(LoweringTool tool, LoweringType loweringType) { if (!enabled) { throw new GraalInternalError("counter nodes shouldn't exist when not enabled"); } StructuredGraph graph = (StructuredGraph) graph(); if (excludedClassPrefix == null || !graph.method().getDeclaringClass().getName().startsWith(excludedClassPrefix)) { int index = addContext ? getIndex(name + " @ " + MetaUtil.format("%h.%n", ((StructuredGraph) graph()).method())) : getIndex(name); + STATIC_COUNTERS[index] += increment; + GROUPS[index] = group; ConstantNode arrayConstant = ConstantNode.forObject(COUNTERS, tool.getRuntime(), graph); ConstantNode indexConstant = ConstantNode.forInt(index, graph); @@ -140,10 +168,10 @@ graph.removeFixed(this); } - public static void addCounterBefore(String name, long increment, boolean addContext, FixedNode position) { + public static void addCounterBefore(String group, String name, long increment, boolean addContext, FixedNode position) { if (enabled) { StructuredGraph graph = (StructuredGraph) position.graph(); - DynamicCounterNode counter = graph.add(new DynamicCounterNode(name, increment, addContext)); + DynamicCounterNode counter = graph.add(new DynamicCounterNode(name, group, increment, addContext)); graph.addBeforeFixed(position, counter); } } diff -r 435bb9425124 -r c4561d60fd9a graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/debug/SurvivingCounterNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/debug/SurvivingCounterNode.java Tue Apr 23 15:19:53 2013 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/debug/SurvivingCounterNode.java Tue Apr 23 15:21:20 2013 +0200 @@ -35,8 +35,8 @@ @Input private ValueNode checkedValue; - public SurvivingCounterNode(String name, long increment, boolean addContext, ValueNode checkedValue) { - super(name, increment, addContext); + public SurvivingCounterNode(String group, String name, long increment, boolean addContext, ValueNode checkedValue) { + super(group, name, increment, addContext); this.checkedValue = checkedValue; } diff -r 435bb9425124 -r c4561d60fd9a graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/GraphEffectList.java --- a/graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/GraphEffectList.java Tue Apr 23 15:19:53 2013 +0200 +++ b/graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/GraphEffectList.java Tue Apr 23 15:21:20 2013 +0200 @@ -33,7 +33,7 @@ public class GraphEffectList extends EffectList { - public void addCounterBefore(final String name, final int increment, final boolean addContext, final FixedNode position) { + public void addCounterBefore(final String group, final String name, final int increment, final boolean addContext, final FixedNode position) { if (!DynamicCounterNode.enabled) { return; } @@ -47,13 +47,13 @@ @Override public void apply(StructuredGraph graph, ArrayList obsoleteNodes) { assert position.isAlive(); - DynamicCounterNode node = graph.add(new DynamicCounterNode(name, increment, addContext)); + DynamicCounterNode node = graph.add(new DynamicCounterNode(group, name, increment, addContext)); graph.addBeforeFixed(position, node); } }); } - public void addSurvivingCounterBefore(final String name, final int increment, final boolean addContext, final ValueNode checkedValue, final FixedNode position) { + public void addSurvivingCounterBefore(final String group, final String name, final int increment, final boolean addContext, final ValueNode checkedValue, final FixedNode position) { if (!DynamicCounterNode.enabled) { return; } @@ -67,7 +67,7 @@ @Override public void apply(StructuredGraph graph, ArrayList obsoleteNodes) { assert position.isAlive(); - DynamicCounterNode node = graph.add(new SurvivingCounterNode(name, increment, addContext, checkedValue)); + DynamicCounterNode node = graph.add(new SurvivingCounterNode(group, name, increment, addContext, checkedValue)); graph.addBeforeFixed(position, node); } });