本篇日志为原创,当然方法参考了各种网络上的文章
方法
(1)在Qt程序的pro文件中加入如下三行
QMAKE_CFLAGS+=-pg
QMAKE_CXXFLAGS += -pg
QMAKE_LFLAGS += -pg
(2)点Qt左下角的小锤子,编译,然后运行
(3)运行后,在程序目录会生成gmon.out文件,使用命令
$gprof -b -A -p -q t gmon.out>pg
来解析这个文件到pg文件
其中,t是应用程序文件名
上述命令可以用不带参数的形式,为
$gprof t gmon.out>pg
(4)pg文件的说明
Flat profile:
Each sample counts as 0.01 seconds.
% cumulative self self total
time seconds seconds calls s/call s/call name
100.81 2.36 2.36 1 2.36 2.36 CMisaka::circulation(int)
0.00 2.36 0.00 1 0.00 0.00 _GLOBAL__sub_I__ZN7CMisaka11circulationEi
0.00 2.36 0.00 1 0.00 0.00 __static_initialization_and_destruction_0(int, int)
0.00 2.36 0.00 1 0.00 0.00 CMisaka::get_age()
0.00 2.36 0.00 1 0.00 0.00 CMisaka::set_age(int)
0.00 2.36 0.00 1 0.00 0.00 CMisaka::get_bango()
0.00 2.36 0.00 1 0.00 0.00 CMisaka::set_bango(int)
其中
参考文章:
http://blog.sina.com.cn/s/blog_6608391701013phr.html
http://blog.chinaunix.net/uid-9950859-id-99112.html 代码分析工具--gcov, gprof
http://richelbilderbeek.nl/CppQtGprofExample1.htm Qt Creator gprof example 1: profiling a simple console application
http://hi.baidu.com/good_dream/item/a41769133bec56eb9813d6db QT + Gprof 程序性能分析
http://www.myvoipapp.com/blogs/yxh/2012/02/24/qt%E7%A8%8B%E5%BA%8F%E4%B8%8Egprof/ QT程序与gprof