当我在我的 C 程序上运行 gprof 时,它说我的程序没有累积时间,并且所有函数调用都显示 0 时间。但是它确实对函数调用进行计数。
如何修改我的程序,以便 gprof 能够计算某项运行所需的时间?
编译的时候有没有指定-pg?
http://sourceware.org/binutils/docs-2.20/gprof/Compiling.html#Compiling http://sourceware.org/binutils/docs-2.20/gprof/Compiling.html#Compiling
编译完成后,运行该程序,然后对二进制文件运行 gprof。
E.g.:
test.c:
#include <stdio.h>
int main ()
{
int i;
for (i = 0; i < 10000; i++) {
printf ("%d\n", i);
}
return 0;
}
编译为cc -pg test.c
,然后运行为a.out
, then gprof a.out
, 给我
granularity: each sample hit covers 4 byte(s) for 1.47% of 0.03 seconds
% cumulative self self total
time seconds seconds calls ms/call ms/call name
45.6 0.02 0.02 10000 0.00 0.00 __sys_write [10]
45.6 0.03 0.02 0 100.00% .mcount (26)
2.9 0.03 0.00 20000 0.00 0.00 __sfvwrite [6]
1.5 0.03 0.00 20000 0.00 0.00 memchr [11]
1.5 0.03 0.00 10000 0.00 0.00 __ultoa [12]
1.5 0.03 0.00 10000 0.00 0.00 _swrite [9]
1.5 0.03 0.00 10000 0.00 0.00 vfprintf [2]
你得到什么?
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)