use of com.oracle.truffle.tools.profiler.CPUSampler in project graal by oracle.
the class CPUSamplerCLI method printAttributes.
private static void printAttributes(PrintStream out, CPUSampler sampler, String prefix, List<ProfilerNode<CPUSampler.Payload>> nodes, int maxRootLength) {
long samplePeriod = sampler.getPeriod();
long samples = sampler.getSampleCount();
long selfInterpreted = 0;
long selfCompiled = 0;
long totalInterpreted = 0;
long totalCompiled = 0;
for (ProfilerNode<CPUSampler.Payload> tree : nodes) {
CPUSampler.Payload payload = tree.getPayload();
selfInterpreted += payload.getSelfInterpretedHitCount();
selfCompiled += payload.getSelfCompiledHitCount();
if (!tree.isRecursive()) {
totalInterpreted += payload.getInterpretedHitCount();
totalCompiled += payload.getCompiledHitCount();
}
}
long totalSamples = totalInterpreted + totalCompiled;
if (totalSamples <= 0L) {
// hide methods without any cost
return;
}
assert totalSamples < samples;
ProfilerNode<CPUSampler.Payload> firstNode = nodes.get(0);
SourceSection sourceSection = firstNode.getSourceSection();
String rootName = firstNode.getRootName();
if (!firstNode.getTags().contains(StandardTags.RootTag.class)) {
rootName += "~" + formatIndices(sourceSection, needsColumnSpecifier(firstNode));
}
long selfSamples = selfInterpreted + selfCompiled;
long selfTime = selfSamples * samplePeriod;
double selfCost = selfSamples / (double) samples;
double selfCompiledP = 0.0;
if (selfSamples > 0) {
selfCompiledP = selfCompiled / (double) selfSamples;
}
String selfTimes = String.format("%10dms %5.1f%% | %5.1f%%", selfTime, selfCost * 100, selfCompiledP * 100);
long totalTime = totalSamples * samplePeriod;
double totalCost = totalSamples / (double) samples;
double totalCompiledP = totalCompiled / (double) totalSamples;
String totalTimes = String.format("%10dms %5.1f%% | %5.1f%%", totalTime, totalCost * 100, totalCompiledP * 100);
String location = getShortDescription(sourceSection);
out.println(//
String.format(//
" %-" + Math.max(maxRootLength, 10) + "s | %s || %s | %s ", prefix + rootName, totalTimes, selfTimes, location));
}
Aggregations