linux-perf-data 0.6.0

A parser for the perf.data format. This format is emitted by the Linux perf tool.
Documentation

A parser for the perf.data file format.

Files of this format consist of a header, a data section, and a few other supplemental sections. The data section contains the main content of the file: a sequence of records.

There are two types of records: event records from the kernel, and "user records" from perf / simpleperf.

Example

use linux_perf_data::{AttributeDescription, PerfFileReader, PerfFileRecord};

# fn wrapper() -> Result<(), linux_perf_data::Error> {
let file = std::fs::File::open("perf.data")?;
let reader = std::io::BufReader::new(file);
let PerfFileReader { mut perf_file, mut record_iter } = PerfFileReader::parse_file(reader)?;
let event_names: Vec<_> =
perf_file.event_attributes().iter().filter_map(AttributeDescription::name).collect();
println!("perf events: {}", event_names.join(", "));

while let Some(record) = record_iter.next_record(&mut perf_file)? {
match record {
PerfFileRecord::EventRecord { attr_index, record } => {
let record_type = record.record_type;
let parsed_record = record.parse()?;
println!("{:?} for event {}: {:?}", record_type, attr_index, parsed_record);
}
PerfFileRecord::UserRecord(record) => {
let record_type = record.record_type;
let parsed_record = record.parse()?;
println!("{:?}: {:?}", record_type, parsed_record);
}
}
}
# Ok(())
# }