Chinaunix

标题: 为何gprof分析不了某些函数执行的信息? [打印本页]

作者: prc    时间: 2006-07-11 14:49
标题: 为何gprof分析不了某些函数执行的信息?
  1. #include <stdlib.h>

  2. #define ABS(a) ((a)>=0?(a):(-a))

  3. static volatile int array[256];
  4. static volatile int y1, y2;

  5. void ff1()
  6. {
  7.         int i, j;
  8.         for(i=0; i<1000; i++)
  9.                 for(j=0; j<256; j++)
  10.                         y1 += abs(array[j]);
  11. }

  12. void ff2()
  13. {
  14.         int i, j;
  15.         for(i=0; i<1000; i++)
  16.                 for(j=0; j<256; j++)
  17.                         y2 += ABS(array[j]);
  18. }

  19. int main()
  20. {
  21.         int i;
  22.         srand(time(NULL));
  23.         for(i=0; i<256; i++)
  24.                 array[i] = rand();
  25.        
  26.         ff1();
  27.         ff2();
  28.        
  29.         printf("y1=%d, y2=%d\n", y1, y2);
  30.        
  31.         return 0;
  32. }
复制代码


编译:  gcc -pg -g -O3 aa.c
运行:  a.exe
分析:  gprof -b aa.exe
输出为:
  1. Flat profile:

  2. Each sample counts as 0.01 seconds.
  3.   %   cumulative   self              self     total           
  4. time   seconds   seconds    calls  Ts/call  Ts/call  name   
  5. 100.00      0.01     0.01                             main

  6.                         Call graph


  7. granularity: each sample hit covers 4 byte(s) for 100.00% of 0.01 seconds

  8. index % time    self  children    called     name
  9.                                                  <spontaneous>
  10. [1]    100.0    0.01    0.00                 main [1]
  11. -----------------------------------------------

  12. Index by function name

  13.    [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