Cachegrind: a cache and branch-prediction profiler
• If you compile some files with
-g
and some without, some events that take place in a file without debug info could
be attributed to the last line of a file with debug info (whichever one gets placed before the non-debug-info file in
the executable).
This list looks long, but these cases should be fairly rare.
5.2.11. Merging Profiles with cg_merge
cg_merge is a simple program which reads multiple profile files, as created by Cachegrind, merges them together, and
writes the results into another file in the same format. You can then examine the merged results using
cg_annotate
<filename>
, as described above. The merging functionality might be useful if you want to aggregate costs over
multiple runs of the same program, or from a single parallel run with multiple instances of the same program.
cg_merge is invoked as follows:
cg_merge -o outputfile file1 file2 file3 ...
It reads and checks
file1
, then read and checks
file2
and merges it into the running totals, then the same with
file3
, etc. The final results are written to
outputfile
, or to standard out if no output file is specified.
Costs are summed on a per-function, per-line and per-instruction basis. Because of this, the order in which the input
files does not matter, although you should take care to only mention each file once, since any file mentioned twice will
be added in twice.
cg_merge does not attempt to check that the input files come from runs of the same executable. It will happily merge
together profile files from completely unrelated programs. It does however check that the
Events:
lines of all the
inputs are identical, so as to ensure that the addition of costs makes sense. For example, it would be nonsensical for it
to add a number indicating D1 read references to a number from a different file indicating LL write misses.
A number of other syntax and sanity checks are done whilst reading the inputs.
cg_merge will stop and attempt to
print a helpful error message if any of the input files fail these checks.
5.2.12. Differencing Profiles with cg_diff
cg_diff is a simple program which reads two profile files, as created by Cachegrind, finds the difference between
them, and writes the results into another file in the same format. You can then examine the merged results using
cg_annotate <filename>
, as described above. This is very useful if you want to measure how a change to a
program affected its performance.
cg_diff is invoked as follows:
cg_diff file1 file2
It reads and checks
file1
, then read and checks
file2
, then computes the difference (effectively
file1
-
file2
).
The final results are written to standard output.
Costs are summed on a per-function basis.
Per-line costs are not summed, because doing so is too difficult.
For
example, consider differencing two profiles, one from a single-file program A, and one from the same program A
where a single blank line was inserted at the top of the file. Every single per-line count has changed. In comparison,
the per-function counts have not changed.
The per-function count differences are still very useful for determining
differences between programs. Note that because the result is the difference of two profiles, many of the counts will
85