8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 package org.graalvm.compiler.core.common.alloc; 24 25 import java.util.List; 26 27 import org.graalvm.compiler.core.common.cfg.AbstractBlockBase; 28 import org.graalvm.compiler.debug.Debug; 29 import org.graalvm.compiler.debug.Debug.Scope; 30 import org.graalvm.compiler.debug.Indent; 31 32 public final class TraceStatisticsPrinter { 33 private static final String SEP = ";"; 34 35 @SuppressWarnings("try") 36 public static void printTraceStatistics(TraceBuilderResult result, String compilationUnitName) { 37 try (Scope s = Debug.scope("DumpTraceStatistics")) { 38 if (Debug.isLogEnabled(Debug.VERBOSE_LEVEL)) { 39 print(result, compilationUnitName); 40 } 41 } catch (Throwable e) { 42 Debug.handle(e); 43 } 44 } 45 46 @SuppressWarnings("try") 47 protected static void print(TraceBuilderResult result, String compilationUnitName) { 48 List<Trace> traces = result.getTraces(); 49 int numTraces = traces.size(); 50 51 try (Indent indent0 = Debug.logAndIndent(Debug.VERBOSE_LEVEL, "<tracestatistics>")) { 52 Debug.log(Debug.VERBOSE_LEVEL, "<name>%s</name>", compilationUnitName != null ? compilationUnitName : "null"); 53 try (Indent indent1 = Debug.logAndIndent(Debug.VERBOSE_LEVEL, "<traces>")) { 54 printRawLine("tracenumber", "total", "min", "max", "numBlocks"); 55 for (int i = 0; i < numTraces; i++) { 56 AbstractBlockBase<?>[] t = traces.get(i).getBlocks(); 57 double total = 0; 58 double max = Double.NEGATIVE_INFINITY; 59 double min = Double.POSITIVE_INFINITY; 60 for (AbstractBlockBase<?> block : t) { 61 double probability = block.probability(); 62 total += probability; 63 if (probability < min) { 64 min = probability; 65 } 66 if (probability > max) { 67 max = probability; 68 } 69 } 70 printLine(i, total, min, max, t.length); 71 } 72 } 73 Debug.log(Debug.VERBOSE_LEVEL, "</traces>"); 74 } 75 Debug.log(Debug.VERBOSE_LEVEL, "</tracestatistics>"); 76 77 } 78 79 private static void printRawLine(Object tracenr, Object totalTime, Object minProb, Object maxProb, Object numBlocks) { 80 Debug.log(Debug.VERBOSE_LEVEL, "%s", String.join(SEP, tracenr.toString(), totalTime.toString(), minProb.toString(), maxProb.toString(), numBlocks.toString())); 81 } 82 83 private static void printLine(int tracenr, double totalTime, double minProb, double maxProb, int numBlocks) { 84 printRawLine(tracenr, totalTime, minProb, maxProb, numBlocks); 85 } 86 } | 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 package org.graalvm.compiler.core.common.alloc; 24 25 import java.util.List; 26 27 import org.graalvm.compiler.core.common.cfg.AbstractBlockBase; 28 import org.graalvm.compiler.debug.DebugContext; 29 import org.graalvm.compiler.debug.Indent; 30 31 public final class TraceStatisticsPrinter { 32 private static final String SEP = ";"; 33 34 @SuppressWarnings("try") 35 public static void printTraceStatistics(DebugContext debug, TraceBuilderResult result, String compilationUnitName) { 36 try (DebugContext.Scope s = debug.scope("DumpTraceStatistics")) { 37 if (debug.isLogEnabled(DebugContext.VERBOSE_LEVEL)) { 38 print(debug, result, compilationUnitName); 39 } 40 } catch (Throwable e) { 41 debug.handle(e); 42 } 43 } 44 45 @SuppressWarnings("try") 46 protected static void print(DebugContext debug, TraceBuilderResult result, String compilationUnitName) { 47 List<Trace> traces = result.getTraces(); 48 int numTraces = traces.size(); 49 50 try (Indent indent0 = debug.logAndIndent(DebugContext.VERBOSE_LEVEL, "<tracestatistics>")) { 51 debug.log(DebugContext.VERBOSE_LEVEL, "<name>%s</name>", compilationUnitName != null ? compilationUnitName : "null"); 52 try (Indent indent1 = debug.logAndIndent(DebugContext.VERBOSE_LEVEL, "<traces>")) { 53 printRawLine(debug, "tracenumber", "total", "min", "max", "numBlocks"); 54 for (int i = 0; i < numTraces; i++) { 55 AbstractBlockBase<?>[] t = traces.get(i).getBlocks(); 56 double total = 0; 57 double max = Double.NEGATIVE_INFINITY; 58 double min = Double.POSITIVE_INFINITY; 59 for (AbstractBlockBase<?> block : t) { 60 double probability = block.probability(); 61 total += probability; 62 if (probability < min) { 63 min = probability; 64 } 65 if (probability > max) { 66 max = probability; 67 } 68 } 69 printLine(debug, i, total, min, max, t.length); 70 } 71 } 72 debug.log(DebugContext.VERBOSE_LEVEL, "</traces>"); 73 } 74 debug.log(DebugContext.VERBOSE_LEVEL, "</tracestatistics>"); 75 76 } 77 78 private static void printRawLine(DebugContext debug, Object tracenr, Object totalTime, Object minProb, Object maxProb, Object numBlocks) { 79 debug.log(DebugContext.VERBOSE_LEVEL, "%s", String.join(SEP, tracenr.toString(), totalTime.toString(), minProb.toString(), maxProb.toString(), numBlocks.toString())); 80 } 81 82 private static void printLine(DebugContext debug, int tracenr, double totalTime, double minProb, double maxProb, int numBlocks) { 83 printRawLine(debug, tracenr, totalTime, minProb, maxProb, numBlocks); 84 } 85 } |