【发布时间】:2011-05-17 15:02:26
【问题描述】:
我有这个程序需要 2.34 秒才能运行,而 gprof 说它只需要 1.18 秒。我在其他地方读过的答案表明,如果程序是 I/O 绑定的,gprof 可能会出错,但这个程序显然不是。
这也发生在我尝试分析的有用程序上。它并不特定于这个琐碎的测试用例。
(同样在这种情况下,gprof 表示 main() 占用了程序运行时间的 100% 以上,这是一个非常愚蠢的错误,但对我来说并没有真正引起问题。)
$ cat test.c
int main() {
int i;
for (i=0;i<1000000000;i++);
}
$ gcc test.c -o test
$ time ./test
real 0m2.342s
user 0m2.340s
sys 0m0.000s
$ gcc test.c -o test -pg
$ time ./test
real 0m2.342s
user 0m2.340s
sys 0m0.000s
$ gprof test |head
Flat profile:
Each sample counts as 0.01 seconds.
% cumulative self self total
time seconds seconds calls Ts/call Ts/call name
101.33 1.18 1.18 main
% the percentage of the total running time of the
time program used by this function.
【问题讨论】:
-
我无法重现这一点。您的操作系统、GCC 和 gprof 版本是什么?您是否安装了启用分析的 libc 版本?
-
Ubuntu 9.10(在双核 x86_64 上)、gcc 4.4.1、gprof 2.20。我不知道我是否安装了 profiling libc 版本。
-
我做了更多调查。分析依赖于每次 SIGPROF 交付时的采样。 gprof 希望每 10 毫秒发送一次 SIGPROF。看起来 SIGPROF 没有以正确的频率发送。如果我将计时器设置为 x ms,其中 10