【问题标题】:No function names when using gperftools/pprof使用 gperftools/pprof 时没有函数名
【发布时间】:2019-12-14 02:02:46
【问题描述】:

我一直在尝试让 gperftools CPU 分析在我的程序上运行。

我遇到了一个问题,当 pprof 报告时,我的程序中的所有函数名称都是指针地址。令人讨厌的是,我链接的库中的大多数函数名称都是可读的,但我的程序文件中没有。下面的例子。

s979258ca% pprof --text ./hmiss hmiss.prof                                        
Using local file ./hmiss.
Using local file hmiss.prof.
Total: 469 samples
     152  32.4%  32.4%      152  32.4% 0x000000010ba6dd45
      47  10.0%  42.4%       47  10.0% 0x000000010ba6d365
      46   9.8%  52.2%       46   9.8% 0x000000010ba6d371
      34   7.2%  59.5%       34   7.2% 0x000000010ba8a04a
      32   6.8%  66.3%       32   6.8% 0x000000010ba6d35a
      10   2.1%  68.4%       10   2.1% 0x000000010ba8873c
       9   1.9%  70.4%        9   1.9% 0x00007fff63f409da
       6   1.3%  71.6%        6   1.3% 0x000000010ba7feca
       6   1.3%  72.9%        6   1.3% 0x00007fff63f40116
       6   1.3%  74.2%        6   1.3% 0x00007fff63f409f2
       5   1.1%  75.3%        5   1.1% 0x000000010ba6dd4c
       ...

我需要做什么才能让我的函数名称包含在 pprof 输出中?

如果对我有帮助,这就是达到上述目的的过程。 我使用以下选项构建我的程序

clang++
"-std=c++17",
"-g",
"-O2",
"...cpp files..."
"-o",
"~/cpp/hmiss/hmiss",
"/usr/local/Cellar/gperftools/2.7/lib/libprofiler.dylib",

我通过运行 gprof 启用 CPU 分析

DYLD_FALLBACK_LIBRARY_PATH=/opt/local/lib CPUPROFILE=hmiss.prof ./hmiss

然后我运行pprof --text ./hmiss hmiss.prof

从对similar question 的回答中,我认为可能包括调试符号可能会在其中获得名称,但仅使用 -g 构建我的程序似乎没有帮助。此外,删除 -O2 标志也无济于事。

【问题讨论】:

  • 我认为只有“-g”就足够了,但我想不是。尝试不使用“O2”。
  • 对不起,我应该补充一下,我也试过没有 O2
  • 你试过“-rdynamic”和/或“-Wl,--export-dynamic”吗?
  • 以前没有听说过这些选项,但这是个好主意。可悲的是 -rdynamic 不起作用,我无法使用 -Wl,--export-dynamic 编译任何东西(使用 clang++ 或 g++)。似乎根据这里:stackoverflow.com/a/30468391/7965931 第二个选项可能与 macos 无关。

标签: macos profiling c++17 clang++ gperftools


【解决方案1】:

使用 google 的 pprof 代替 brew 的 pprof https://github.com/google/pprof

【讨论】:

  • 安装类似GOPATH=(path-to-install-dir) go get -u github.com/google/pprofI think
【解决方案2】:

我有一个类似的问题,pprof 只显示二进制文件,而不是函数名和行。产生痕迹也需要很长时间。

我发现您不能将其称为 go tool pprof,而必须调用 ~/go/bin/pprof 或直接将其放在您的路径上。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-25
    • 1970-01-01
    • 2022-10-21
    • 1970-01-01
    • 2014-04-07
    • 1970-01-01
    • 2021-08-28
    • 2022-01-14
    相关资源
    最近更新 更多