Expand description
Parse data emitted by the linux perf_event_open
syscall.
§Important Types
Record
is an enum that can parse any known record type emitted byperf_event_open
. You will likely want to start here.- The
parse
module has theParser
andParseConfig
types which you will need in order to parse anything.
§Example
Parsing a mmap record directly from its raw byte format.
use perf_event_data::endian::Little;
use perf_event_data::parse::{ParseConfig, Parser};
use perf_event_data::Record;
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::<Little>::default();
let mut parser = Parser::new(data, config);
let record: Record = parser.parse()?;
let mmap = match record {
Record::Mmap(mmap) => mmap,
_ => panic!("expected a MMAP record"),
};
§Crate Orginization
This crate is organized like this:
- The root contains all the data types that records can be parsed into. This includes not only the types corresponding to the perf records but also those that make up their fields, and so on.
- The
parse
module contains types and traits needed to implement parsing support. Most types exposed in the root implementParse
but to actually make use of that you will need theParser
andParseConfig
types from theparse
module. - The
endian
module contains some types for converting values to the native endian. You likely won’t have to interact with it other than picking one type to use when creating aParseConfig
.
§Parsing perf.data
files
This crate doesn’t yet have support for this, although it could be used as part of implementing a larger parser. If you would like to do this please open an issue!
Modules§
- endian
- Traits and types for converting between a source endianness and that of the current host.
- parse
- Parsing interface for parsing data in to record types.
Structs§
- Aux
- AUX records indicate that new data is available in the aux buffer region.
- AuxFlags
- Flags describing the aux buffer update.
- AuxOutput
HwId - AUX_OUTPUT_HW_ID events allow matching data written to the aux area with an architecture-specific hadrware ID.
- AuxPmu
Format Type - PMU-specific trace format type
- BpfEvent
- BPF_EVENT records indicate when a BPF program is loaded or unloaded.
- BpfEvent
Type - Indicates the type of a
BpfEvent
- Branch
Entry - Record of a branch taken by the hardware.
- Branch
Type - Branch type as used by the last branch record.
- CGroup
- CGROUP records indicate when a new cgroup is created and activated.
- Comm
- COMM records indicate changes in process names.
- Data
Source - Describes where in the memory hierarchy the sampled instruction came from.
- Exit
- EXIT records indicate that a process has exited.
- Group
Entry - The values read from a single perf event counter.
- Group
Iter - Iterator over the entries of a group.
- ITrace
Start - ITRACE_START records indicate when a process has started an instruction trace.
- KSymbol
- KSYMBOL records indicate symbols being registered or unregistered within the kernel.
- KSymbol
Flags - Flags for
KSymbol
. - KSymbol
Type - The type of the kernel symbol.
- Lost
- Lost records indicate when events are dropped by the kernel.
- Lost
Samples - LOST_SAMPLES records indicate that some samples were lost while using hardware sampling.
- MemBlk
- Access was blocked.
- MemDtlb
- Memory TLB access.
- MemLevel
- Location in the memory hierarchy.
- MemLevel
Num - Memory hierarchy level number.
- MemLock
- Whether the instruction was a locked instruction.
- MemOp
- Memory operation.
- MemSnoop
- Memory snoop mode.
- MemSnoopX
- Extended bits for
MemSnoop
. - Mmap
- MMAP events record memory mappings.
- Mmap2
- MMAP2 events record memory mappings with extra info compared to MMAP records.
- Namespace
Entry - An individual namespace entry.
- Namespaces
- NAMESPACES records include namespace information of a process.
- Read
- READ events happen when the kernel records the counters on its own.
- Read
Format - Flags that control what data is returned when reading from a perf_event file descriptor.
- Read
Group - The values read from a group of counters.
- Read
Value - Data read from a counter.
- Record
Metadata - Extra record data emitted by the kernel that is common to all records.
- Registers
- Describes the captured subset of registers when a sample was taken.
- Sample
- A sample emitted by the kernel.
- Sample
Flags - Specifies which fields to include in the sample.
- Sample
Id - A subset of the sample fields that can be recorded in non-SAMPLE records.
- Sample
Regs Abi - ABI of the program when sampling registers.
- Text
Poke - TEXT_POKE records indicate a change in the kernel text.
- Throttle
- Record for a throttle or unthrottle events.
- TryFrom
Group Error - Error when attempting to convert
ReadGroup
to aReadValue
. - Txn
- Info about a transactional memory event.
Enums§
- Record
- A record emitted by the linux kernel.
- Switch
CpuWide - SWITCH_CPU_WIDE records indicates a context switch when profiling in cpu-wide mode.
Traits§
- Visitor
- A visitor for visiting parsed records.