我一直在尝试使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标志也无济于事。
使用Google的pprof代替brew的pprof https://github.com/google/pprof