关于macos:使用gperftools / pprof时没有函数名称

No function names when using gperftools/pprof

我一直在尝试让gperftools CPU配置文件在我的程序上正常工作。

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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输出中,我该怎么做?

在这里,达到上述目的的过程对我来说很可能,如果有帮助的话。
我使用以下选项构建程序

1
2
3
4
5
6
7
8
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

从一个类似问题的答案中,我认为可能包括调试符号可能会在其中获得名称,但仅使用-g构建程序似乎没有帮助。同样,删除-O2标志也无济于事。


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