linux_perf_data/lib.rs
1//! A parser for the perf.data file format.
2//!
3//! Files of this format consist of a header, a data section, and a few other
4//! supplemental sections. The data section contains the main content of the
5//! file: a sequence of records.
6//!
7//! There are two types of records: event records from the kernel, and "user
8//! records" from perf / simpleperf.
9//!
10//! The [`jitdump`] module lets you parse jitdump files, which are used in
11//! conjunction with perf.data files when profiling JIT runtimes.
12//!
13//! # Example
14//!
15//! ```
16//! use linux_perf_data::{AttributeDescription, PerfFileReader, PerfFileRecord};
17//!
18//! # fn wrapper() -> Result<(), linux_perf_data::Error> {
19//! let file = std::fs::File::open("perf.data")?;
20//! let reader = std::io::BufReader::new(file);
21//! let PerfFileReader { mut perf_file, mut record_iter } = PerfFileReader::parse_file(reader)?;
22//! let event_names: Vec<_> =
23//! perf_file.event_attributes().iter().filter_map(AttributeDescription::name).collect();
24//! println!("perf events: {}", event_names.join(", "));
25//!
26//! while let Some(record) = record_iter.next_record(&mut perf_file)? {
27//! match record {
28//! PerfFileRecord::EventRecord { attr_index, record } => {
29//! let record_type = record.record_type;
30//! let parsed_record = record.parse()?;
31//! println!("{:?} for event {}: {:?}", record_type, attr_index, parsed_record);
32//! }
33//! PerfFileRecord::UserRecord(record) => {
34//! let record_type = record.record_type;
35//! let parsed_record = record.parse()?;
36//! println!("{:?}: {:?}", record_type, parsed_record);
37//! }
38//! }
39//! }
40//! # Ok(())
41//! # }
42//! ```
43
44mod build_id_event;
45mod constants;
46mod dso_info;
47mod dso_key;
48mod error;
49mod feature_sections;
50mod features;
51mod file_reader;
52mod header;
53pub mod jitdump;
54mod perf_file;
55mod record;
56mod section;
57mod simpleperf;
58mod sorter;
59mod thread_map;
60
61/// This is a re-export of the linux-perf-event-reader crate. We use its types
62/// in our public API.
63pub use linux_perf_event_reader;
64
65/// This is a re-export of the `prost` crate. We use its types in our public API.
66pub use prost;
67
68pub use linux_perf_event_reader::Endianness;
69
70pub use dso_info::DsoInfo;
71pub use dso_key::DsoKey;
72pub use error::{Error, ReadError};
73pub use feature_sections::{AttributeDescription, NrCpus, SampleTimeRange};
74pub use features::{Feature, FeatureSet, FeatureSetIter};
75pub use file_reader::{PerfFileReader, PerfRecordIter};
76pub use perf_file::PerfFile;
77pub use record::{PerfFileRecord, RawUserRecord, UserRecord, UserRecordType};
78pub use simpleperf::{
79 simpleperf_dso_type, SimpleperfDexFileInfo, SimpleperfElfFileInfo, SimpleperfFileRecord,
80 SimpleperfKernelModuleInfo, SimpleperfSymbol, SimpleperfTypeSpecificInfo,
81};
82pub use thread_map::ThreadMap;