# HG changeset patch # User Christian Humer # Date 1414419494 -3600 # Node ID ae3b7695f0fbdc923c7c1b13cb43537c833428f2 # Parent 62de94d5cf7345fb656d9fbc8b32205519c61212 Truffle: refactor TruffleCallTargetProfiling into a separate class. diff -r 62de94d5cf73 -r ae3b7695f0fb graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/GraalTruffleRuntime.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/GraalTruffleRuntime.java Mon Oct 27 15:18:14 2014 +0100 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/GraalTruffleRuntime.java Mon Oct 27 15:18:14 2014 +0100 @@ -60,6 +60,7 @@ TraceCompilationFailureListener.install(this); TraceCompilationListener.install(this); TraceCompilationPolymorphismListener.install(this); + PrintCallTargetProfiling.install(this); } protected void lookupCallMethods(MetaAccessProvider metaAccess) { diff -r 62de94d5cf73 -r ae3b7695f0fb graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallTargetLog.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallTargetLog.java Mon Oct 27 15:18:14 2014 +0100 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallTargetLog.java Mon Oct 27 15:18:14 2014 +0100 @@ -26,30 +26,15 @@ import java.io.*; import java.util.*; -import java.util.function.*; -import java.util.stream.*; import com.oracle.graal.debug.*; import com.oracle.graal.truffle.TruffleInlining.CallTreeNodeVisitor; -import com.oracle.truffle.api.*; -import com.oracle.truffle.api.nodes.Node; +import com.oracle.truffle.api.nodes.*; public final class OptimizedCallTargetLog { protected static final PrintStream OUT = TTY.out().out(); - static { - if (TruffleCallTargetProfiling.getValue()) { - Runtime.getRuntime().addShutdownHook(new Thread() { - - @Override - public void run() { - printProfiling(); - } - }); - } - } - private OptimizedCallTargetLog() { } @@ -188,63 +173,4 @@ } OUT.println(sb.toString()); } - - private static int sumCalls(List targets, Function function) { - return targets.stream().collect(Collectors.summingInt(target -> function.apply((TraceCompilationProfile) target.getCompilationProfile()))); - } - - private static void printProfiling() { - // @formatter:off - Map> groupedTargets = Truffle.getRuntime().getCallTargets().stream(). - map(target -> (OptimizedCallTarget) target). - collect(Collectors.groupingBy(target -> { - if (target.getSourceCallTarget() != null) { - return target.getSourceCallTarget(); - } - return target; - })); - // @formatter:on - - List uniqueSortedTargets = groupedTargets.keySet().stream().sorted( - (target1, target2) -> sumCalls(groupedTargets.get(target2), p -> p.getTotalCallCount()) - sumCalls(groupedTargets.get(target1), p -> p.getTotalCallCount())).collect( - Collectors.toList()); - // @formatter:on - - int totalDirectCallCount = 0; - int totalInlinedCallCount = 0; - int totalIndirectCallCount = 0; - int totalTotalCallCount = 0; - int totalInterpretedCallCount = 0; - int totalInvalidationCount = 0; - - OUT.println(); - OUT.printf(" %-50s | %-15s || %-15s | %-15s || %-15s | %-15s | %-15s || %3s \n", "Call Target", "Total Calls", "Interp. Calls", "Opt. Calls", "Direct Calls", "Inlined Calls", - "Indirect Calls", "Invalidations"); - for (OptimizedCallTarget uniqueCallTarget : uniqueSortedTargets) { - List allCallTargets = groupedTargets.get(uniqueCallTarget); - int directCallCount = sumCalls(allCallTargets, p -> p.getDirectCallCount()); - int indirectCallCount = sumCalls(allCallTargets, p -> p.getIndirectCallCount()); - int inlinedCallCount = sumCalls(allCallTargets, p -> p.getInlinedCallCount()); - int interpreterCallCount = sumCalls(allCallTargets, p -> p.getInterpreterCallCount()); - int totalCallCount = sumCalls(allCallTargets, p -> p.getTotalCallCount()); - int invalidationCount = allCallTargets.stream().collect(Collectors.summingInt(target -> target.getCompilationProfile().getInvalidationCount())); - - totalDirectCallCount += directCallCount; - totalInlinedCallCount += inlinedCallCount; - totalIndirectCallCount += indirectCallCount; - totalInvalidationCount += invalidationCount; - totalInterpretedCallCount += interpreterCallCount; - totalTotalCallCount += totalCallCount; - - if (totalCallCount > 0) { - OUT.printf(" %-50s | %15d || %15d | %15d || %15d | %15d | %15d || %3d\n", uniqueCallTarget, totalCallCount, interpreterCallCount, totalCallCount - interpreterCallCount, - directCallCount, inlinedCallCount, indirectCallCount, invalidationCount); - } - - } - - OUT.printf(" %-50s | %15d || %15d | %15d || %15d | %15d | %15d || %3d\n", "Total", totalTotalCallCount, totalInterpretedCallCount, totalTotalCallCount - totalInterpretedCallCount, - totalDirectCallCount, totalInlinedCallCount, totalIndirectCallCount, totalInvalidationCount); - - } } diff -r 62de94d5cf73 -r ae3b7695f0fb graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/debug/PrintCallTargetProfiling.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/debug/PrintCallTargetProfiling.java Mon Oct 27 15:18:14 2014 +0100 @@ -0,0 +1,75 @@ +package com.oracle.graal.truffle.debug; + +import static com.oracle.graal.truffle.TruffleCompilerOptions.*; + +import java.util.*; +import java.util.function.*; +import java.util.stream.*; + +import com.oracle.graal.truffle.*; +import com.oracle.truffle.api.*; + +public class PrintCallTargetProfiling extends AbstractDebugCompilationListener { + + public static void install(GraalTruffleRuntime runtime) { + if (TruffleCallTargetProfiling.getValue()) { + runtime.addCompilationListener(new PrintCallTargetProfiling()); + } + } + + @Override + public void notifyShutdown(TruffleRuntime runtime) { + Map> groupedTargets = Truffle.getRuntime().getCallTargets().stream().map(target -> (OptimizedCallTarget) target).collect( + Collectors.groupingBy(target -> { + if (target.getSourceCallTarget() != null) { + return target.getSourceCallTarget(); + } + return target; + })); + + List uniqueSortedTargets = groupedTargets.keySet().stream().sorted( + (target1, target2) -> sumCalls(groupedTargets.get(target2), p -> p.getTotalCallCount()) - sumCalls(groupedTargets.get(target1), p -> p.getTotalCallCount())).collect( + Collectors.toList()); + + int totalDirectCallCount = 0; + int totalInlinedCallCount = 0; + int totalIndirectCallCount = 0; + int totalTotalCallCount = 0; + int totalInterpretedCallCount = 0; + int totalInvalidationCount = 0; + + OUT.println(); + OUT.printf(" %-50s | %-15s || %-15s | %-15s || %-15s | %-15s | %-15s || %3s \n", "Call Target", "Total Calls", "Interp. Calls", "Opt. Calls", "Direct Calls", "Inlined Calls", + "Indirect Calls", "Invalidations"); + for (OptimizedCallTarget uniqueCallTarget : uniqueSortedTargets) { + List allCallTargets = groupedTargets.get(uniqueCallTarget); + int directCallCount = sumCalls(allCallTargets, p -> p.getDirectCallCount()); + int indirectCallCount = sumCalls(allCallTargets, p -> p.getIndirectCallCount()); + int inlinedCallCount = sumCalls(allCallTargets, p -> p.getInlinedCallCount()); + int interpreterCallCount = sumCalls(allCallTargets, p -> p.getInterpreterCallCount()); + int totalCallCount = sumCalls(allCallTargets, p -> p.getTotalCallCount()); + int invalidationCount = allCallTargets.stream().collect(Collectors.summingInt(target -> target.getCompilationProfile().getInvalidationCount())); + + totalDirectCallCount += directCallCount; + totalInlinedCallCount += inlinedCallCount; + totalIndirectCallCount += indirectCallCount; + totalInvalidationCount += invalidationCount; + totalInterpretedCallCount += interpreterCallCount; + totalTotalCallCount += totalCallCount; + + if (totalCallCount > 0) { + OUT.printf(" %-50s | %15d || %15d | %15d || %15d | %15d | %15d || %3d\n", uniqueCallTarget, totalCallCount, interpreterCallCount, totalCallCount - interpreterCallCount, + directCallCount, inlinedCallCount, indirectCallCount, invalidationCount); + } + + } + + OUT.printf(" %-50s | %15d || %15d | %15d || %15d | %15d | %15d || %3d\n", "Total", totalTotalCallCount, totalInterpretedCallCount, totalTotalCallCount - totalInterpretedCallCount, + totalDirectCallCount, totalInlinedCallCount, totalIndirectCallCount, totalInvalidationCount); + + } + + private static int sumCalls(List targets, Function function) { + return targets.stream().collect(Collectors.summingInt(target -> function.apply((TraceCompilationProfile) target.getCompilationProfile()))); + } +}