From 89428dd9a4724fa18b904ca59e55694d7f8f5520 Mon Sep 17 00:00:00 2001 From: Foivos Zakkak Date: Tue, 5 Oct 2021 09:51:37 +0300 Subject: [PATCH] Introduce PrintAnalysisCallTreeType option This option enables users to choose the structure of the call tree report. Currently supported formats are txt and csv. The use of this flag implicitly enables PrintAnalysisCallTree option. Closes: #3843 --- .../reports/AnalysisReportsOptions.java | 16 ++++++++++++++++ .../graal/pointsto/reports/CallTreePrinter.java | 17 +++++++++++++---- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/reports/AnalysisReportsOptions.java b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/reports/AnalysisReportsOptions.java index 62b9e9d5780f..b9b89061da1e 100644 --- a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/reports/AnalysisReportsOptions.java +++ b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/reports/AnalysisReportsOptions.java @@ -24,6 +24,8 @@ */ package com.oracle.graal.pointsto.reports; +import org.graalvm.collections.EconomicMap; +import org.graalvm.compiler.options.EnumOptionKey; import org.graalvm.compiler.options.Option; import org.graalvm.compiler.options.OptionKey; @@ -38,6 +40,15 @@ public class AnalysisReportsOptions { @Option(help = "Print analysis call tree, a breadth-first tree reduction of the call graph.")// public static final OptionKey PrintAnalysisCallTree = new OptionKey<>(false); + @Option(help = "Change the output format of the analysis call tree. See: Reports.md.")// + public static final EnumOptionKey PrintAnalysisCallTreeType = new EnumOptionKey(CallTreeType.TXT) { + @Override + protected void onValueUpdate(EconomicMap, Object> values, CallTreeType oldValue, CallTreeType newValue) { + super.onValueUpdate(values, oldValue, newValue); + PrintAnalysisCallTree.update(values, true); + } + }; + @Option(help = "Print image object hierarchy.")// public static final OptionKey PrintImageObjectTree = new OptionKey<>(false); @@ -52,4 +63,9 @@ public class AnalysisReportsOptions { @Option(help = "Suppress the expansion of specified types. See: Reports.md.")// public static final OptionKey ImageObjectTreeSuppressTypes = new OptionKey<>(""); + + enum CallTreeType { + TXT, + CSV; + } } diff --git a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/reports/CallTreePrinter.java b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/reports/CallTreePrinter.java index ac4b690ce86d..57d883526efe 100644 --- a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/reports/CallTreePrinter.java +++ b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/reports/CallTreePrinter.java @@ -61,6 +61,7 @@ import com.oracle.graal.pointsto.flow.InvokeTypeFlow; import com.oracle.graal.pointsto.meta.AnalysisMethod; +import com.oracle.graal.pointsto.util.AnalysisError; import jdk.vm.ci.code.BytecodePosition; import jdk.vm.ci.meta.JavaKind; import jdk.vm.ci.meta.ResolvedJavaMethod; @@ -75,16 +76,24 @@ public static void print(BigBang bb, String reportsPath, String reportName) { CallTreePrinter printer = new CallTreePrinter(bb); printer.buildCallTree(); - ReportUtils.report("call tree", reportsPath, "call_tree_" + reportName, "txt", - printer::printMethods); + AnalysisReportsOptions.CallTreeType optionValue = AnalysisReportsOptions.PrintAnalysisCallTreeType.getValue(bb.getOptions()); + switch (optionValue) { + case TXT: + ReportUtils.report("call tree", reportsPath, "call_tree_" + reportName, "txt", + printer::printMethods); + break; + case CSV: + printCsvFiles(printer.methodToNode, reportsPath, reportName); + break; + default: + throw AnalysisError.shouldNotReachHere("Unsupported CallTreeType " + optionValue + " used with PrintAnalysisCallTreeType option"); + } ReportUtils.report("list of used methods", reportsPath, "used_methods_" + reportName, "txt", printer::printUsedMethods); ReportUtils.report("list of used classes", reportsPath, "used_classes_" + reportName, "txt", writer -> printer.printClasses(writer, false)); ReportUtils.report("list of used packages", reportsPath, "used_packages_" + reportName, "txt", writer -> printer.printClasses(writer, true)); - - printCsvFiles(printer.methodToNode, reportsPath, reportName); } interface Node {