简体   繁体   English

如何使用Linux性能工具进行代码理解

[英]How to use linux perf tool for code comprehension

I'm fascinated by the ability of 'perf' to record call graphs and am trying to understand how to use it to understand a new code base. 我对“性能”记录调用图的能力着迷,并试图了解如何使用它来理解新的代码库。

I compiled the code in debug mode, and ran unit tests using the following command: 我在调试模式下编译了代码,并使用以下命令运行了单元测试:

perf record --call-graph dwarf make test 性能记录-调用图矮人测试

This creates a 230 meg perf.data. 这将创建一个230兆的perf.data。 I then write out the call graph 然后我写出调用图

perf report --call-graph --stdio > callgraph.txt 性能报告--call-graph --stdio> callgraph.txt

This creates a 50 meg file. 这将创建一个50兆的文件。

Ideally, I would only like to see code belonging to the project, not kernel code, system calls, c++ standard libraries, even boost and whatever other third party software. 理想情况下,我只希望看到属于该项目的代码,而不是内核代码,系统调用,c ++标准库,甚至是boost和任何其他第三方软件。 Currently I see items like __GI___dl_iterate_phdr, _Unwind_Find_FDE, etc. 目前,我看到诸如__GI ___ dl_iterate_phdr,_Unwind_Find_FDE等项目。

I love the flamegraph project. 我喜欢flamegraph项目。 However, that visualization isn't good for code comprehension. 但是,这种可视化效果不利于代码理解。 Are there any other projects, write-ups, ideas, which might be helpful? 还有其他项目,文章,想法可能会有所帮助吗?

perf report -g for huge application should not be dumped to external file as too verbose. 对于大型应用程序, perf report -g不应过于冗长地转储到外部文件中。 Collected perf.data (with -g ) will work without file redirection with interactive perf report TUI interface. 收集的perf.data (带有-g )可以在没有交互式Perf报告TUI界面的文件重定向的情况下工作。 You may disable callgraph reporting to find functions took most time with perf record without -g or perf report --no-children . 您可以禁用调用图报告,以查找在没有-gperf report --no-children情况下,花费最多时间进行perf record函数。

There is gprof2dot script ( https://github.com/jrfonseca/gprof2dot ) to visualize lagre perf report call-graphs as compact picture (graph). 有gprof2dot脚本( https://github.com/jrfonseca/gprof2dot )可将lagre perf报告调用图可视化为紧凑图片(图)。

There is also Brendan D. Gregg's interactive FlameGraphs in svg/js; svg / js中还有Brendan D. Gregg的交互式FlameGraphs and he often notes in presentations that perf report -g output shows many megabyte raw dumps of report as lot of A4 pages. 他经常在演示文稿中指出, perf report -g输出显示了许多兆字节的原始报告转储,以及许多A4页面。 There is usage instruction for the perf: http://www.brendangregg.com/FlameGraphs/cpuflamegraphs.html#perf : 有perf的使用说明: http ://www.brendangregg.com/FlameGraphs/cpuflamegraphs.html#perf:

# git clone https://github.com/brendangregg/FlameGraph  # or download it from github
# cd FlameGraph
# perf record -F 99 -g -- ../command
# perf script | ./stackcollapse-perf.pl > out.perf-folded
# ./flamegraph.pl out.perf-folded > perf-kernel.svg

PS: Why you are profiling make process? PS:为什么要进行概要分析过程? Try to select some test and profile only them. 尝试选择一些测试,然后仅对它们进行配置。 Use lower profile frequency to get smaller perf.data file. 使用较低的配置文件频率以获取较小的perf.data文件。 Also disable kernel-mode samples with :u suffix of default event "cycles": perf record -F 99 -g -e cycles:u -- ../command 还可以使用默认事件“ cycles”的后缀:u禁用内核模式样本: perf record -F 99 -g -e cycles:u -- ../command

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM