Skip to content

Instantly share code, notes, and snippets.

@xsnpdngv
Created February 17, 2017 12:42
Show Gist options
  • Save xsnpdngv/fece55819130bc6a70cec4a537f3570e to your computer and use it in GitHub Desktop.
Save xsnpdngv/fece55819130bc6a70cec4a537f3570e to your computer and use it in GitHub Desktop.
Profiling HowTo

Profiling with Callgrind

Callgrind is a profiling tool that can be used via the Valgrind framework and its report can be displayed/inspected with the KCachegrind profile data visualization tool.

Install

sudo apt-get install valgrind kcachegrind graphviz

Prepare

Not necessarily required but useful to have the debugging information in the binary so if it's possible compile with the -g option.

gcc -g -o program program.c

Profile

valgrind --tool=callgrind <program> [program-options]

# or even
valgrind --tool=callgrind --dump-instr=yes --simulate-cache=yes --collect-jumps=yes <program> [program-options]

NOTE: This way the program runs much slower...

Inspect

kcachegrind &
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment