performance - 性能如何工作?

标签 performance perf

我正在使用 perf 来了解我的程序的每个函数对总执行时间施加的开销。为此,我使用 cpu-cycles 事件:

perf record -e cpu-cycles -c 10000 <binary-with-arguments>

当我查看输出时,我会看到与每个函数相关的一些百分比。但对我来说没有意义的是这样的情况:函数 A 在函数 B 内被调用,在其他地方没有。但是我得到的函数 A 的开销百分比高于 B。如果 B 调用 A,那意味着 B 应该包括 A 的开销。还是我在这里遗漏了什么?

最佳答案

您正在使用的 perf 命令只是对您的程序进行采样,而没有记录调用堆栈的任何信息。使用 perf report您可以独立于调用关系获得落入函数中的样本数量。

您可以使用 --call-graph使用时获取树的选项 perf report :

perf record -e cpu-cycles --call-graph dwarf -c 10000 <binary-with-arguments>

关于performance - 性能如何工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31460986/

相关文章:

javascript - 为 innerHTML 设置大值时提高性能的方法

performance - 无法使用cfcontent传递缓存内容

.net - 在 Win32/COM 方法上调用 PInvoke 时,通常是否会对性能造成明显影响?

linux - 在脚本中使用别名

Linux 性能 : is it possible to somehow ignore busy waiting threads?

linux - 需要性能计数器信息

SQL 性能 ( MySQL )

C++ 函数名对于 perf 来说太长了

c++ - 如何分析 C/C++ 应用程序中内存访问所花费的时间?

algorithm - 比较 BFS 算法的两种不同实现时了解性能细节