perf_event_data/records/
bpf_event.rs

1use crate::prelude::*;
2use perf_event_open_sys::bindings;
3
4/// BPF_EVENT records indicate when a BPF program is loaded or unloaded.
5///
6/// This struct corresponds to `PERF_RECORD_BPF_EVENT`. See the [manpage] for
7/// more documentation.
8///
9/// [manpage]: http://man7.org/linux/man-pages/man2/perf_event_open.2.html
10#[derive(Copy, Clone, Debug)]
11#[allow(missing_docs)]
12pub struct BpfEvent {
13    pub ty: BpfEventType,
14    pub flags: u16,
15    pub id: u32,
16    pub tag: [u8; 8],
17}
18
19c_enum! {
20    /// Indicates the type of a [`BpfEvent`]
21    #[derive(Copy, Clone, Eq, PartialEq, Hash)]
22    pub enum BpfEventType : u16 {
23        /// The event type is unknown.
24        UNKNOWN = bindings::PERF_BPF_EVENT_UNKNOWN as _,
25
26        /// A BPF program was loaded.
27        PROG_LOAD = bindings::PERF_BPF_EVENT_PROG_LOAD as _,
28
29        /// A BPF program was unloaded.
30        PROG_UNLOAD = bindings::PERF_BPF_EVENT_PROG_UNLOAD as _,
31    }
32}
33
34impl BpfEventType {
35    /// Create a new `BpfEventType`.
36    pub const fn new(value: u16) -> Self {
37        Self(value)
38    }
39}
40
41impl<'p> Parse<'p> for BpfEventType {
42    fn parse<B, E>(p: &mut Parser<B, E>) -> ParseResult<Self>
43    where
44        E: Endian,
45        B: ParseBuf<'p>,
46    {
47        Ok(Self::new(p.parse()?))
48    }
49}
50
51impl<'p> Parse<'p> for BpfEvent {
52    fn parse<B, E>(p: &mut Parser<B, E>) -> ParseResult<Self>
53    where
54        E: Endian,
55        B: ParseBuf<'p>,
56    {
57        Ok(Self {
58            ty: p.parse()?,
59            flags: p.parse()?,
60            id: p.parse()?,
61            tag: p.parse()?,
62        })
63    }
64}