静心学习 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条回答

    报告相同问题?

    悬赏问题

    • ¥100 求数学坐标画圆以及直线的算法
    • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
    • ¥15 名为“Product”的列已属于此 DataTable
    • ¥15 安卓adb backup备份应用数据失败
    • ¥15 eclipse运行项目时遇到的问题
    • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
    • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
    • ¥15 自己瞎改改,结果现在又运行不了了
    • ¥15 链式存储应该如何解决
    • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站