Skip to content

Commit 8483d4b

Browse files
galderzzakkak
authored andcommitted
Add call tree csv links for easier imports into graph db
1 parent 322f6e7 commit 8483d4b

File tree

2 files changed

+34
-20
lines changed

2 files changed

+34
-20
lines changed

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/reports/CallTreePrinter.java

+32-19
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@
3131
import static com.oracle.graal.pointsto.reports.ReportUtils.invokeComparator;
3232
import static com.oracle.graal.pointsto.reports.ReportUtils.methodComparator;
3333

34+
import java.io.IOException;
3435
import java.io.PrintWriter;
36+
import java.nio.file.Files;
37+
import java.nio.file.LinkOption;
38+
import java.nio.file.Path;
39+
import java.nio.file.Paths;
3540
import java.util.ArrayDeque;
3641
import java.util.ArrayList;
3742
import java.util.Arrays;
@@ -46,6 +51,7 @@
4651
import java.util.Objects;
4752
import java.util.Set;
4853
import java.util.concurrent.atomic.AtomicInteger;
54+
import java.util.function.Consumer;
4955
import java.util.regex.Matcher;
5056
import java.util.regex.Pattern;
5157
import java.util.stream.Collectors;
@@ -333,26 +339,33 @@ private static void printCsvFiles(Map<AnalysisMethod, MethodNode> methodToNode,
333339
walkNodes(node, directEdges, virtualEdges, overridenByEdges, virtualNodes, nonVirtualNodes, virtualNodeId);
334340
}
335341

336-
ReportUtils.report("call tree for vm entry point", reportsPath, "csv_call_tree_vm_" + reportName, "csv",
337-
CallTreePrinter::printVMEntryPoint);
338-
339-
ReportUtils.report("call tree for methods", reportsPath, "csv_call_tree_methods_" + reportName, "csv",
340-
writer -> printMethodNodes(methodToNode.values(), writer));
341-
342-
ReportUtils.report("call tree for virtual methods", reportsPath, "csv_call_tree_virtual_methods_" + reportName, "csv",
343-
writer -> printVirtualNodes(virtualNodes, writer));
344-
345-
ReportUtils.report("call tree for entry points", reportsPath, "csv_call_tree_entry_points_" + reportName, "csv",
346-
writer -> printEntryPointIds(entryPointIds, writer));
347-
348-
ReportUtils.report("call tree for direct edges", reportsPath, "csv_call_tree_direct_edges_" + reportName, "csv",
349-
writer -> printBciEdges(directEdges, writer));
350-
351-
ReportUtils.report("call tree for overriden by edges", reportsPath, "csv_call_tree_override_by_edges_" + reportName, "csv",
352-
writer -> printNonBciEdges(overridenByEdges, writer));
342+
toCsvFile("call tree for vm entry point", reportsPath, "csv_call_tree_vm", reportName, CallTreePrinter::printVMEntryPoint);
343+
toCsvFile("call tree for methods", reportsPath, "csv_call_tree_methods", reportName, writer -> printMethodNodes(methodToNode.values(), writer));
344+
toCsvFile("call tree for virtual methods", reportsPath, "csv_call_tree_virtual_methods", reportName, writer -> printVirtualNodes(virtualNodes, writer));
345+
toCsvFile("call tree for entry points", reportsPath, "csv_call_tree_entry_points", reportName, writer -> printEntryPointIds(entryPointIds, writer));
346+
toCsvFile("call tree for direct edges", reportsPath, "csv_call_tree_direct_edges", reportName, writer -> printBciEdges(directEdges, writer));
347+
toCsvFile("call tree for overriden by edges", reportsPath, "csv_call_tree_override_by_edges", reportName, writer -> printNonBciEdges(overridenByEdges, writer));
348+
toCsvFile("call tree for virtual edges", reportsPath, "csv_call_tree_virtual_edges", reportName, writer -> printBciEdges(virtualEdges, writer));
349+
}
350+
351+
private static void toCsvFile(String description, String reportsPath, String prefix, String reportName, Consumer<PrintWriter> reporter) {
352+
final String name = prefix + "_" + reportName;
353+
final String csvFile = ReportUtils.report(description, reportsPath, name, "csv", reporter);
354+
final Path csvLink = Paths.get(reportsPath).resolve(prefix + ".csv");
355+
356+
if (Files.exists(csvLink, LinkOption.NOFOLLOW_LINKS)) {
357+
try {
358+
Files.delete(csvLink);
359+
} catch (IOException e) {
360+
// Ignore
361+
}
362+
}
353363

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

358371
private static void printVMEntryPoint(PrintWriter writer) {

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/reports/ReportUtils.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,11 @@ public class ReportUtils {
7575
* @param extension the extension of the report
7676
* @param reporter a consumer that writes to a PrintWriter
7777
*/
78-
public static void report(String description, String path, String name, String extension, Consumer<PrintWriter> reporter) {
78+
public static String report(String description, String path, String name, String extension, Consumer<PrintWriter> reporter) {
7979
String fileName = timeStampedFileName(name, extension);
8080
Path reportDir = Paths.get(path);
8181
reportImpl(description, reportDir, fileName, reporter);
82+
return fileName;
8283
}
8384

8485
public static String timeStampedFileName(String name, String extension) {

0 commit comments

Comments
 (0)