use super::RecordId;
#[cfg(feature = "linux-5.1")]
const BPF_TAG_SIZE: u32 = crate::ffi::bindings::BPF_TAG_SIZE;
#[cfg(not(feature = "linux-5.1"))]
const BPF_TAG_SIZE: u32 = 8;
#[derive(Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct BpfEvent {
pub record_id: Option<RecordId>,
pub ty: Type,
pub id: u32,
pub tag: [u8; BPF_TAG_SIZE as _],
pub flags: u16,
}
impl BpfEvent {
#[cfg(feature = "linux-5.1")]
pub(crate) unsafe fn from_ptr(
mut ptr: *const u8,
sample_id_all: Option<super::SampleType>,
) -> Self {
use super::SampleType;
use crate::ffi::{bindings as b, deref_offset};
let ty = match deref_offset::<u16>(&mut ptr) as _ {
b::PERF_BPF_EVENT_PROG_LOAD => Type::ProgLoad,
b::PERF_BPF_EVENT_PROG_UNLOAD => Type::ProgUnload,
b::PERF_BPF_EVENT_UNKNOWN => Type::Unknown,
_ => Type::Unknown, };
let flags = deref_offset(&mut ptr);
let id = deref_offset(&mut ptr);
let tag = deref_offset(&mut ptr);
let record_id = sample_id_all.map(|SampleType(ty)| RecordId::from_ptr(ptr, ty));
Self {
record_id,
ty,
id,
tag,
flags,
}
}
}
super::from!(BpfEvent);
super::debug!(BpfEvent {
{record_id?},
{ty},
{id},
{tag},
{flags},
});
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Type {
ProgLoad,
ProgUnload,
Unknown,
}