如何使 linux 'perf record' 适用于 libc 和 libstdc++ 符号?

Ben*_*ngs 13 glibc profiling perf

perf record -g在 x86-64 Linux 上使用来分析程序。libc 或 libstdc++ 中的几个符号0作为父符号:例如__GI___strcmp_ssse3(libc) 和strcmp@plt(libstdc++)。(我实际上可以在调试器中打破这些符号并获得回溯。)

我很想知道这些函数的主要调用者是什么,以及为什么没有记录它们。这是因为 libc 和 libstdc++ 在 x86_64 上没有帧指针吗?而且,更实际的是,有没有办法解决这个问题?

ajd*_*574 5

这是一个老问题,但现在可以使用--call-graph dwarf. 从手册页:

 -g
       Enables call-graph (stack chain/backtrace) recording.

   --call-graph
       Setup and enable call-graph (stack chain/backtrace) recording, implies -g.

           Allows specifying "fp" (frame pointer) or "dwarf"
           (DWARF's CFI - Call Frame Information) as the method to collect
           the information used to show the call graphs.

           In some systems, where binaries are build with gcc
           --fomit-frame-pointer, using the "fp" method will produce bogus
           call graphs, using "dwarf", if available (perf tools linked to
           the libunwind library) should be used instead.
Run Code Online (Sandbox Code Playgroud)

我相信这需要一个最近的 Linux 内核(>=3.9?我不完全确定)。您可以检查发行版的 perf 包是否与 libdw 或 libunwind 与readelf -d $(which perf) | grep -e libdw -e libunwind. 在 Fedora 20 上,perf 与 libdw 相关联。


小智 -3

perf是一个显示系统调用所用时间的内核工具。您正在寻找 GNU gprof。“gprof - 显示调用图配置文件数据”。要使用 gprof,您需要使用开关编译源代码-pg

除此之外,还有许多复杂的分析工具,例如eclipse-cdt-profiling-framework.