对于内核的函数调用关系参见:
http://tree.celinuxforum.org/CelfPubWiki/KernelFunctionTrace
http://www.csn.ul.ie/~mel/projects/codeviz/
[jfo@Fedora4 debug]$ ls
main.c
[jfo@Fedora4 debug]$ cat main.c
///////////////////////////////////////////////////
//main.c
#include <stdio.h>
#include <stdlib.h>
void f1(int);
void f12(int i)
{
printf("f12(%d)n", i);
if(i>0)
f1(i-1);
}
void f13()
{
printf("f13()n");
}
void f1(int i)
{
printf("f1(%d)n", i);
f12(i);
f13();
}
void f2(int i)
{
printf("f2(%d)n", i);
if(i>0)
f2(i-1);
}
int main()
{
f1(4);
f2(3);
return 0;
}
///////////////////////////////////////////////////////
[jfo@Fedora4 debug]$ gcc -pg -g -o main main.c
[jfo@Fedora4 debug]$ ls
main main.c
[jfo@Fedora4 debug]$ ./main
f1(4)
f12(4)
f1(3)
f12(3)
f1(2)
f12(2)
f1(1)
f12(1)
f1(0)
f12(0)
f13()
f13()
f13()
f13()
f13()
f2(3)
f2(2)
f2(1)
f2(0)
[jfo@Fedora4 debug]$ ls
gmon.out main main.c
/
Call Graph Drawing Interface
Call Graph tools can be downloaded here:
http://www.ida.liu.se/%7Evaden/cgdi/
cg.tar.gz contains two usefull tools:
g2v: convert gprof output into a pair file
vco: generate vcg file based on the pair file & exception file
exception file defines functions which is to be removed
from call graph.
The final output vcg file can be used as input to xvcg to
draw call graph.
/
[jfo@Fedora4 debug]$ gprof main gmon.out | g2v
1 3
2 4
2 3
3 2
5 5
0000 0000
1 <cycle 1 as a whole> [1]
2 f1
3 f12
4 f13
5 f2
[jfo@Fedora4 debug]$ gprof main gmon.out | g2v > main.pair
[jfo@Fedora4 debug]$ ls
gmon.out main main.c main.pair
[jfo@Fedora4 debug]$ vco main.pair main.exc -i
graph: {
orientation: left_to_right
node: { title: "2" label: "f1" borderwidth: 0 }
node: { title: "3" label: "f12" borderwidth: 0 }
node: { title: "4" label: "f13" borderwidth: 0 }
node: { title: "5" label: "f2" borderwidth: 0 }
edge: { sourcename: "2" targetname: "4" thickness: 1 }
edge: { sourcename: "2" targetname: "3" thickness: 1 }
edge: { sourcename: "3" targetname: "2" thickness: 1 }
edge: { sourcename: "5" targetname: "5" thickness: 1 }
}
[jfo@Fedora4 debug]$ vco main.pair main.exc -i > main.vcg
[jfo@Fedora4 debug]$ ls
gmon.out main main.c main.exc main.pair main.vcg
/
vcg reference
http://rw4.cs.uni-sb.de/~sander/html/gsvcg1.html
/
[jfo@Fedora4 debug]$ xvcg main.vcg
…
[jfo@Fedora4 debug]$ xvcg -psoutput main.ps main.vcg
Wait…………………..x[jfo@Fedora4 debug]$
[jfo@Fedora4 debug]$ ls
gmon.out main main.c main.exc main.pair main.ps main.vcg
=============================== or ================================
/
mkgraph
We can used the tools from redhat:
http://people.redhat.com/sgrubb/audit/visualize/index.html
mkgraph-redhat.tar.bz2 contains:
mkgraph: take function call pairs to generate .ps using dot,
you can modify this bash script to keep .dot file,
and generate .jpg file directly.
usage: cat pairs | mkgraph file_prefix
output: file_prefix.ps.gz or file_prefix.jpg
function call pairs format:
f1 f2
f1 f3
f2 f3
….
mkinput: modified from vco.cc, output function calls pairs.
input file should be a pair file from g2v
usage: mkinput file.pair file.exp
/
[jfo@Fedora4 debug]$ mkinput main.pair main.exc
f1 f13
f1 f12
f12 f1
f2 f2
[jfo@Fedora4 debug]$ mkinput main.pair main.exc > main.input
[jfo@Fedora4 debug]$ cat main.input | mkgraph
Gzipping graph…
Graph was written to gr.ps.gz
[jfo@Fedora4 debug]$ ls
gmon.out main main.exc main.pair main.vcg
gr.ps.gz main.c main.input main.ps
[jfo@Fedora4 debug]$ cat main.input | mkgraph main.graph
Gzipping graph…
Graph was written to main.graph.ps.gz
[jfo@Fedora4 debug]$ ls
gmon.out main.c main.graph.ps.gz main.pair main.vcg
main main.exc main.input main.ps
=============================== or ================================
/
mkgraph0.sh
see http://hi.baidu.com/j%5Ffo/blog/item/409969636d1bdd630c33fab0.html
The tarball can be downloaded at:
http://www.ioplex.com/~miallen/mkgraph.tar.gz
For Multiprocess Program, see the company manual "mkgraph.html"
/
[jfo@Fedora4 debug]$ mkgraph0.sh main gmon.out
Use of uninitialized value in hash element at /home/jfo/work/mkgraph.sh/dot_from_pl.pl line 46, <STDIN> chunk 1.
[jfo@Fedora4 debug]$ ls
gmon.out gmon.out.ps main.c main.graph.jpg main.input main.ps
gmon.out.dot main main.exc main.graph.ps.gz main.pair main.vcg
[jfo@Fedora4 debug]$
================================== or ==================================
/
__cyg_profile_func_enter、pvtrace、Graphviz
For this method, refer:
http://hi.baidu.com/j%5Ffo/blog/item/e305087b7ab3cff70bd18734.html
/
[jfo@Fedora4 debug]$ dot -Tjpg gmon.out.dot -o main.jpg
Error: Could not find/open font : Times-Roman
[jfo@Fedora4 debug]$ ls
gmon.out main main.graph.jpg main.jpg main.vcg
gmon.out.dot main.c main.graph.ps.gz main.pair
gmon.out.ps main.exc main.input main.ps