#perf-event #perf-event-open #perf-events #parser #perf #linux #record

perf-event-data

Types and traits for parsing records emitted by perf_event_open

9 releases

new 0.1.8 Jan 21, 2025
0.1.7 Jan 18, 2025
0.1.6 May 21, 2024
0.1.4 Oct 24, 2023
0.1.2 May 17, 2023

#73 in Profiling

Download history 65/week @ 2024-10-06 15/week @ 2024-10-13 141/week @ 2024-10-20 92/week @ 2024-10-27 70/week @ 2024-11-03 73/week @ 2024-11-10 92/week @ 2024-11-17 114/week @ 2024-11-24 276/week @ 2024-12-01 123/week @ 2024-12-08 62/week @ 2024-12-15 2/week @ 2024-12-22 21/week @ 2024-12-29 71/week @ 2025-01-05 151/week @ 2025-01-12 236/week @ 2025-01-19

479 downloads per month
Used in 3 crates (via perf-event2)

MIT/Apache

175KB
4K SLoC

perf-event-data

ci badge crates.io badge docs.rs badge

Parse data emitted by perf_event_open into usable rust structs.

Getting Started

  • The Record type is an enum with every known record type.
  • The parse module has what you need to parse bytes into known records.

Putting it all together, we get

use perf_event_data::endian::Native;
use perf_event_data::parse::{ParseConfig, Parser};
use perf_event_data::Record;

fn main() {
    let data: &[u8] = &[
        0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00,
        0x16, 0x4C, 0x01, 0x00, 0x17, 0x4C, 0x01, 0x00,
        0x00, 0xA0, 0x48, 0x96, 0x4F, 0x7F, 0x00, 0x00,
        0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0xA0, 0x48, 0x96, 0x4F, 0x7F, 0x00, 0x00,
        0x2F, 0x2F, 0x61, 0x6E, 0x6F, 0x6E, 0x00, 0x00, 
    ];

    let config = ParseConfig::<Native>::default();
    let mut parser = Parser::new(data, config);
    let record: Record = parser.parse().expect("failed to parse the record");

    // ...
}

See Also

  • The perf-event2 crate allows you to set up sampled perf event counters. You will likely need this, or an equivalent crate, in order to get the event data this crate parses.
  • The linux-perf-event-reader crate provides similar functionality to this one.

Dependencies

~570–770KB
~19K SLoC