Chapter 19. Monitoring processes for performance bottlenecks by using perf circular buffers


You can create circular buffers that take event-specific snapshots of data with the perf tool. Use them to monitor performance bottlenecks in specific processes or parts of applications running on your system.

In such cases, perf only writes data to a perf.data file for later analysis if a specified event is detected.

Recording hours of perf data before a specific event may cause excessive overhead or prove impractical for analysis. In such cases, use perf record to create custom circular buffers that take snapshots after specific events.

The --overwrite option makes perf record store all data in an overwritable circular buffer. When the buffer gets full, perf record automatically overwrites the oldest records which, therefore, never get written to a perf.data file.

Using the --overwrite and --switch-output-event options together configures a circular buffer. It records and dumps data continuously until it detects the --switch-output-event trigger event. The trigger signals perf record to write data from the circular buffer to the perf.data file after an event. This collects specific data while reducing overhead by only writing relevant information to the perf.data file.

With the perf tool, you can create circular buffers. These are triggered by events you specify to only collect data you are interested in. To create circular buffers that collect event-specific data, use the --overwrite and --switch-output-event options for perf.

Prerequisites

  • You have the perf user space tool installed. For more information, see Installing perf.
  • You have placed a uprobe in the process or application you are interested in monitoring at a location of interest within the process or application:

    # perf probe -x </path/to/executable> -a function
    Added new event:
      probe_executable:function   (on function in /path/to/executable)
    
    You can now use it in all perf tools, such as:
    
        perf record -e probe_executable:function -aR sleep 1

Procedure

  • Create the circular buffer with the uprobe as the trigger event:

    # perf record --overwrite -e cycles --switch-output-event probe_executable:function ./executable
    [ perf record: dump data: Woken up 1 times ]
    [ perf record: Dump perf.data.2021021012231959 ]
    [ perf record: dump data: Woken up 1 times ]
    [ perf record: Dump perf.data.2021021012232008 ]
    [ perf record: dump data: Woken up 1 times ]
    [ perf record: Dump perf.data.2021021012232082 ]
    [ perf record: Captured and wrote 5.621 MB perf.data.<timestamp> ]

    This command initiates the executable and collects cpu cycles, specified after the -e option, until perf detects the uprobe, the trigger event specified after the --switch-output-event option. At that point, perf snapshots circular buffer data and stores it in a unique perf.data file identified by timestamp. This example produced a total of 2 snapshots, the last perf.data file was forced by pressing Ctrl+C.

Red Hat logoGithubredditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust. Explore our recent updates.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

Theme

© 2026 Red Hat
Back to top