小智 16
编译时是否指定了-pg?
http://sourceware.org/binutils/docs-2.20/gprof/Compiling.html#Compiling
编译完成后,运行该程序,然后在二进制文件上运行gprof.
例如:
test.c的:
#include <stdio.h>
int main ()
{
int i;
for (i = 0; i < 10000; i++) {
printf ("%d\n", i);
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
编译为cc -pg test.c,然后运行a.out,然后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]
你得到了什么?