Skip to content

Instantly share code, notes, and snippets.

@zakkak
Created January 23, 2017 12:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zakkak/636cbacf1c298558297e1b7d024d209d to your computer and use it in GitHub Desktop.
Save zakkak/636cbacf1c298558297e1b7d024d209d to your computer and use it in GitHub Desktop.
Perf usage

Profile the program

perf record -g ./my-program

where g instructs perf to create a call graph.

Known issue

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.

Read the results

~perf report -g ‘graph,0.5,caller’~

where:

  • the graph part instructs perf 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 instructs perf to produce the call graph from the caller to the callees, instead of the default from callee to callers (backtrace like).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment