Cachegrind: a cache and branch-prediction profiler
(figures and code for line 704)
-- line 704 ----------------------------------------
-- line 878 ----------------------------------------
(figures and code for line 878)
The amount of context to show around annotated lines is controlled by the
--context
option.
To get automatic annotation, use the
--auto=yes
option. cg_annotate will automatically annotate every source file
it can find that is mentioned in the function-by-function summary. Therefore, the files chosen for auto-annotation
are affected by the
--sort
and
--threshold
options. Each source file is clearly marked (
Auto-annotated
source
) as being chosen automatically. Any files that could not be found are mentioned at the end of the output, eg:
------------------------------------------------------------------
The following files chosen for auto-annotation could not be found:
------------------------------------------------------------------
getc.c
ctype.c
../sysdeps/generic/lockfile.c
This is quite common for library files, since libraries are usually compiled with debugging information, but the source
files are often not present on a system. If a file is chosen for annotation both manually and automatically, it is marked
as
User-annotated source
. Use the
-I
/
--include
option to tell Valgrind where to look for source files if
the filenames found from the debugging information aren’t specific enough.
Beware that cg_annotate can take some time to digest large
cachegrind.out.<pid>
files, e.g. 30 seconds or
more. Also beware that auto-annotation can produce a lot of output if your program is large!
5.2.7. Annotating Assembly Code Programs
Valgrind can annotate assembly code programs too, or annotate the assembly code generated for your C program.
Sometimes this is useful for understanding what is really happening when an interesting line of C code is translated
into multiple instructions.
To do this, you just need to assemble your
.s
files with assembly-level debug information. You can use compile with
the
-S
to compile C/C++ programs to assembly code, and then assemble the assembly code files with
-g
to achieve
this. You can then profile and annotate the assembly code source files in the same way as C/C++ source files.
5.2.8. Forking Programs
If your program forks, the child will inherit all the profiling data that has been gathered for the parent.
If the output file format string (controlled by
--cachegrind-out-file
) does not contain
%p
, then the outputs
from the parent and child will be intermingled in a single output file, which will almost certainly make it unreadable
by cg_annotate.
5.2.9. cg_annotate Warnings
There are a couple of situations in which cg_annotate issues warnings.
83