有没有办法使用 perf 工具在进程中查找单个函数的性能?

Bap*_*ekh 9 linux profiling function perf

我试图在一个过程中获得单个功能的性能。我怎样才能使用 perf 工具做到这一点?有没有其他工具可以做到这一点?

例如,假设 main 函数调用函数 A 、 B 、 C 。我想分别获得主要功能以及功能 A、B、C 的性能。

是否有一个很好的文档来低估 perf 源代码?

谢谢你。

qqi*_*row 5

您想要做的是用户空间探测。Perf只能做一部分。尝试sudo perf top -p [pid]然后观察记分牌。它将显示按 CPU 使用率排序的函数列表。以下是基准测试期间 Redis 的快照:

redis 性能顶级分析

如果你想获得用户层功能的更多信息,例如 IO 使用情况、延迟、内存使用情况,我强烈建议你使用 Systemtap。它既是脚本语言,也是在基于 Linux 内核的操作系统上分析程序的工具。这是一个关于它的教程:

http://qqibrow.github.io/performance-profiling-with-systemtap/

而且您不需要成为 systemtap 脚本编写专家,网上有很多好的脚本适合您。例如,有一个关于使用它来找出特定功能的延迟的示例。

https://github.com/openresty/stapxx#func-latency-distr


小智 0

perf 的文档位于https://perf.wiki.kernel.org/index.php/Main_Page,教程位于https://perf.wiki.kernel.org/index.php/Tutorial

perf 报告按“命令”进行细分,请参阅https://perf.wiki.kernel.org/index.php/Tutorial#Sample_analysis_with_perf_report。perf annotate 提供了一种选择要报告的命令的方法,请参阅https://perf.wiki.kernel.org/index.php/Tutorial#Options_controlling_output_2中的“使用 perf annotate 进行源级别分析” 。