静心学习 2013-08-21 13:35
浏览 1058

gprof得到的结果中%time中的数值有问题

最近在学习使用gprof这个程序性能分析工具,网上有不少资料,但是自己在使用的过程中碰到了问题,问题描述如下。
操作系统centos 5.5

所使用的测试程序是bubble.c,源代码如下:
#include
#define NUM 10000
void bubble(int *a, int len) {

int i, j, t;
for(i = len - 1; i>0; i--) {
for(j = 0; j < i; j++)
if(a[j+1] < a[j]) {
t = a[j];
a[j] = a[j+1];
a[j+1] = t;
}
}
}
void print(int *a, int len) {
int i;
for(i = 0; i < len; i++)
printf("%d ", a[i]);
printf("\n");
}
int main() {
int a[NUM];
int i;
for(i=0;i<NUM;i++)
a[i]=rand()%(NUM*100);
bubble(a, sizeof(a)/sizeof(int));
print(a, sizeof(a)/sizeof(int));
return 0;
}

使用gprof过程如下:
gcc -o bubble bubble.c -pg
./bubble
gprof bubble gmon.out -b >result
打开result文件,得到的信息如下:

Flat profile:

Each sample counts as 0.01 seconds.
% cumulative self self total

time seconds seconds calls ms/call ms/call name

100.41 0.67 0.67 1 672.73 672.73 bubble
0.00 0.67 0.00 1 0.00 0.00 print

Call graph

granularity: each sample hit covers 2 byte(s) for 1.49% of 0.67 seconds

index % time self children called name
0.67 0.00 1/1 main [2]

[1] 100.0 0.67 0.00 1 bubble [1]

                                             <spontaneous>

[2] 100.0 0.00 0.67 main [2]
0.67 0.00 1/1 bubble [1]

0.00 0.00 1/1 print [3]

            0.00    0.00       1/1           main [2]

[3] 0.0 0.00 0.00 1 print [3]

Index by function name

[1] bubble [3] print

注意上面flat profile中的%time字段下,对应的bubble函数那一行中的数字是100.41。本来%time这个字段下的数值是表示当前函数所消耗的时间占整个程序执行时间的百分比,是小于等于100的,但是这里竟然比100还大,不知道是怎么回事,请大家多指教。

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
    • ¥15 MCNP里如何定义多个源?
    • ¥20 双层网络上信息-疾病传播
    • ¥50 paddlepaddle pinn
    • ¥20 idea运行测试代码报错问题
    • ¥15 网络监控:网络故障告警通知
    • ¥15 django项目运行报编码错误
    • ¥15 请问这个是什么意思?
    • ¥15 STM32驱动继电器
    • ¥15 Windows server update services