3

Is it possible to generate a global call graph of an application?

Basically I am trying to find the most important class of an application.

I am looking for options for Java.

I have tried Doxy Gen, but it only generates inheritance graphs.

My current script:

#! /bin/bash

echo "digraph G
{"
find $1 -name \*.class |
    sed s/\\.class$// |
    while read x
    do
        javap -v $x | grep " = class" | sed "s%.*// *%\"$x\" -> %" | sed "s/$1\///" | sed "s/-> \(.*\)$/-> \"\1\"/"
    done
echo "}"
4
  • possible duplicate of How to generate a Java call graph Commented Feb 11, 2011 at 21:42
  • "Most important", probably not, but this would probably expose classes with too much functionality, I think. Commented Feb 11, 2011 at 21:43
  • 2
    @Sean, it may be a duplicate question but none of the answers there address it. Commented Feb 11, 2011 at 21:46
  • @Peter I know, and that's the problem with the "duplicate question" on this site. But it is the policy to close dupes. Commented Feb 11, 2011 at 21:49

2 Answers 2

2

javap -v and a bit of perl will get you dependencies between classes. You can make your parser slightly more sophisticated and get dependencies between methods.

Update: or if you have either a *nix or cygwin you can get a list of dependencies as

find com/akshor/pjt33/image -name \*.class |
  sed s/\\.class$// |
    while read x
    do
      javap -v $x | grep " = class" | sed "s%.*// *%$x -> %"
    done

Add a header and a footer and you can pass it to dot to render a graph. If you just want to know which classes are used by the most other classes, as your question implies, then

find com/akshor/pjt33/image -name \*.class |
  sed s/\\.class$// |
    while read x
    do
      javap -v $x | grep " = class" | sed "s%.*// *%%"
    done |
      sort | uniq -c | sort -n
Sign up to request clarification or add additional context in comments.

6 Comments

I am not sure this can help. And I know close to nothing about Perl. I know its a shame.
@Tiago, you can read input and apply regular expression in Java too, it's just rather more verbose.
I'll give this a try. I am guessing that this command will look for files in com/akshor/pjt33/image with the *.classextension, but shouldn't it be *.java? I was under the impression the javap command would read java files and not class files.
Never mind. I am almost done with this, I am tweaking your bash script to my needs.
@Peter: I am getting some weird symbols like [Z and [B. I have added the current version of the script I am building on my question.
|
1

For advanced code analysis you might wanna have a look at http://www.moosetechnology.org/

Cheers
Thomas

(edit: moved down here by general request, See: How to generate a Java call graph)

4 Comments

LOL... you beat me to the punch (+1)
I don't think you understand what the OP is looking for.
I have seen that question, but it does not what I am looking for.
@Tiago and what about Moose? I used this tool to analyse projects at work.

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.