Crate perf_event_data

source ·
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 by perf_event_open. You will likely want to start here.
  • The parse module has the Parser and ParseConfig 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 implement Parse but to actually make use of that you will need the Parser and ParseConfig types from the parse 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 a ParseConfig.

§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§

  • Traits and types for converting between a source endianness and that of the current host.
  • Parsing interface for parsing data in to record types.

Structs§

  • AUX records indicate that new data is available in the aux buffer region.
  • Flags describing the aux buffer update.
  • AUX_OUTPUT_HW_ID events allow matching data written to the aux area with an architecture-specific hadrware ID.
  • PMU-specific trace format type
  • BPF_EVENT records indicate when a BPF program is loaded or unloaded.
  • Indicates the type of a BpfEvent
  • Record of a branch taken by the hardware.
  • Branch type as used by the last branch record.
  • CGROUP records indicate when a new cgroup is created and activated.
  • COMM records indicate changes in process names.
  • Describes where in the memory hierarchy the sampled instruction came from.
  • EXIT records indicate that a process has exited.
  • The values read from a single perf event counter.
  • Iterator over the entries of a group.
  • ITRACE_START records indicate when a process has started an instruction trace.
  • KSYMBOL records indicate symbols being registered or unregistered within the kernel.
  • Flags for KSymbol.
  • The type of the kernel symbol.
  • Lost records indicate when events are dropped by the kernel.
  • LOST_SAMPLES records indicate that some samples were lost while using hardware sampling.
  • Access was blocked.
  • Memory TLB access.
  • Location in the memory hierarchy.
  • Memory hierarchy level number.
  • Whether the instruction was a locked instruction.
  • Memory operation.
  • Memory snoop mode.
  • Extended bits for MemSnoop.
  • MMAP events record memory mappings.
  • MMAP2 events record memory mappings with extra info compared to MMAP records.
  • An individual namespace entry.
  • NAMESPACES records include namespace information of a process.
  • READ events happen when the kernel records the counters on its own.
  • Flags that control what data is returned when reading from a perf_event file descriptor.
  • The values read from a group of counters.
  • Data read from a counter.
  • Extra record data emitted by the kernel that is common to all records.
  • Describes the captured subset of registers when a sample was taken.
  • A sample emitted by the kernel.
  • Specifies which fields to include in the sample.
  • A subset of the sample fields that can be recorded in non-SAMPLE records.
  • ABI of the program when sampling registers.
  • TEXT_POKE records indicate a change in the kernel text.
  • Record for a throttle or unthrottle events.
  • Error when attempting to convert ReadGroup to a ReadValue.
  • Info about a transactional memory event.

Enums§

  • A record emitted by the linux kernel.
  • SWITCH_CPU_WIDE records indicates a context switch when profiling in cpu-wide mode.

Traits§

  • A visitor for visiting parsed records.

Type Aliases§

  • FORK records indicate that a process called fork(2) successfully.