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

1
  • Hi, Did you manage to find a solution for this? Commented Jun 24, 2014 at 22:46

4 Answers 4

3

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

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

Sign up to request clarification or add additional context in comments.

Comments

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.

1 Comment

Chord seems dead now. All outgoing links 404s
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);
     }
}

2 Comments

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
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.
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.