1 下载
http://code.google.com/p/jrfonseca/wiki/Gprof2Dot
http://jrfonseca.googlecode.com/svn/trunk/gprof2dot/gprof2dot.py 下载gprof2dot.py
http://www.graphviz.org/Download_source.php下载源代码graphviz-2.18.tar.gz
2 环境
[admin@b2bsearch80 bin]$ python -V
Python2.3.4
[admin@b2bsearch80 bin]$ gcc -v
Reading specs from /usr/lib/gcc/i386-redhat-linux/3.4.6/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-java-awt=gtk --host=i386-redhat-linux
Thread model: posix
gcc version 3.4.6 20060404 (Red Hat3.4.6-3)
[admin@b2bsearch80 bin]$ uname -a
Linux b2bsearch802.6.9-42.ELsmp #1 SMP Wed Jul 12 23:27:17 EDT 2006 i686 i686 i386 GNU/Linux
3 安装
Chmod 744 gprof2dot.py
Tar -zxvf graphviz-2.18.tar.gz
./configure
make
su -
make install
4 编译代码
gcc -pg -g -o uniqueCoreDump uniqueCoreDump.c
5 执行代码生成gmon.out
执行命令产生gmon.out文件
./uniqueCoreDump
ll gmon.out
如果gprof ./uniqueCoreDump有:
gmon.out file is missing call-graph data
则表示没有正确的编译选项或者只有一个main函数
6 生成图片
gprof ./uniqueCoreDump | ./gprof2dot.py -n0 -e0 | dot -Tpng -o output.png
sz output.png