gprof在特定代码行上花费的时间

编程入门 行业动态 更新时间:2024-10-08 20:36:25
本文介绍了gprof在特定代码行上花费的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我一直将gprof探查器与g++结合使用.

I've been using the gprof profiler in conjunction with g++.

我的代码中有一个函数,其中封装了行为的几个部分,这些部分与主要函数有足够的联系,以至于没有必要将它们拆分为各自的函数.

I have a function in my code which encapsulates several sections of behaviour which are related enough to the primary function that it would not make sense to split them off into their own functions.

我想知道在这些代码的每个区域中花费了多少时间.

I'd like to know how much time is spent in each of these areas of code.

所以,如果您认为代码看起来像

So, if you imagine the code looks like

function(){ A A A B B B C C C }

其中A,B和C代表我感兴趣的代码的特定部分,有没有办法让gprof告诉我在这些特定部分上花费了多少时间?

where A, B, and C represent particular sections of code I'm interested in, is there a way to get gprof to tell me how much time is spent working on those particular sections?

推荐答案

我知道这是一个老问题,但是我找到了一个有趣的答案. 正如Sam所说,-l选项仅适用于旧的gcc编译器.但是我发现,如果您编译并链接-pg -fprofile-arcs -ftest-coverage并运行该程序,则gprof -l的结果将非常有趣.

I know it's a old question, but I have found a interesting answer. As Sam say, the -l option is only for old gcc compiler. But I have found that if you compile and link with -pg -fprofile-arcs -ftest-coverage, run the program, the result of gprof -l is very interesting.

Flat profile: Each sample counts as 0.01 seconds. % cumulative self self total time seconds seconds calls Ts/call Ts/call name 13.86 0.26 0.26 main (ComAnalyste.c:450 @ 804b315) 10.87 0.46 0.20 main (ComAnalyste.c:386 @ 804b151) 7.07 0.59 0.13 main (ComAnalyste.c:437 @ 804b211) 6.25 0.70 0.12 main (ComAnalyste.c:436 @ 804b425) 4.89 0.79 0.09 main (ComAnalyste.c:283 @ 804a3f4) 4.89 0.88 0.09 main (ComAnalyste.c:436 @ 804b1e9) 4.08 0.96 0.08 main (ComAnalyste.c:388 @ 804ad95) 3.81 1.03 0.07 main (ComAnalyste.c:293 @ 804a510) 3.53 1.09 0.07 main (ComAnalyste.c:401 @ 804af04) 3.26 1.15 0.06 main (ComAnalyste.c:293 @ 804a4bf) 2.72 1.20 0.05 main (ComAnalyste.c:278 @ 804a48d) 2.72 1.25 0.05 main (ComAnalyste.c:389 @ 804adae) 2.72 1.30 0.05 main (ComAnalyste.c:406 @ 804aecb) 2.45 1.35 0.05 main (ComAnalyste.c:386 @ 804ad6d) 2.45 1.39 0.05 main (ComAnalyste.c:443 @ 804b248) 2.45 1.44 0.05 main (ComAnalyste.c:446 @ 804b2f4) 2.17 1.48 0.04 main (ComAnalyste.c:294 @ 804a4e4) 2.17 1.52 0.04 main (ComAnalyste.c:459 @ 804b43b) 1.63 1.55 0.03 main (ComAnalyste.c:442 @ 804b22d) 1.63 1.58 0.03 main (ComAnalyste.c:304 @ 804a56d) 1.09 1.60 0.02 main (ComAnalyste.c:278 @ 804a3b3) 1.09 1.62 0.02 main (ComAnalyste.c:285 @ 804a450) 1.09 1.64 0.02 main (ComAnalyste.c:286 @ 804a470) 1.09 1.66 0.02 main (ComAnalyste.c:302 @ 804acdf) 0.82 1.67 0.02 main (ComAnalyste.c:435 @ 804b1d2) 0.54 1.68 0.01 main (ComAnalyste.c:282 @ 804a3db) 0.54 1.69 0.01 main (ComAnalyste.c:302 @ 804a545) 0.54 1.70 0.01 main (ComAnalyste.c:307 @ 804a586) 0.54 1.71 0.01 main (ComAnalyste.c:367 @ 804ac1a) 0.54 1.72 0.01 main (ComAnalyste.c:395 @ 804ade6) 0.54 1.73 0.01 main (ComAnalyste.c:411 @ 804aff8) 0.54 1.74 0.01 main (ComAnalyste.c:425 @ 804b12a) 0.54 1.75 0.01 main (ComAnalyste.c:429 @ 804b19f) 0.54 1.76 0.01 main (ComAnalyste.c:444 @ 804b26f) 0.54 1.77 0.01 main (ComAnalyste.c:464 @ 804b4a1) 0.54 1.78 0.01 main (ComAnalyste.c:469 @ 804b570) 0.54 1.79 0.01 main (ComAnalyste.c:472 @ 804b5b9) 0.27 1.80 0.01 main (ComAnalyste.c:308 @ 804a5a3) 0.27 1.80 0.01 main (ComAnalyste.c:309 @ 804a5a9) 0.27 1.81 0.01 main (ComAnalyste.c:349 @ 804a974) 0.27 1.81 0.01 main (ComAnalyste.c:350 @ 804a99c) 0.27 1.82 0.01 main (ComAnalyste.c:402 @ 804af1d) 0.27 1.82 0.01 main (ComAnalyste.c:416 @ 804b073) 0.27 1.83 0.01 main (ComAnalyste.c:417 @ 804b0a1) 0.27 1.83 0.01 main (ComAnalyste.c:454 @ 804b3ec) 0.27 1.84 0.01 main (ComAnalyste.c:461 @ 804b44a) 0.27 1.84 0.01 main (ComAnalyste.c:462 @ 804b458)

这是指每行花费的时间.这是非常有趣的结果. 我不知道它的准确性或有效性,但这很有趣. 希望对您有帮助

It's say the time spent per line. It's very interesting result. I don't know the accuracy or the validity of that, but it's quite interesting. Hope it's help

更多推荐

gprof在特定代码行上花费的时间

本文发布于:2023-11-23 06:44:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1620483.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:代码   时间   在特定   gprof

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!