Reputation: 2100
I would like to generate a simple call graph in order to be able to analyze the flow of execution in methods in java.
So for example, if in the code I'm able to go from method X to method Y in a number of method calls, then I would like to generate the call graph which shows the flow from method X to method Y.
I tried using SOOT however I did not manage to get this required call graph. Does anyone know of an API which I can use to generate such call graphs? I'm using Eclipse, however I cannot use plugins, as this tool is needed to be used across a number of projects
Thanks a lot for your help
Upvotes: 3
Views: 8151
Reputation: 6087
I have been looking into what static analysis libraries are available for Java recently. Here are some of them that I have come across:
Upvotes: 3
Reputation: 1767
JTracer is a tool for understanding execution flow of Java programs by generating and visualizing call graphs. Various events like method entry and method exit are logged and visualized. No modification of code is required.
Upvotes: 0
Reputation: 25196
This is as good an API as I've seen:
https://github.com/gousiosg/java-callgraph
Upvotes: 3
Reputation: 30934
You could in Y throw an Exception that is caught in X and then analyze the Exceptions stack trace
// in X:
try {
do your calls ...
} catch (Exception e ) {
StackTraceElement[] elements = e.getStackTrace();
for (StackTraceElement e : elements ) {
// ... evaluate / print ...
System.out.println(e);
}
}
Upvotes: 0