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.
This crate also contains parsing code for jitdump files, which are used in conjunction with perf.data files when profiling JIT runtimes.
```rust use linuxperfdata::{AttributeDescription, PerfFileReader, PerfFileRecord};
let file = std::fs::File::open("perf.data")?; let reader = std::io::BufReader::new(file); let PerfFileReader { mut perffile, mut recorditer } = PerfFileReader::parsefile(reader)?; let eventnames: Vec<_> = perffile.eventattributes().iter().filtermap(AttributeDescription::name).collect(); println!("perf events: {}", eventnames.join(", "));
while let Some(record) = recorditer.nextrecord(&mut perffile)? { match record { PerfFileRecord::EventRecord { attrindex, record } => { let recordtype = record.recordtype; let parsedrecord = record.parse()?; println!("{:?} for event {}: {:?}", recordtype, attrindex, parsedrecord); } PerfFileRecord::UserRecord(record) => { let recordtype = record.recordtype; let parsedrecord = record.parse()?; println!("{:?}: {:?}", recordtype, parsed_record); } } } ```
```rust use linuxperfdata::jitdump::{JitDumpReader, JitDumpRecord};
let file = std::fs::File::open("jit-12345.dump")?; let mut reader = JitDumpReader::new(file)?; println!("jitdump header: {:?}", reader.header());
while let Some(rawrecord) = reader.nextrecord()? { let timestamp = rawrecord.timestamp; match rawrecord.parse()? { JitDumpRecord::CodeLoad(record) => { println!("{timestamp:016} LOAD {record:?}"); } JitDumpRecord::CodeMove(record) => { println!("{timestamp:016} MOVE {record:?}"); } JitDumpRecord::CodeDebugInfo(record) => { println!("{timestamp:016} DEBUGINFO {record:?}"); } JitDumpRecord::CodeClose => { println!("{timestamp:016} CLOSE"); } JitDumpRecord::CodeUnwindingInfo(record) => { println!("{timestamp:016} UNWINDINGInfo {record:?}"); } JitDumpRecord::Other(record) => { println!("{timestamp:016} {} {record:?}", record.record_type.0); } } } ```
Licensed under either of
LICENSE-APACHE
or http://www.apache.org/licenses/LICENSE-2.0)LICENSE-MIT
or http://opensource.org/licenses/MIT)at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.