Skip to content

Commit

Permalink
Add call tree csv links for easier imports into graph db
Browse files Browse the repository at this point in the history
  • Loading branch information
galderz authored and zakkak committed Oct 18, 2021
1 parent 322f6e7 commit 8483d4b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@
import static com.oracle.graal.pointsto.reports.ReportUtils.invokeComparator;
import static com.oracle.graal.pointsto.reports.ReportUtils.methodComparator;

import java.io.IOException;
import java.io.PrintWriter;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -46,6 +51,7 @@
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -333,26 +339,33 @@ private static void printCsvFiles(Map<AnalysisMethod, MethodNode> methodToNode,
walkNodes(node, directEdges, virtualEdges, overridenByEdges, virtualNodes, nonVirtualNodes, virtualNodeId);
}

ReportUtils.report("call tree for vm entry point", reportsPath, "csv_call_tree_vm_" + reportName, "csv",
CallTreePrinter::printVMEntryPoint);

ReportUtils.report("call tree for methods", reportsPath, "csv_call_tree_methods_" + reportName, "csv",
writer -> printMethodNodes(methodToNode.values(), writer));

ReportUtils.report("call tree for virtual methods", reportsPath, "csv_call_tree_virtual_methods_" + reportName, "csv",
writer -> printVirtualNodes(virtualNodes, writer));

ReportUtils.report("call tree for entry points", reportsPath, "csv_call_tree_entry_points_" + reportName, "csv",
writer -> printEntryPointIds(entryPointIds, writer));

ReportUtils.report("call tree for direct edges", reportsPath, "csv_call_tree_direct_edges_" + reportName, "csv",
writer -> printBciEdges(directEdges, writer));

ReportUtils.report("call tree for overriden by edges", reportsPath, "csv_call_tree_override_by_edges_" + reportName, "csv",
writer -> printNonBciEdges(overridenByEdges, writer));
toCsvFile("call tree for vm entry point", reportsPath, "csv_call_tree_vm", reportName, CallTreePrinter::printVMEntryPoint);
toCsvFile("call tree for methods", reportsPath, "csv_call_tree_methods", reportName, writer -> printMethodNodes(methodToNode.values(), writer));
toCsvFile("call tree for virtual methods", reportsPath, "csv_call_tree_virtual_methods", reportName, writer -> printVirtualNodes(virtualNodes, writer));
toCsvFile("call tree for entry points", reportsPath, "csv_call_tree_entry_points", reportName, writer -> printEntryPointIds(entryPointIds, writer));
toCsvFile("call tree for direct edges", reportsPath, "csv_call_tree_direct_edges", reportName, writer -> printBciEdges(directEdges, writer));
toCsvFile("call tree for overriden by edges", reportsPath, "csv_call_tree_override_by_edges", reportName, writer -> printNonBciEdges(overridenByEdges, writer));
toCsvFile("call tree for virtual edges", reportsPath, "csv_call_tree_virtual_edges", reportName, writer -> printBciEdges(virtualEdges, writer));
}

private static void toCsvFile(String description, String reportsPath, String prefix, String reportName, Consumer<PrintWriter> reporter) {
final String name = prefix + "_" + reportName;
final String csvFile = ReportUtils.report(description, reportsPath, name, "csv", reporter);
final Path csvLink = Paths.get(reportsPath).resolve(prefix + ".csv");

if (Files.exists(csvLink, LinkOption.NOFOLLOW_LINKS)) {
try {
Files.delete(csvLink);
} catch (IOException e) {
// Ignore
}
}

ReportUtils.report("call tree for virtual edges", reportsPath, "csv_call_tree_virtual_edges_" + reportName, "csv",
writer -> printBciEdges(virtualEdges, writer));
try {
Files.createSymbolicLink(csvLink, Paths.get(csvFile));
} catch (IOException e) {
throw new RuntimeException(e);
}
}

private static void printVMEntryPoint(PrintWriter writer) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,11 @@ public class ReportUtils {
* @param extension the extension of the report
* @param reporter a consumer that writes to a PrintWriter
*/
public static void report(String description, String path, String name, String extension, Consumer<PrintWriter> reporter) {
public static String report(String description, String path, String name, String extension, Consumer<PrintWriter> reporter) {
String fileName = timeStampedFileName(name, extension);
Path reportDir = Paths.get(path);
reportImpl(description, reportDir, fileName, reporter);
return fileName;
}

public static String timeStampedFileName(String name, String extension) {
Expand Down

0 comments on commit 8483d4b

Please sign in to comment.