How to make linux ‘perf record’ work for libc and libstdc++ symbols

glibcperfprofiling

I'm using perf record -g on x86-64 Linux to profile a program. Several symbols in libc or libstdc++ have 0 as a parent: __GI___strcmp_ssse3 (libc) and strcmp@plt (libstdc++) for example. (I can actually break on these symbols in the debugger and get a backtrace.)

I'd love to know what the major callers of these functions are, and why they are not recorded. Is this because libc and libstdc++ do not have frame pointers on x86_64? And, more practically, is there some way around this?

Best Answer

This is an old question, but this in now possible with --call-graph dwarf. From the man page:

 -g
       Enables call-graph (stack chain/backtrace) recording.

   --call-graph
       Setup and enable call-graph (stack chain/backtrace) recording, implies -g.

           Allows specifying "fp" (frame pointer) or "dwarf"
           (DWARF's CFI - Call Frame Information) as the method to collect
           the information used to show the call graphs.

           In some systems, where binaries are build with gcc
           --fomit-frame-pointer, using the "fp" method will produce bogus
           call graphs, using "dwarf", if available (perf tools linked to
           the libunwind library) should be used instead.

I believe this requires a somewhat recent Linux kernel (>=3.9? I'm not entirely sure). You can check if your distro's perf package is linked with libdw or libunwind with readelf -d $(which perf) | grep -e libdw -e libunwind. On Fedora 20, perf is linked with libdw.

Related Question