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//! # File Mode Example
14//!
15//! Parse a perf.data file from disk (requires `Seek`):
16//!
17//! ```no_run
18//! use linux_perf_data::{AttributeDescription, PerfFileReader, PerfFileRecord};
19//!
20//! # fn wrapper() -> Result<(), linux_perf_data::Error> {
21//! let file = std::fs::File::open("perf.data")?;
22//! let reader = std::io::BufReader::new(file);
23//! let PerfFileReader { mut perf_file, mut record_iter } = PerfFileReader::parse_file(reader)?;
24//! let event_names: Vec<_> =
25//! perf_file.event_attributes().iter().filter_map(AttributeDescription::name).collect();
26//! println!("perf events: {}", event_names.join(", "));
27//!
28//! while let Some(record) = record_iter.next_record(&mut perf_file)? {
29//! match record {
30//! PerfFileRecord::EventRecord { attr_index, record } => {
31//! let record_type = record.record_type;
32//! let parsed_record = record.parse()?;
33//! println!("{:?} for event {}: {:?}", record_type, attr_index, parsed_record);
34//! }
35//! PerfFileRecord::UserRecord(record) => {
36//! let record_type = record.record_type;
37//! let parsed_record = record.parse()?;
38//! println!("{:?}: {:?}", record_type, parsed_record);
39//! }
40//! }
41//! }
42//! # Ok(())
43//! # }
44//! ```
45//!
46//! # Pipe Mode Example
47//!
48//! Parse perf.data from a stream (e.g., stdin, pipe - requires only `Read`):
49//!
50//! ```no_run
51//! use linux_perf_data::{PerfFileReader, PerfFileRecord};
52//!
53//! # fn wrapper() -> Result<(), linux_perf_data::Error> {
54//! let stdin = std::io::stdin();
55//! let PerfFileReader { mut perf_file, mut record_iter } = PerfFileReader::parse_pipe(stdin)?;
56//!
57//! while let Some(record) = record_iter.next_record(&mut perf_file)? {
58//! // Process records...
59//! # let _ = record;
60//! }
61//! # Ok(())
62//! # }
63//! ```
64
65mod auxtrace;
66mod build_id_event;
67mod constants;
68#[cfg(feature = "zstd")]
69mod decompression;
70mod dso_info;
71mod dso_key;
72mod error;
73mod feature_sections;
74mod features;
75mod file_reader;
76mod header;
77pub mod jitdump;
78mod perf_file;
79mod record;
80mod section;
81mod simpleperf;
82mod sorter;
83mod thread_map;
84
85/// This is a re-export of the linux-perf-event-reader crate. We use its types
86/// in our public API.
87pub use linux_perf_event_reader;
88
89/// This is a re-export of the `prost` crate. We use its types in our public API.
90pub use prost;
91
92pub use linux_perf_event_reader::Endianness;
93
94pub use auxtrace::Auxtrace;
95pub use dso_info::DsoInfo;
96pub use dso_key::DsoKey;
97pub use error::{Error, ReadError};
98pub use feature_sections::{AttributeDescription, CompressionInfo, NrCpus, SampleTimeRange};
99pub use features::{Feature, FeatureSet, FeatureSetIter};
100pub use file_reader::{PerfFileReader, PerfRecordIter};
101pub use perf_file::PerfFile;
102pub use record::{
103 HeaderAttr, HeaderFeature, PerfFileRecord, RawUserRecord, UserRecord, UserRecordType,
104};
105pub use simpleperf::{
106 simpleperf_dso_type, SimpleperfDexFileInfo, SimpleperfElfFileInfo, SimpleperfFileRecord,
107 SimpleperfKernelModuleInfo, SimpleperfSymbol, SimpleperfTypeSpecificInfo,
108};
109pub use thread_map::ThreadMap;