perf_event_data/records/
aux_record.rs

1use bitflags::bitflags;
2use perf_event_open_sys::bindings;
3
4use crate::prelude::*;
5
6/// AUX records indicate that new data is available in the aux buffer region.
7///
8/// This struct corresponds to `PERF_RECORD_AUX`. See the [manpage] for more
9/// documentation.
10///
11/// [manpage]: http://man7.org/linux/man-pages/man2/perf_event_open.2.html
12#[derive(Clone, Debug)]
13#[allow(missing_docs)]
14pub struct Aux {
15    pub aux_offset: u64,
16    pub aux_size: u64,
17    pub flags: AuxFlags,
18}
19
20bitflags! {
21    /// Flags describing the aux buffer update.
22    ///
23    /// Some flags are documented in the [manpage], others are not yet
24    /// documented in the manpage but are instead documented in the [source].
25    ///
26    /// [manpage]: http://man7.org/linux/man-pages/man2/perf_event_open.2.html
27    /// [source]: https://sourcegraph.com/github.com/torvalds/linux@eb7081409f94a9a8608593d0fb63a1aa3d6f95d8/-/blob/tools/include/uapi/linux/perf_event.h?L1248
28    #[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
29    pub struct AuxFlags : u64 {
30        /// The data returned was truncated to fit within the buffer size.
31        const TRUNCATED = bindings::PERF_AUX_FLAG_TRUNCATED as _;
32
33        /// The data returned overwrote previous data.
34        const OVERWRITE = bindings::PERF_AUX_FLAG_OVERWRITE as _;
35
36        /// The record contains gaps.
37        const PARTIAL = bindings::PERF_AUX_FLAG_PARTIAL as _;
38
39        /// The aux sample collided with another.
40        const COLLISION = bindings::PERF_AUX_FLAG_COLLISION as _;
41
42        /// Certain bits actually contain a [`AuxPmuFormat`] enum.
43        const PMU_FORMAT_MASK = bindings::PERF_AUX_FLAG_PMU_FORMAT_TYPE_MASK as _;
44    }
45}
46
47c_enum! {
48    /// PMU-specific trace format type
49    #[derive(Copy, Clone, Eq, PartialEq, Hash)]
50    pub enum AuxPmuFormatType : u8 {
51        CORESIGHT = (bindings::PERF_AUX_FLAG_CORESIGHT_FORMAT_CORESIGHT >> 8) as _,
52        CORESIGHT_RAW = (bindings::PERF_AUX_FLAG_CORESIGHT_FORMAT_RAW >> 8) as _,
53    }
54
55    #[allow(missing_docs)]
56    impl {}
57}
58
59impl AuxPmuFormatType {
60    /// Create a new `AuxPmuFormatType`.
61    pub const fn new(value: u8) -> Self {
62        Self(value)
63    }
64}
65
66impl AuxFlags {
67    /// PMU-specific trace format type.
68    pub fn pmu_format_type(&self) -> AuxPmuFormatType {
69        AuxPmuFormatType(((*self & Self::PMU_FORMAT_MASK).bits() >> 8) as u8)
70    }
71}
72
73impl<'p> Parse<'p> for Aux {
74    fn parse<B, E>(p: &mut Parser<B, E>) -> ParseResult<Self>
75    where
76        E: Endian,
77        B: ParseBuf<'p>,
78    {
79        Ok(Self {
80            aux_offset: p.parse()?,
81            aux_size: p.parse()?,
82            flags: p.parse()?,
83        })
84    }
85}
86
87impl<'p> Parse<'p> for AuxFlags {
88    fn parse<B, E>(p: &mut Parser<B, E>) -> ParseResult<Self>
89    where
90        E: Endian,
91        B: ParseBuf<'p>,
92    {
93        p.parse().map(Self::from_bits_retain)
94    }
95}