Chinaunix
标题:
为何gprof分析不了某些函数执行的信息?
[打印本页]
作者:
prc
时间:
2006-07-11 14:49
标题:
为何gprof分析不了某些函数执行的信息?
#include <stdlib.h>
#define ABS(a) ((a)>=0?(a):(-a))
static volatile int array[256];
static volatile int y1, y2;
void ff1()
{
int i, j;
for(i=0; i<1000; i++)
for(j=0; j<256; j++)
y1 += abs(array[j]);
}
void ff2()
{
int i, j;
for(i=0; i<1000; i++)
for(j=0; j<256; j++)
y2 += ABS(array[j]);
}
int main()
{
int i;
srand(time(NULL));
for(i=0; i<256; i++)
array[i] = rand();
ff1();
ff2();
printf("y1=%d, y2=%d\n", y1, y2);
return 0;
}
复制代码
编译: gcc -pg -g -O3 aa.c
运行: a.exe
分析: gprof -b aa.exe
输出为:
Flat profile:
Each sample counts as 0.01 seconds.
% cumulative self self total
time seconds seconds calls Ts/call Ts/call name
100.00 0.01 0.01 main
Call graph
granularity: each sample hit covers 4 byte(s) for 100.00% of 0.01 seconds
index % time self children called name
<spontaneous>
[1] 100.0 0.01 0.00 main [1]
-----------------------------------------------
Index by function name
[1] main
复制代码
看不到函数ff1, ff2的信息。如果用-O2编译之后运行再用gprof分析是可以看到ff1, ff2的信息的。
请问对-O3有没有解决的办法呢?
作者:
800long
时间:
2006-07-11 18:22
经过调试查看,好象是使用O3后,程序运行根本没有将它的运行的时间信息写入gmon.out中。
作者:
liubinbj
时间:
2006-07-11 19:30
还是别用O3吧?
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2