在 Linux 中分析部分程序
我有一个程序,其中花费了大量时间加载和保存数据。现在我想知道每个函数花费的时间占总运行时间的百分比。但是,我想从探查器考虑的总时间中排除加载和保存函数所花费的时间。有没有办法使用 gprof 或任何其他流行的分析器来做到这一点?
I have a program in which significant amount of time is spent loading and saving data. Now I want to know how much time each function is taking in terms of percentage of the total running time. However, I want to exclude the time taken by loading and saving functions from the total time considered by the profiler. Is there any way to do so using gprof or any other popular profiler?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
同样,您可以使用
其他选项来查看:
要获取指令级统计信息:
或者您可以即时“远程控制”它:
callgrind_control
或注释您的源代码(IIRC 还具有分支预测统计信息):callgrind_annotate
。优秀的工具
kcachegrind
是一个奇妙可视化/导航工具。我强烈推荐它:Similarly you can use
Other options to look at:
To get instructionlevel stats:
Alternatively you can 'remote control' it on the fly:
callgrind_control
or annotate your source code (IIRC also with branch predictions stats):callgrind_annotate
.The excellent tool
kcachegrind
is a marvellous visualization/navigation tool. I can hardly recommend it enough:我会考虑使用比 gprof 更现代的东西,例如 OProfile。使用
opreport
生成报告时,您可以使用--exclude-symbols
选项来排除您不感兴趣的函数。请参阅OProfile 网页 了解更多详情;不过,要获得快速入门指南,请参阅 OProfile 文档 页面。
I would consider using something more modern than
gprof
, such asOProfile
. When generating a report usingopreport
you can use the--exclude-symbols
option to exclude functions you are not interested in.See the OProfile webpage for more details; however for a quick start guide see the OProfile docs page.
RotateRight 的 Zoom 为 Linux 提供了系统范围的时间配置文件。如果您的代码在 I/O 上花费大量时间,那么该时间将不会显示在 CPU 的时间配置文件中。或者,如果您想考虑 I/O 所花费的时间,请尝试“线程时间配置文件”。
Zoom from RotateRight offers a system-wide time profile for Linux. If your code spends a lot of time in i/o, then that time won't show up in a time profile of the CPUs. Alternatively, if you want to account for time spent in i/o, try the "thread time profile".
对于简单、基本的解决方案,您可能希望将数据记录到 csv 文件。
例如,格式 [functionKey,timeStamp\n]
...然后将其加载到 Excel 中。获取增量,然后根据 if 函数包含或排除。没什么花哨的。从好的方面来说,您可以相当便宜地获得一些可视化效果。
for a simple, basic solution, you might want log data to a csv file.
e.g. Format [functionKey,timeStamp\n]
... then load that up in Excel. Get the deltas, and then include or exclude based on if functions. Nothing fancy. On the upside, you could get some visualisations fairly cheaply.