3

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

Anirudh Sharma
  • 115
  • 3
  • 14
ict1991
  • 1,900
  • 4
  • 24
  • 31

4 Answers4

3

This is as good an API as I've seen:

https://github.com/gousiosg/java-callgraph

Sridhar Sarnobat
  • 19,595
  • 12
  • 74
  • 93
3

I have been looking into what static analysis libraries are available for Java recently. Here are some of them that I have come across:

  • Chord: seems to be a robust framework that is still being maintained/updated. Here is a link to some of the documentation on their predefined analysis (includes Call Graph stuff).
  • DepFinder: this tool is used for generating a dependency graph from a project, I imagine you could extract static call graph information from it.
Klerisson
  • 292
  • 1
  • 2
  • 16
jbranchaud
  • 5,439
  • 8
  • 42
  • 69
0

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.

rrevo
  • 1,367
  • 1
  • 12
  • 21
0

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);
     }
}
Heiko Rupp
  • 28,212
  • 13
  • 79
  • 118
  • 2
    i will not be able to modify the code in the system that I am going to analyze. I need to use the call graph as part of a tool that i'm developing and will be used to analyze the code in a given project. so the code has to be left as is – ict1991 Feb 15 '12 at 09:59
  • Even though the strategy is limited to your source code like you said, anyone else reading this should make a note of this suggestion. It's the best solution I've seen so far. – Sridhar Sarnobat Sep 04 '13 at 19:03