# Record page fault events in a trace

## Overview

Fuchsia tracing captures kernel events, one of which is named `page_fault`. This
event represents the duration of the time used to handle the page fault. Page
faults occur when the running process needs a page of memory to continue execution.

## Enable page fault events

Page faults are handled by the kernel and are part of the `kernel:vm` category.

## Capture the trace

For general information on Fuchsia tracing and how to capture trace events
with [`ffx trace`](https://fuchsia.dev/reference/tools/sdk/ffx#ffx_trace), see [Fuchsia tracing](https://fuchsia.dev/docs/development/tracing/README).

To include page fault events in your trace, specify the
`kernel:vm` category:

    ffx trace start --categories "#default,kernel:vm"

## Understand a page fault event

![page_fault.png](https://fuchsia.dev/static/fuchsia-src/development/tracing/advanced/page_fault.png)

Page faults appear as slices in Perfetto.

The details of the event are shown in the bottom panel of Perfetto when you click
on the slice:

![page_fault_details.png](https://fuchsia.dev/static/fuchsia-src/development/tracing/advanced/page_fault_details.png)

The left part of the details displays the standard properties of any slice.
On the right side, there are arguments included in the page fault event.

- `vaddr` is the address of the page being processed by the page fault.
- `flags` indicate the type of the page fault:

| Read/Write | Type | Kind | Present |
|---|---|---|---|
| **R** ead/**W**rite | **U** ser/**G** uest/**S**ystem | **I** nstruction/**D**ata | **N** ot Present/ **P**resent |

See the source code for [fault.h](https://cs.opensource.google/fuchsia/fuchsia/+/main:/zircon/kernel/vm/include/vm/fault.h)
[](https://issues.fuchsia.dev/issues/new?component=1439230&template=1881640&description=Issue+on:+https://fuchsia.dev/docs/development/tracing/advanced/recording-page-faults.md "Report a bug or suggest improvements on this page") [](https://cs.opensource.google/fuchsia/fuchsia/+/main:docs/development/tracing/advanced/recording-page-faults.md "View the source code of this page") [](https://ci.android.com/edit?repo=fuchsia/fuchsia/main&file=docs/development/tracing/advanced/recording-page-faults.md&cloneRepo=fuchsia/fuchsia:refs/heads/main&fullPath=fuchsia/docs/development/tracing/advanced/recording-page-faults.md "Edit the source code of this page")