linux timing profile

本文介绍了一个用于测量C++程序运行时间的方法,并利用gprof工具进行性能分析。文中提供了一段示例代码来获取程序运行的时间,并展示了如何通过gprof获取每个函数的执行时间、调用关系及调用次数。
double getUnixTime(void)
{
    struct timespec tv;

    if(clock_gettime(CLOCK_REALTIME, &tv) != 0) return 0;

    return (((double) tv.tv_sec) + (double) (tv.tv_nsec / 1000000000.0));
}

double start_time = getUnixTime();
double stop_time, difference;

algorithm();

stop_time = getUnixTime();
difference = stop_time - start_time;
printf("elipsed time :%lf\ns",difference);

g++ t.c++ -lrt

 

 

gprof 

gprof -b -p astart gmon.out >&tmp.txt

 

   @ gprof hello gmon.out -p 得到每个函数占用的执行时间
       @ gprof hello gmon.out -q 得到call graph,包含了每个函数的调用关系,调用次数,执行时间等信息。
       @ gprof hello gmon.out -A 得到一个带注释的“源代码清单”,它会注释源码,指出每个函数的执行次数。这需要在编译的时候增加 -g选项。

 

http://www.thegeekstuff.com/2012/08/gprof-tutorial/

转载于:https://www.cnblogs.com/huashiyiqike/p/3879127.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值