#perf-events #perf #linux #parser

linux-perf-event-reader

Parse Linux perf_event information from raw bytes

9 breaking releases

0.10.1 Jul 3, 2024
0.10.0 Mar 3, 2024
0.9.0 Dec 8, 2022
0.8.0 Jun 10, 2022

#217 in Parser implementations

Download history 319/week @ 2024-07-22 454/week @ 2024-07-29 312/week @ 2024-08-05 416/week @ 2024-08-12 255/week @ 2024-08-19 303/week @ 2024-08-26 310/week @ 2024-09-02 307/week @ 2024-09-09 316/week @ 2024-09-16 421/week @ 2024-09-23 362/week @ 2024-09-30 487/week @ 2024-10-07 404/week @ 2024-10-14 376/week @ 2024-10-21 315/week @ 2024-10-28 353/week @ 2024-11-04

1,466 downloads per month
Used in 6 crates (via linux-perf-data)

MIT/Apache

130KB
2.5K SLoC

linux-perf-event-reader

This crate lets you parse Linux perf events and associated structures.

Example

use linux_perf_event_reader::{Endianness, PerfEventAttr, RawData, RecordType};
use linux_perf_event_reader::records::{CommOrExecRecord, EventRecord, RawEventRecord, RecordParseInfo};

// Read the perf_event_attr data.
let attr_data = [
    0, 0, 0, 0, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 229, 3, 0, 0, 0, 0, 0, 0, 47, 177, 0,
    0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 3, 183, 215, 97, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 15,
    255, 0, 0, 0, 0, 0, 0, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 104, 0, 0, 0, 0, 0, 0, 0, 128, 0,
    0, 0, 0, 0, 0, 0,
];
let (attr, _size) =
    PerfEventAttr::parse::<_, byteorder::LittleEndian>(&attr_data[..]).unwrap();
let parse_info = RecordParseInfo::new(&attr, Endianness::LittleEndian);

let body = b"lG\x08\0lG\x08\0dump_syms\0\0\0\0\0\0\0lG\x08\0lG\x08\08\x1b\xf8\x18hX\x04\0";
let body_raw_data = RawData::from(&body[..]);
let raw_record = RawEventRecord::new(RecordType::COMM, 0x2000, body_raw_data, parse_info);
let parsed_record = raw_record.parse().unwrap();

assert_eq!(
    parsed_record,
    EventRecord::Comm(CommOrExecRecord {
        pid: 542572,
        tid: 542572,
        name: RawData::Single(b"dump_syms"),
        is_execve: true
    })
);

Acknowledgements

Some of the code in this repo was based on @koute's not-perf project.

License

Licensed under either of

at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~0.5–1.2MB
~25K SLoC