这个技巧从开发那里学来的。
这帮GG寻找好东西的能力一流 :)
1 下载
http://code.google.com/p/jrfonseca/wiki/Gprof2Dot
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 安装
Chmod744 gprof2dot.py
./configure
make
su-
make install
4编译代码
gcc -pg-g-ouniqueCoreDumpuniqueCoreDump.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