use super::RecordId;
#[derive(Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Aux {
pub record_id: Option<RecordId>,
pub offset: u64,
pub size: u64,
pub truncated: bool,
pub overwrite: bool,
pub partial: bool,
pub collision: bool,
pub pmu_format_type: u8,
}
impl Aux {
#[cfg(feature = "linux-4.1")]
pub(crate) unsafe fn from_ptr(
mut ptr: *const u8,
sample_id_all: Option<super::SampleType>,
) -> Self {
use crate::ffi::{bindings as b, deref_offset};
let offset = deref_offset(&mut ptr);
let size = deref_offset(&mut ptr);
let flags: u64 = deref_offset(&mut ptr);
macro_rules! when {
($($feature: literal,)? $flag:ident) => {{
$(#[cfg(feature = $feature)])?
let val = flags & b::$flag as u64 > 0;
$(
#[cfg(not(feature = $feature))]
let val = false;
)?
val
}};
}
let truncated = when!(PERF_AUX_FLAG_TRUNCATED);
let overwrite = when!(PERF_AUX_FLAG_OVERWRITE);
let partial = when!("linux-4.12", PERF_AUX_FLAG_PARTIAL);
let collision = when!("linux-4.15", PERF_AUX_FLAG_COLLISION);
#[cfg(feature = "linux-5.13")]
let pmu_format_type = {
let masked = flags & b::PERF_AUX_FLAG_PMU_FORMAT_TYPE_MASK as u64;
(masked >> 8) as _
};
#[cfg(not(feature = "linux-5.13"))]
let pmu_format_type = 0;
let record_id = sample_id_all.map(|super::SampleType(ty)| RecordId::from_ptr(ptr, ty));
Self {
record_id,
offset,
size,
truncated,
overwrite,
partial,
collision,
pmu_format_type,
}
}
}
super::from!(Aux);
super::debug!(Aux {
{record_id?},
{offset},
{size},
{truncated},
{overwrite},
{partial},
{collision},
{pmu_format_type},
});
#[derive(Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct AuxOutputHwId {
pub record_id: Option<RecordId>,
pub hw_id: u64,
}
impl AuxOutputHwId {
#[cfg(feature = "linux-5.16")]
pub(crate) unsafe fn from_ptr(
mut ptr: *const u8,
sample_id_all: Option<super::SampleType>,
) -> Self {
use crate::ffi::deref_offset;
let hw_id = deref_offset(&mut ptr);
let record_id = sample_id_all.map(|super::SampleType(ty)| RecordId::from_ptr(ptr, ty));
Self { record_id, hw_id }
}
}
super::from!(AuxOutputHwId);
super::debug!(AuxOutputHwId {
{record_id?},
{hw_id},
});