How can I get perf to find symbols in my program
Solution 1
This post is already over a year old, but since it came out at the top of my Google search results when I had the same problem, I thought I'd answer it here. After some more searching around, I found the answer given in this related StackOverflow question very helpful. On my Ubuntu Raring system, I then ended up doing the following:
- Compile my C++ sources with
-g
(fairly obvious, you need debug symbols) -
Run
perf
asrecord -g dwarf -F 97 /path/to/my/program
This way
perf
is able to handle the DWARF 2 debug format, which is the standard formatgcc
uses on Linux. The-F 97
parameter reduces the sampling rate to 97 Hz. The default sampling rate was apparently too large for my system and resulted in messages like this:Warning: Processed 172390 events and lost 126 chunks! Check IO/CPU overload!
and the
perf report
call afterwards would fail with a segmentation fault. With the reduced sampling rate everything worked out fine. - Once the
perf.data
file has been generated without any errors in the previous step, you can runperf report
etc. I personally like the FlameGraph tools to generate SVG visualizations. -
Other people reported that running
echo 0 > /proc/sys/kernel/kptr_restrict
as root can help as well, if kernel symbols are required.
Solution 2
In my case the solution was to delete the elf files which contained cached symbols from previous builds and were messing things up.
They are in ~/.debug/ folder
Solution 3
You can always use the '$ nm ' command.
here is some sample output:
Ethans-MacBook-Pro:~ phyrrus9$ nm a.out
0000000100000000 T __mh_execute_header
0000000100000f30 T _main
U _printf
0000000100000f00 T _sigint
U _signal
U dyld_stub_binder
Solution 4
Make sure that you compile the program using -g option along with gcc(cc) so that debugging information is produced in the operating system's native format. Try to do the following and check if there are debug symbols present in the symbol table.
$objdump -t your-elf
$readelf -a your-elf
$nm -a your-elf
Solution 5
I had this problem too, I couldn't see any userspace symbol, but I saw some kernel symbols. I thought this was a symbol loading issue. After tried all the possible solutions I could find, I still couldn't get it work.
Then I faintly remember that
ulimit -u unlimited
is needed. I tried and it magically worked.
I found from this wiki that this command is needed when you use too many file descriptors.
https://perf.wiki.kernel.org/index.php/Tutorial#Troubleshooting_and_Tips
my final command was
perf record -F 999 -g ./my_program
didn't need --call-graph
Sam Tobin-Hochstadt
I'm an Associate Professor at Indiana University working on programming languages. I'm also a developer of Racket and a member of ECMA TC39, the standards committee for JavaScript. Follow me at @samth.
Updated on March 28, 2020Comments
-
Sam Tobin-Hochstadt about 4 years
When using
perf report
, I don't see any symbols for my program, instead I get output like this:$ perf record /path/to/racket ints.rkt 10000 $ perf report --stdio # Overhead Command Shared Object Symbol # ........ ........ ................. ...... # 70.06% ints.rkt [unknown] [.] 0x5f99b8 26.28% ints.rkt [kernel.kallsyms] [k] 0xffffffff8103d0ca 3.66% ints.rkt perf-32046.map [.] 0x7f1d9be46650
Which is fairly uninformative.
The relevant program is built with debugging symbols, and the
sysprof
tool shows the appropriate symbols, as does Zoom, which I think is usingperf
under the hood.Note that this is on x86-64, so the binary is compiled with
-fomit-frame-pointer
, but that's the case when running under the other tools as well.