callgrind_annotate - Linux


Overview

callgrind_annotate is a performance analysis tool that annotates profiling results from callgrind with additional information. It helps identify performance hotspots and bottlenecks in C/C++ code.

Syntax

callgrind_annotate [options] <callgrind-output> <source-files>...

Options/Flags

  • -c|–context: Show lines of code surrounding a call instead of the exact line.
  • -i|–inclusive: Show both inclusive and exclusive call counts.
  • -n|–num-cols: Set the number of columns to display (default: 80).
  • -q|–quiet: Suppress printing of totals section at the end.
  • -s|–sort: Sort results by time ascending or descending (default: descending).
  • -u|–unresolved: Show entries that have unresolved addresses.
  • -v|–verbose: Enable verbose output.

Examples

Annotate a callgrind.out file:

callgrind_annotate callgrind.out main.c

Annotate multiple source files with resolved addresses:

callgrind_annotate -i callgrind.out main.c util.c

Common Issues

Missing source code:

If the source code is not available, callgrind_annotate will show unresolved addresses. Use the -u option to display these entries.

Incorrect function names:

callgrind_annotate relies on symbol information from the executable. If the executable is stripped or if debugging symbols are not generated during compilation, the function names may be incorrect.

Integration

with gprof2dot:

Create a graphical representation of the callgraph:

callgrind_annotate -i callgrind.out main.c | gprof2dot -f - | dot -Tpng -o callgraph.png

Related Commands

  • gprof – Profile a program and generate a call graph.
  • pprof – Analyze profiling data from callgrind or other profiling tools.