perf record -g ./my-program
where g
instructs perf
to create a call graph.
To produce meaningful call-graphs, perf
needs a way to read the
call stack. To achieve this it relies on frame-pointers, thus we
need to instruct the compiler to not omit them. To do so we need to
compile with --fno-omit-frame-pointer
.
~perf report -g ‘graph,0.5,caller’~
where:
- the
graph
part instructsperf
to keep the percentages normalized to the total execution time, i.e., avoid reporting percentages as the portion of time relative to the parent function, - the
0.5
part filters out functions taking less than 0.5% of the execution time, - the
caller
part instructsperf
to produce the call graph from the caller to the callees, instead of the default from callee to callers (backtrace like).