Mercurial > hg > truffle
diff graal/com.oracle.max.cri/src/com/oracle/max/cri/ci/CiUtil.java @ 5344:f47c770756e6
moved RiResolvedMethod.dumpProfile() to CiUtil.profileAsString()
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Wed, 02 May 2012 18:04:36 +0200 |
parents | cce31bc56c00 |
children | 4c3d953f8131 |
line wrap: on
line diff
--- a/graal/com.oracle.max.cri/src/com/oracle/max/cri/ci/CiUtil.java Wed May 02 17:09:00 2012 +0200 +++ b/graal/com.oracle.max.cri/src/com/oracle/max/cri/ci/CiUtil.java Wed May 02 18:04:36 2012 +0200 @@ -28,6 +28,7 @@ import java.util.*; import com.oracle.max.cri.ri.*; +import com.oracle.max.cri.ri.RiTypeProfile.ProfiledType; /** * Miscellaneous collection of utility methods used in the {@code CRI} project. @@ -736,4 +737,64 @@ } return result; } + + /** + * Formats the profiling information associated with a given method to a string. + */ + public static String profileAsString(RiResolvedMethod method) { + StringBuilder buf = new StringBuilder(100); + buf.append(String.format("canBeStaticallyBound: %b%n", method.canBeStaticallyBound())). + append(String.format("invocationCount: %d%n", method.invocationCount())); + RiProfilingInfo profilingInfo = method.profilingInfo(); + if (profilingInfo != null) { + for (int i = 0; i < method.codeSize(); i++) { + if (profilingInfo.getExecutionCount(i) != -1) { + buf.append(String.format("executionCount@%d: %d%n", i, profilingInfo.getExecutionCount(i))); + } + + if (profilingInfo.getBranchTakenProbability(i) != -1) { + buf.append(String.format("branchProbability@%d: %.3f%n", i, profilingInfo.getBranchTakenProbability(i))); + } + + double[] switchProbabilities = profilingInfo.getSwitchProbabilities(i); + if (switchProbabilities != null) { + buf.append(String.format("switchProbabilities@%d:", i)); + for (int j = 0; j < switchProbabilities.length; j++) { + buf.append(String.format(" %.3f", switchProbabilities[j])); + } + buf.append(NEW_LINE); + } + + if (profilingInfo.getExceptionSeen(i) != RiExceptionSeen.FALSE) { + buf.append(String.format("exceptionSeen@%d: %s%n", i, profilingInfo.getExceptionSeen(i).name())); + } + + RiTypeProfile typeProfile = profilingInfo.getTypeProfile(i); + if (typeProfile != null) { + ProfiledType[] ptypes = typeProfile.getTypes(); + if (ptypes != null) { + buf.append(String.format("types@%d:%n", i)); + for (int j = 0; j < ptypes.length; j++) { + ProfiledType ptype = ptypes[j]; + buf.append(String.format(" %.3f %s%n", ptype.probability, ptype.type)); + } + buf.append(String.format(" %.3f <not recorded>%n", typeProfile.getNotRecordedProbability())); + } + } + } + + boolean firstDeoptReason = true; + for (RiDeoptReason reason: RiDeoptReason.values()) { + int count = profilingInfo.getDeoptimizationCount(reason); + if (count > 0) { + if (firstDeoptReason) { + buf.append("deoptimization history").append(NEW_LINE); + firstDeoptReason = false; + } + buf.append(String.format(" %s: %d%n", reason.name(), count)); + } + } + } + return buf.toString(); + } }