Expand description

linux-perf-event-reader

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

Example

use linux_perf_event_reader::{PerfEventAttr, RawData, RecordType};
use linux_perf_event_reader::records::{CommOrExecRecord, ParsedRecord, RawRecord, RecordParseInfo};

// Read the perf_event_attr data.
let attr_data = vec![
    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 =
    PerfEventAttr::parse::<_, byteorder::LittleEndian>(&attr_data[..], None).unwrap();
let parse_info = RecordParseInfo::from_attr(&attr);

let body = vec![
    108, 71, 8, 0, 108, 71, 8, 0, 100, 117, 109, 112, 95, 115, 121, 109, 115, 0, 0, 0, 0,
    0, 0, 0, 108, 71, 8, 0, 108, 71, 8, 0, 56, 27, 248, 24, 104, 88, 4, 0,
];
let body_raw_data = RawData::from(&body[..]);
let raw_record = RawRecord::new(RecordType(3), 0x2000, body_raw_data);
let parsed_record = raw_record
    .to_parsed::<byteorder::LittleEndian>(&parse_info)
    .unwrap();

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

Modules

Structs

perf_event_attr

perf_event_header

The format of the data returned by read() on a perf event fd, as specified by attr.read_format:

Enums

Specifies how precise the instruction address should be. With perf record -e you can set the precision by appending /p to the event name, with varying numbers of ps.

A slice of u8 data that can have non-contiguous backing storage split into two pieces, and abstracts that split away so that users can pretend to deal with a contiguous slice.

Functions