http://www.tinylab.org/callgraph-draw-the-calltree-of-c-functions/
Http://www.cnblogs.com/louxin/archive/2012/01/02/2310488.html
Using CallTree to view function call relationships in engineering code
Today use CallTree This source function Relationship view tool, the results are very intuitive, but the installation process a bit cumbersome, now the installation process is recorded, lest later forget.
When we look at a larger project code, often the relationship between functions is more complex, if you look directly at the source, the function of jumping to jump, the head is jumping dizzy, and finally did not see why, calltree this tool to meet the majority of programmers "consumption" needs, can be clearly printed out the function of the call relationship , if you want to use a graphical tool to see the function call relationship, you have to install a software Graphviz. OK, let's start with the installation process:
Download the source code from the following website: calltree-2.3.tar.bz
Http://citeseer.ist.psu.edu/graham82gprof.html
1. Unzip the installation to the system path
#tar JXVF calltree-2.3.tar.bz
#cd calltree-2.3
#make//No configuration, direct compilation
After compilation, a binary file is generated in the current directory under the CALLTREE/OBJ/I686-LINUX-CC directory: CallTree, which is the file we need, copy it to the/usr/bin directory, or make a soft link.
2. Start using CallTree
Enter the following command into one of my sample code:
#calltree-gb-np-m *.c
It is easy to see the invocation relationship between functions.
Here are the options:
-B is the vertical line, and it shows the indentation level visually.
-G printing internal function of the file name and line number, the external function belongs to the file name and line number is also printable, detailed man
-NP do not call the C preprocessor, so the printed interface will not be cluttered, but may also produce errors oh, if we only look at
function, there is no big problem with the call relationship.
-M tells the program to start with main
Another important option is listfunction, the abbreviation is LF, which is used to print only the calls in a function, using:
#calltree-GB-NP lf=send_query *.c
From this result can be very convenient to see the function call relationship, but still not beautiful, so add-dot parameters, produce a dot graph bar.
However, before using the dot command, you need to install a Graphviz software package, which I installed in cent-os5.5 directly by entering the following command:
#yum Install graphviz*
If your system does not support yum online installation, you can go to the following website to download the corresponding RPM package.
http://www.graphviz.org/
Here is a script I wrote (can be executed separately from each command) test.sh:
#!/bin/sh
/usr/bin/calltree-gb-np-m *.c-dot > Test.dot
/usr/bin/dot-tjpg Test.dot-o calltree.jpg
To run the script:
#sh +x test.sh
CallTree Source code call graph +callgrath Source code function call Graph