@Override public void notifyCompilationSuccess( OptimizedCallTarget target, TruffleInlining inliningDecision, StructuredGraph graph, CompilationResult result) { success++; long compilationDone = System.nanoTime(); CompilationLocal local = compilationLocal.get(); compilationTime.accept(compilationDone - local.compilationStarted); compilationTimeTruffleTier.accept(local.truffleTierFinished - local.compilationStarted); compilationTimeGraalTier.accept(local.graalTierFinished - local.truffleTierFinished); compilationTimeCodeInstallation.accept(compilationDone - local.graalTierFinished); compilationResultCodeSize.accept(result.getTargetCodeSize()); compilationResultTotalFrameSize.accept(result.getTotalFrameSize()); compilationResultExceptionHandlers.accept(result.getExceptionHandlers().size()); compilationResultInfopoints.accept(result.getInfopoints().size()); compilationResultInfopointStatistics.accept( result.getInfopoints().stream().map(e -> e.reason.toString())); compilationResultMarks.accept(result.getMarks().size()); compilationResultDataPatches.accept(result.getDataPatches().size()); }
private static void printStatisticTime( GraalTruffleRuntime rt, String label, LongSummaryStatistics value) { rt.log( String.format( " %-50s: count=%4d, sum=%8d, min=%8d, average=%12.2f, max=%8d (milliseconds)", label, value.getCount(), value.getSum() / 1000000, value.getMin() / 1000000, value.getAverage() / 1e6, value.getMax() / 1000000)); }
private static Statistics createStatistics(LongSummaryStatistics stats) { boolean some = stats.getCount() > 0L; return new Statistics() { @Override public long getCount() { return stats.getCount(); } @Override public Duration getMaximum() { return some ? Duration.ofNanos(stats.getMax()) : Duration.ZERO; } @Override public Duration getMinimum() { return some ? Duration.ofNanos(stats.getMin()) : Duration.ZERO; } @Override public Duration getTotal() { return some ? Duration.ofNanos(stats.getSum()) : Duration.ZERO; } @Override public Duration getAverage() { return some ? Duration.ofNanos((long) stats.getAverage()) : Duration.ZERO; } private String fixedLengthSeconds(Duration duration) { double seconds = duration.toNanos() * 1e-9; String result = new DecimalFormat("##0.00000").format(seconds) + "s"; if (result.length() == 8) return " " + result; if (result.length() == 9) return " " + result; return result; } private String fixedLength(long count) { String result = new DecimalFormat("###0").format(count); if (result.length() == 1) return " " + result; if (result.length() == 2) return " " + result; if (result.length() == 3) return " " + result; return result; } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append(fixedLengthSeconds(getTotal()) + " total;"); sb.append(fixedLength(getCount()) + " samples;"); sb.append(fixedLengthSeconds(getAverage()) + " avg;"); sb.append(fixedLengthSeconds(getMinimum()) + " min;"); sb.append(fixedLengthSeconds(getMaximum()) + " max"); return sb.toString(); } }; }
@Override public void notifyCompilationQueued(OptimizedCallTarget target) { queues++; if (firstCompilation == 0) { firstCompilation = System.nanoTime(); } OptimizedCompilationProfile profile = target.getCompilationProfile(); if (profile != null) { timeToQueue.accept(System.nanoTime() - profile.getTimestamp()); } }
@Override public void notifyCompilationStarted(OptimizedCallTarget target) { compilations++; CompilationLocal local = new CompilationLocal(); local.compilationStarted = System.nanoTime(); compilationLocal.set(local); OptimizedCompilationProfile profile = target.getCompilationProfile(); if (profile != null) { deferCompilations.accept(profile.getDeferredCount()); timeToCompilation.accept(local.compilationStarted - profile.getTimestamp()); } }
public void printStatistics(GraalTruffleRuntime rt) { long endTime = System.nanoTime(); rt.log("Truffle compilation statistics:"); printStatistic(rt, "Compilations", compilations); printStatistic(rt, " Success", success); printStatistic(rt, " Failed", failures); printStatistic(rt, " Interrupted", compilations - (success + failures)); printStatistic(rt, "Invalidated", invalidations); printStatistic(rt, "Queues", queues); printStatistic(rt, "Dequeues", dequeues); printStatistic(rt, "Splits", splits); printStatistic(rt, "Compilation Accuracy", 1.0 - invalidations / (double) compilations); printStatistic(rt, "Queue Accuracy", 1.0 - dequeues / (double) queues); printStatistic( rt, "Compilation Utilization", compilationTime.getSum() / (double) (endTime - firstCompilation)); printStatistic(rt, "Remaining Compilation Queue", rt.getCompilationQueueSize()); printStatistic(rt, "Times defered until compilation", deferCompilations); printStatisticTime(rt, "Time to queue", timeToQueue); printStatisticTime(rt, "Time to compilation", timeToCompilation); printStatisticTime(rt, "Compilation time", compilationTime); printStatisticTime(rt, " Truffle Tier", compilationTimeTruffleTier); printStatisticTime(rt, " Graal Tier", compilationTimeGraalTier); printStatisticTime(rt, " Code Installation", compilationTimeCodeInstallation); printStatistic(rt, "Truffle node count", nodeCount); printStatistic(rt, " Trivial", nodeCountTrivial); printStatistic(rt, " Non Trivial", nodeCountNonTrivial); printStatistic(rt, " Monomorphic", nodeCountMonomorphic); printStatistic(rt, " Polymorphic", nodeCountPolymorphic); printStatistic(rt, " Megamorphic", nodeCountMegamorphic); printStatistic(rt, "Truffle call count", callCount); printStatistic(rt, " Indirect", callCountIndirect); printStatistic(rt, " Direct", callCountDirect); printStatistic(rt, " Dispatched", callCountDirectDispatched); printStatistic(rt, " Inlined", callCountDirectInlined); printStatistic(rt, " ----------"); printStatistic(rt, " Cloned", callCountDirectCloned); printStatistic(rt, " Not Cloned", callCountDirectNotCloned); printStatistic(rt, "Truffle loops", loopCount); printStatistic(rt, "Graal node count"); printStatistic(rt, " After Truffle Tier", truffleTierNodeCount); printStatistic(rt, " After Graal Tier", graalTierNodeCount); printStatistic(rt, "Graal comilation result"); printStatistic(rt, " Code size", compilationResultCodeSize); printStatistic(rt, " Total frame size", compilationResultTotalFrameSize); printStatistic(rt, " Exception handlers", compilationResultExceptionHandlers); printStatistic(rt, " Infopoints", compilationResultInfopoints); compilationResultInfopointStatistics.printStatistics(rt, identity()); printStatistic(rt, " Marks", compilationResultMarks); printStatistic(rt, " Data references", compilationResultDataPatches); if (TruffleCompilerOptions.TruffleCompilationStatisticDetails.getValue()) { printStatistic(rt, "Truffle nodes"); nodeStatistics.printStatistics(rt, Class::getSimpleName); printStatistic(rt, "Graal nodes after Truffle tier"); truffleTierNodeStatistics.printStatistics(rt, Class::getSimpleName); printStatistic(rt, "Graal nodes after Graal tier"); graalTierNodeStatistics.printStatistics(rt, Class::getSimpleName); } }
/** * Get the top n external Services of the given services. * * @param statistics * @param externalServices * @param timeRange * @param limit * @return */ public static List<ExternalServiceVo> topByAvgResponseTime( Iterable<ExternalServiceStatistic> statistics, Iterable<ExternalService> externalServices, TimeRange timeRange, Integer limit) { Map<Long, ExternalService> rpcTransactionMap = new HashMap<>(); StreamSupport.stream(externalServices.spliterator(), false) .forEach(transaction -> rpcTransactionMap.put(transaction.getId(), transaction)); Map<TransactionGroup, List<ExternalServiceStatistic>> groups = StreamSupport.stream(statistics.spliterator(), false) .collect( Collectors.groupingBy( new Function<ExternalServiceStatistic, TransactionGroup>() { @Override public TransactionGroup apply(ExternalServiceStatistic statistic) { Long transactionId = statistic.getExternalServiceId(); ExternalService webTransaction = rpcTransactionMap.get(transactionId); TransactionGroup group = new TransactionGroup(); group.setAppId(webTransaction.getAppId()); group.setDisplayName(webTransaction.getUrl()); return group; } })); List<ExternalServiceVo> result = new ArrayList<>(); groups.forEach( (group, webTransactionStatistics) -> { DoubleSummaryStatistics responseSummaryStatistics = webTransactionStatistics .stream() .filter(statistic -> statistic.getSumResponseTime() != null) .mapToDouble(ExternalServiceStatistic::getSumResponseTime) .summaryStatistics(); DoubleSummaryStatistics maxSummaryStatistics = webTransactionStatistics .stream() .filter(statistic -> statistic.getMaxResponseTime() != null) .mapToDouble(ExternalServiceStatistic::getMaxResponseTime) .summaryStatistics(); DoubleSummaryStatistics minSummaryStatistics = webTransactionStatistics .stream() .filter(statistic -> statistic.getMinResponseTime() != null) .mapToDouble(ExternalServiceStatistic::getMinResponseTime) .summaryStatistics(); LongSummaryStatistics pvSummaryStatistics = webTransactionStatistics .stream() .filter(statistic -> statistic.getPv() != null) .mapToLong(ExternalServiceStatistic::getPv) .summaryStatistics(); ExternalServiceVo transaction = new ExternalServiceVo(); transaction.setAppId(group.getAppId()); transaction.setDestination(group.getDisplayName()); transaction.setPv(pvSummaryStatistics.getSum()); transaction.setCpm( format( calculateRate( pvSummaryStatistics.getSum(), timeRange.getDuration(ChronoUnit.MINUTES)))); transaction.setMaxResponseTime(format(maxSummaryStatistics.getMax())); transaction.setMinResponseTime(format(minSummaryStatistics.getMin())); transaction.setResponseTime( format( calculateRate(responseSummaryStatistics.getSum(), pvSummaryStatistics.getSum()))); result.add(transaction); }); return result .stream() .sorted(Comparator.comparing(ExternalServiceVo::getResponseTime)) .limit(limit) .collect(Collectors.toList()); }
@Override public void add(Duration duration) { LongSummaryStatistics stats = new LongSummaryStatistics(); if (duration != null) stats.accept(duration.toNanos()); this.stats.set(createStatistics(stats)); }