gpt4 book ai didi

c++ - 使用linux perf和不同的调用图模式对程序进行性能分析会得出不同的结果

转载 作者:行者123 更新时间:2023-12-02 10:07:47 26 4
gpt4 key购买 nike

我想用linux性能分析我的c++程序。
为此,我使用了以下三个命令,但我不明白为什么会得到三个完全不同的报告。

perf record --call-graph dwarf ./myProg
perf report

enter image description here
perf record --call-graph fp ./myProg
perf report

enter image description here
perf record --call-graph lbr ./myProg
perf report

enter image description here

我也不明白为什么 main函数不是列表中的最高函数。

我的程序的逻辑如下, main函数调用 getPogDocumentFromFile函数,该函数调用 fromPoxml,该函数调用 toPred,该函数调用 applySubst,该函数调用 subst。而且 toPredapplySubstsubst是递归函数。而且我希望它们成为瓶颈。

还有一些评论:我的程序运行大约25分钟,它具有很高的递归性,并分配了大量的内存(〜17Go)。我也用 -fno-omit-frame-pointer编译,并使用最新的intel CPU。

任何的想法?

编辑:

再次考虑我的问题,我意识到我不理解“ child ”专栏的含义。

到目前为止,我假设Self列是我们在调用堆栈顶部看到的具有函数的样本的百分比,Children列是函数在调用堆栈中的任何位置的样本的百分比。显然不是这种情况,否则main函数的子列距离100%不远。也许调用栈被截断了?还是我完全误解了探查器的工作原理?

最佳答案

Man page of pref report 文档显示带有子项累积的 call 链:

  --children
Accumulate callchain of children to parent entry so that then can
show up in the output. The output will have a new "Children"
column and will be sorted on the data. It requires callchains are
recorded. See the ‘overhead calculation’ section for more
details. Enabled by default, disable with --no-children.


我可以建议您尝试使用 --no-children(或 perf report perf top)的 -g --no-children -p $PID_OF_PROGRAM选项尝试非默认模式

因此,在默认模式下,当perf.data文件中有一些调用链数据时,perf报表将计算“自我”和“自我+子代”的开销并对累积的数据进行排序。这意味着,如果某个函数 f1()具有10%的“self”样本,并调用某些叶函数 f2()与20%的“self”样本,则 f1() self + children将为30%。累积的数据适用于提及当前功能的所有堆栈:用于其本身所做的工作,以及所有直接和间接子代(后代)中的工作。

您可以在 --call-graph选项(dwarf / lbr / fp)中指定一些调用堆栈采样方法,它们可能有一些限制。有时方法(尤其是fp)可能无法提取部分调用堆栈。 -fno-omit-frame-pointer选项可能会有所帮助,但是在可执行文件中使用它但在某些具有回调的库中不使用它时,则将部分提取调用堆栈。有些方法可能无法提取某些很长的调用链。否则 perf report可能无法处理某些情况。

要检查截断的 call 链样本,请在中间的某处使用 perf script|less。在此模式下,它确实会打印所有记录的带有所有检测到的函数名称的样本,并检查样本是否以 main__libc_start_main结尾的文件-被截断。

otherwise the main function would have its children column not far from 100%



是的,对于单线程程序以及正确记录和处理的调用堆栈, main在“子项”(Children)列中的值应为99%。对于多线程程序,第二个线程和其他线程将具有另一个根节点,如start_thread。

关于c++ - 使用linux perf和不同的调用图模式对程序进行性能分析会得出不同的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59307540/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com