未解析的符号 sudo perf 记录/报告

未解析的符号 sudo perf 记录/报告

我正在尝试使用 perf 来分析我在工作服务器上编写的程序。我有 sudo 特权,但应该限制我用它做什么。

$ rm perf.data
$ perf record ./catch-hedging stress_BS_EURUSD_03M_delta_gamma_n_2_1_1
WARNING: Kernel address maps (/proc/{kallsyms,modules}) are restricted,
check /proc/sys/kernel/kptr_restrict.

Samples in kernel functions may not be resolved if a suitable vmlinux
file is not found in the buildid cache or in the vmlinux path.

Samples in kernel modules won't be resolved at all.

If some relocation was applied (e.g. kexec) symbols may be misresolved
even with a suitable vmlinux or kallsyms file.

Lowering default frequency rate to 250.
Please consider tweaking /proc/sys/kernel/perf_event_max_sample_rate.
Cannot read kernel map
Couldn't record kernel reference relocation symbol
Symbol resolution may be skewed if relocation was used (e.g. kexec).
Check /proc/kallsyms permission or run as root.
Read 'results-gcc.txt', got 285 results. Took 0.000514 seconds
===============================================================================
All tests passed (1 assertion in 1 test case)

[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.007 MB perf.data (143 samples) ]

当我运行 perf 报告时,我得到如下条目:

10.79%  catch-hedging  [unknown]         [k] 0xffffffff81614733

现在我拥有 sudo 特权,我认为这可以解决我的未解析内核符号的问题。所以我跑:

$ sudo perf record ./catch-hedging stress_BS_EURUSD_03M_delta_gamma_n_2_1_1
Lowering default frequency rate to 250.
Please consider tweaking /proc/sys/kernel/perf_event_max_sample_rate.
Read 'results-gcc.txt', got 285 results. Took 0.000942 seconds
===============================================================================
All tests passed (1 assertion in 1 test case)

[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.020 MB perf.data (149 samples) ]

这看起来更好,但是当我从我自己的代码运行 sudo perf report -f 符号时似乎没有得到解析:

17.13%  catch-hedging  catch-hedging      [.] 0x000000000002eced

为什么我的程序中的符号未解析?如何同时解析内核符号和程序中的符号?

作为参考,典型的编译命令如下所示(某些名称已更改):

g++ -Wunused -pthread -std=c++17 -g -fno-omit-frame-pointer -O2 -pthread -std=c++17 -Wno-parentheses -Wsequence-point -Wconversion -Wuninitialized -Wunused -Wmissing-field-initializers -g -fno-omit-frame-pointer -O2 -Isome-include-directories-omitted -D__stdcall= -DWINAPI= '-D__declspec(X)='  -c -o file.o file.cpp

我正在使用 g++ 8.1.0。

相关内容