linux 内核函数调用次数,Linux 显示每个函数调用的耗时,调用次数,调用关系

[root@shanghai c++11]# cat test3.c

#include

int a(void) {

int i=0,g=0;

while(i++<200000)

{

g^=i;

}

return g;

}

int b(void) {

int i=0,g=0;

while(i++<800000)

{

g^=i;

}

return g;

}

int main(int argc, char** argv)

{

int iterations;

if(argc != 2)

{

printf("Usage %s \n", argv[0]);

return -1;

}

else

iterations = atoi(argv[1]);

printf("你键入的数是 = %d\n", iterations);

while(iterations--)

{

a();

b();

}

}

[root@shanghai c++11]#

[root@shanghai c++11]# gcc -g -pg test3.c && ./a.out 9999

你键入的数是 = 9999

[root@shanghai c++11]#

[root@shanghai c++11]# ll

total 64

-rwxr-xr-x 1 root root 10176 Mar 22 16:33 a.out

-rw-r--r-- 1 root root 471 Mar 22 16:34 gmon.out

-rw-r--r-- 1 root root 537 Mar 22 16:33 test3.c

[root@shanghai c++11]#

[root@shanghai c++11]# gprof a.out gmon.out > log

Each sample counts as 0.01 seconds.

% cumulative self self total

time seconds seconds calls ms/call ms/call name

81.22 21.19 21.19 9999 2.12 2.12 b

19.88 26.38 5.19 9999 0.52 0.52 a

index % time self children called name

[1] 100.0 0.00 26.38 main [1]

21.19 0.00 9999/9999 b [2]

5.19 0.00 9999/9999 a [3]

-----------------------------------------------

21.19 0.00 9999/9999 main [1]

[2] 80.3 21.19 0.00 9999 b [2]

-----------------------------------------------

5.19 0.00 9999/9999 main [1]

[3] 19.7 5.19 0.00 9999 a [3]

-----------------------------------------------

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值