Expand description
§linux-perf-event-reader
This crate lets you parse Linux perf events and associated structures.
§Example
use linux_perf_event_reader::{
CommOrExecRecord, Endianness, EventRecord, PerfEventAttr, RawData, RawEventRecord,
RecordParseInfo, RecordType
};
// 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
})
);
Modules§
Structs§
- Attr
Flags - Branch
Sample Format - Comm
OrExec Record - Common
Data - Fork
OrExit Record - HwBreakpoint
Addr - The address of the breakpoint.
- HwBreakpoint
Len - The length of the breakpoint being measured.
- HwBreakpoint
Type - Lost
Record - Mmap2
Inode AndVersion - Mmap2
Record - Mmap
Record - These aren’t emitted by the kernel any more - the kernel uses MMAP2 events
these days.
However,
perf record
still emits synthetic MMAP events (not MMAP2!) for the kernel image. So if you want to symbolicate kernel addresses you still need to process these. The kernel image MMAP events have pid -1. - Perf
Event Attr perf_event_attr
- Perf
Event Header perf_event_header
- PmuType
Id - PMU type ID
- RawData
U64 - RawEvent
Record - An unparsed event record.
- Read
Format - The format of the data returned by read() on a perf event fd, as specified by attr.read_format:
- Record
IdParse Info - Record
Parse Info - Record
Type - Regs
- Sample
Format - Sample
Record - Throttle
Record
Enums§
- ClockId
- Context
Switch Record - CpuMode
- Endianness
- An enum for little or big endian.
- Event
Record - A fully parsed event record.
- Hardware
Cache Id - Hardware
Cache Op - Hardware
Cache OpResult - Hardware
Event Id - IpSkid
Constraint - 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 ofp
s. - Mmap2
File Id - Perf
Clock - This allows selecting which internal Linux clock to use when generating timestamps.
- Perf
Event Type - The type of perf event
- RawData
- 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.
- Sampling
Policy - Sampling Policy
- Software
Counter Type - Task
WasPreempted - Whether a task was in the
TASK_RUNNING
state when it was switched away from. - Wakeup
Policy - Wakeup policy for “overflow notifications”. This controls the point at
which the
read
call completes. (TODO: double check this)
Functions§
- get_
record_ id - Get the ID from an event record, with the help of
RecordIdParseInfo
. - get_
record_ identifier - Get the ID from an event record, if the sample format includes SampleFormat::IDENTIFIER.
- get_
record_ timestamp - Get the timestamp from an event record, with the help of
RecordParseInfo
. - is_
swapped_ endian