# Use perf to Measure Cache Miss and TLB Miss

## Installation <a href="#installation" id="installation"></a>

Note that if you use *perf* on department **linux9** servers, there is no need to install.  Just in case, this is how to install *perf* on your Ubuntu VM (though not so useful):

```bash
sudo apt-get install linux-tools-common linux-tools-5.15.0-130-generic
```

Note that you may need to change the version number to your system's.

## Usage <a href="#usage" id="usage"></a>

To measure branch miss:

```bash
perf stat -e branch-misses <command>
```

To measure cache miss:

```bash
perf stat -e cache-misses <command>
```

To collect TLB miss:

```bash
perf stat -e dTLB-load-misses,iTLB-load-misses <command>
```

## **Example**

```bash
perf stat -e branch-misses ls > /dev/null
```

![](/files/-Lp-6W9_59YP-SsUWH14)

```bash
perf stat -e cache-misses ls > /dev/null
```

![](/files/-Lp-6W9bM91cDEf3-nhN)

```bash
perf stat -e dTLB-load-misses,iTLB-load-misses ls > /dev/null
```

![](/files/-Lp-6W9d-y-BY0SgZWPk)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://eric-lo.gitbook.io/program-optimization/measurement/use-perf-to-measure-cache-misses-and-tlb-misses.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
