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(); } }; }
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)); }