32

I'm running "perf" in the following way:

perf record -a --call-graph -p some_pid

perf report --call-graph --stdio

Then, I see this:

 1.60%     my_binary  my_binary                [.] my_func
           |
           --- my_func
              |          
              |--71.10%-- (nil)
              |          (nil)
              |          
               --28.90%-- 0x17f310000000a

I can't see which functions call my_func(). I see "nil" and "0x17f310000000a" instead. Am I doing something wrong? It is probably not a debug info problem because some symbols are shown while others are not shown.

More info:

  • I'm runnning CentOS 6.2 (kernel 2.6.32-220.4.1).
  • perf rpm - perf-2.6.32-279.5.2.el6.x86_64.
1

2 Answers 2

35

Make sure you compiled the code with -fno-omit-frame-pointer gcc option.

3
  • 34
    or try perf record --call-graph dwarf (which works without frame-pointer)
    – maxy
    Jan 26, 2015 at 15:50
  • install debuginfo packages for the code you profile, most of the time you'll need glibc, ie debuginfo-install glibc Dec 22, 2016 at 21:41
  • So, perf record --call-graph dwarf does NOT work (for me), and actively PREVENTS a callgraph from being recorded, even if one compiled with -fno-omit-frame-pointer ... it took me many hours & hair-pulling before I realized that I MUST do perf record --call-graph fp to get a callgraph!
    – Linas
    Aug 18, 2020 at 4:43
19

You're almost there, you're missing the -G option (you might need a more recent perf than the one installed on your system):

$ perf report --call-graph --stdio -G

From perf help report:

   -G, --inverted
       alias for inverted caller based call graph.
2
  • 2
    -G just changes order of call stack printing in perf report; if there is no full call stack recorded to perf.data at time of perf record, -G option will not help. Just need to enable frame pointers or dwarf (may be not ported to rh's 2.6.32) to decode frames at time of record: brendangregg.com/perf.html#StackTraces "Omitting frame pointers is an evil compiler optimization that breaks debugger"
    – osgx
    Jul 9, 2016 at 8:44
  • 4
    Note that -G on perf record (rather than report) selects by cgroup, in case anyone gets confusing errors about cgroups. Dec 4, 2017 at 5:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.