14

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?

countermode
  • 7,373
  • 5
  • 31
  • 58

2 Answers2

5

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.

ajduff574
  • 223
  • 3
  • 7
  • `perf record --call-graph dwarf` solves this problem for me. unfortunately, it seems that perf has problems showing caller-based (i.e. "inverted") call-graphs when using dwarf information. That is why I started using FlameGraph for visualisation. – blue Feb 12 '17 at 13:29
  • note that using dwarf unwinding causes very significant overhead during profiling – Azsgy Feb 16 '20 at 02:35
-3

perf is a kernel tool which shows elapsed time for system calls. You are looking for GNU gprof. "gprof - display call graph profile data". To use gprof you need to compile your sources with the -pg switch.

Beside of this there are a lot of sophisticated profiling tools like eclipse-cdt-profiling-framework.