Mercurial > hg > graal-compiler
changeset 22763:948369884428
TraceRA: add trace statistics dumping.
author | Josef Eisl <josef.eisl@jku.at> |
---|---|
date | Tue, 06 Oct 2015 17:58:23 +0200 |
parents | 8523434db559 |
children | 40a8dedf1554 |
files | graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/alloc/TraceStatisticsPrinter.java graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/trace/TraceRegisterAllocationPhase.java |
diffstat | 2 files changed, 89 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/alloc/TraceStatisticsPrinter.java Tue Oct 06 17:58:23 2015 +0200 @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.compiler.common.alloc; + +import java.util.List; + +import com.oracle.graal.compiler.common.cfg.AbstractBlockBase; +import com.oracle.graal.debug.Debug; +import com.oracle.graal.debug.Debug.Scope; +import com.oracle.graal.debug.Indent; + +public final class TraceStatisticsPrinter { + private static final String SEP = ";"; + private static final int TRACE_DUMP_LEVEL = 3; + + @SuppressWarnings("try") + public static <T extends AbstractBlockBase<T>> void printTraceStatistics(TraceBuilder.TraceBuilderResult<T> result, String compilationUnitName) { + try (Scope s = Debug.scope("DumpTraceStatistics")) { + if (Debug.isLogEnabled(TRACE_DUMP_LEVEL)) { + print(result, compilationUnitName); + } + } catch (Throwable e) { + Debug.handle(e); + } + } + + @SuppressWarnings("try") + protected static <T extends AbstractBlockBase<T>> void print(TraceBuilder.TraceBuilderResult<T> result, String compilationUnitName) { + List<List<T>> traces = result.getTraces(); + int numTraces = traces.size(); + + try (Indent indent0 = Debug.logAndIndent(TRACE_DUMP_LEVEL, "<tracestatistics>")) { + Debug.log(TRACE_DUMP_LEVEL, "<name>%s</name>", compilationUnitName != null ? compilationUnitName : "null"); + try (Indent indent1 = Debug.logAndIndent(TRACE_DUMP_LEVEL, "<traces>")) { + printRawLine("tracenumber", "total", "min", "max", "numBlocks"); + for (int i = 0; i < numTraces; i++) { + List<T> t = traces.get(i); + double total = 0; + double max = Double.NEGATIVE_INFINITY; + double min = Double.POSITIVE_INFINITY; + for (T block : t) { + double probability = block.probability(); + total += probability; + if (probability < min) { + min = probability; + } + if (probability > max) { + max = probability; + } + } + printLine(i, total, min, max, t.size()); + } + } + Debug.log(TRACE_DUMP_LEVEL, "</traces>"); + } + Debug.log(TRACE_DUMP_LEVEL, "</tracestatistics>"); + + } + + private static void printRawLine(Object tracenr, Object totalTime, Object minProb, Object maxProb, Object numBlocks) { + Debug.log(TRACE_DUMP_LEVEL, "%s", String.join(SEP, tracenr.toString(), totalTime.toString(), minProb.toString(), maxProb.toString(), numBlocks.toString())); + } + + private static void printLine(int tracenr, double totalTime, double minProb, double maxProb, int numBlocks) { + printRawLine(tracenr, totalTime, minProb, maxProb, numBlocks); + } +}
--- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/trace/TraceRegisterAllocationPhase.java Tue Oct 06 16:23:50 2015 +0200 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/trace/TraceRegisterAllocationPhase.java Tue Oct 06 17:58:23 2015 +0200 @@ -34,6 +34,7 @@ import com.oracle.graal.compiler.common.alloc.RegisterAllocationConfig; import com.oracle.graal.compiler.common.alloc.TraceBuilder; import com.oracle.graal.compiler.common.alloc.TraceBuilder.TraceBuilderResult; +import com.oracle.graal.compiler.common.alloc.TraceStatisticsPrinter; import com.oracle.graal.compiler.common.cfg.AbstractBlockBase; import com.oracle.graal.debug.Debug; import com.oracle.graal.debug.Debug.Scope; @@ -76,6 +77,7 @@ B startBlock = linearScanOrder.get(0); assert startBlock.equals(lir.getControlFlowGraph().getStartBlock()); TraceBuilderResult<B> resultTraces = TraceBuilder.computeTraces(startBlock, linearScanOrder); + TraceStatisticsPrinter.printTraceStatistics(resultTraces, lirGenRes.getCompilationUnitName()); Debug.dump(lir, "Before TraceRegisterAllocation"); int traceNumber = 0;