# Using Cachegrind

Cachegrind performs cache and branching profiling. A Cachegrind profile run measures the number of cache misses and branch mispredictions performed by an application. Cachegrind collects the following statistics:

- L1 instruction cache reads and misses
- L1 data cache reads and read misses, writes, and write misses
- L2 unified cache reads and read misses, writes and write misses
- Conditional branches and mispredicted conditional branches
- Indirect branches and mispredicted indirect brances

To use Cachegrind, navigate to Profiling Tools > Profile Configurations to access the Profile Configurations menu. Open the Valgrind Options tab and choose Cachegrind from the Tool to run: drop-down list.

## Analyzing Cachegrind Profile Results

The results of a Cachegrind profile run are displayed in the Valgrind view. These results show Cachegrind's cache/branch data in different levels of granularity. Double-clicking on any file, function, or line will open the corresponding source file and place the cursor on the appropriate location (if the source can be resolved).

## Configuring a Cachegrind Profile Run

To configure a Massif profile run, navigate to Profiling Tools > Profile Configurations to access the Profile Configurations menu. In the Valgrind Options tab, navigate further to Cachegrind Options .

The Cachegrind Options tab allows you to configure the following Cachegrind options:

- Profile Cache Accesses/Misses is identical to the Cachegrind command-line option `--cache-sim=`, which specifies whether or not to collect cache accesses and miss counts. This option is enabled by default.

- Profile Branch Instructions/Mispredictions is identical to the Cachegrind command-line option `--branch-sim=`, wich specifies whether or not to collect branch instruction and misprediction counts. This option is disabled by default.

- The options inside the Manually Set Cache Specifications box allow you to configure the size, associativity, and line size of the following caches:
  - l1 (level 1 instruction) cache
  - D1 (level 1 data) cache
  - L2 (level 2) cache

For more information about each Cachegrind option in the Valgrind plug-in for Eclipse, refer to `man valgrind`.