Now released under GPL
#include <stdlib.h>
class A {
public:
void a();
void b();
void c();
};
void A::a(){b();}
void A::b(){}
void A::c(){}
int main()
{A t;
t.a();
t.c();
exit(0);}
|
![]() |
|
|
|
See also a larger (52K) example. |
Call graph drawing utilities can be found in various commercial CASE tools and programming environments. But if you work without any CASE tools, and use just traditional compilers, you can find a simple and cheap solution here.
This tool produces call graph profile of your program. First you compile and execute the program, and then a detailed text file is produced.
There are two ways you can get it:
See how to use it .
There are, probably some bugs in it.
The GNU gprof is also free available on the net as part of
binutils
package. If you have not this software you can
download it from ftp://ftp.isy.liu.se/pub/gnu/binutils-2.7.tar.gz
or ftp://prep.ai.mit.edu/pub/gnu/binutils-2.7.tar.gz
or from other mirror
sites .
See how to use it .
There are, probably, some bugs in it too.
Let me know if there are other gprof implementations available.
Sometimes additional library should be added by flag -ldl.
When your program runs it always produces the file gmon.out.
You start gprof -C program-name gmon.out if you want to display all calls that were executed at least once.
You start gprof -C -c -z program-name gmon.out if you want to display all the calls in the code. Due to bugs I haven't checked it yet.
You start gprof program-name gmon.out if you want to display all calls that were executed at least once.
You start gprof -c -z program-name gmon.out if you want to display all the calls in the code. Due to bugs I haven't checked it yet.
gprof a.out gmon.out | g2v > test.pair
The format of test.pair is:
calling-index called-index calling-index called-index ... 0000 0000 index function-name index function-name ... |
The format of test.exc is:
index function-name index function-name ... |
You also may want to skip all library functions and all member functions of stream classes. Then do like this:
egrep ' _|filebuf|stream|unsafe|mutex|ios' test.pair | egrep -v '[0-9]$' > test.exc
vco test.pair test.exc -i > test.vcg - the same,
but function without incoming and outcoming calls are skipped.
The format of test.vcg is:
graph: {
orientation: left_to_right
node: { title: "index" label: "function-name" borderwidth:0}
node: { title: "index" label: "function-name" borderwidth:0}
....
edge: { sourcename: "index-from" targetname: "index-to" thickness: 1}
edge: { sourcename: "index-from" targetname: "index-to" thickness: 1}
...
}
|
You can modify the layout algorithm options in many different ways,
as well as save and export the diagram in one or several pages in the PostScript
format.
The programs didn't quite work for HP-UX, so I made some changes
and managed to get a working version. I thought you might be
interested, so here are the changes:
vco.cc,line 135
while(exc) ->
while(!exc.eof())
g2v.cc, line 59
add '|| s[0]==12'
In addition, compilation should be done with '-G -g', instead of
the
'-pg -g' for Sun and Gnu.
I hope this information is of interest to you.
Richard Schaaf - Richard.Schaaf@vrijuit.nl
I have no time to support it anymore. The tool is under GPL - Gnu Public License now.
If interested please mail to
.
Send me questions, bug reports etc by e-mail
.
Page created: 16 Aug 1996
Last change: 26 May 2003