use bitflags::bitflags;
use crate::sys::bindings;
use crate::{Builder, ReadFormat, SampleFlag};
used_in_docs!(Builder);
used_in_docs!(SampleFlag);
pub(crate) trait ReadFormatExt: Sized {
const MAX_NON_GROUP_SIZE: usize;
fn prefix_len(&self) -> usize;
fn element_len(&self) -> usize;
}
impl ReadFormatExt for ReadFormat {
const MAX_NON_GROUP_SIZE: usize = Self::all() .difference(Self::GROUP)
.bits()
.count_ones() as usize
+ 1;
fn prefix_len(&self) -> usize {
1 + (*self & (Self::TOTAL_TIME_ENABLED | Self::TOTAL_TIME_RUNNING))
.bits()
.count_ones() as usize
}
fn element_len(&self) -> usize {
1 + (*self & (Self::ID | Self::LOST)).bits().count_ones() as usize
}
}
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
pub enum SampleSkid {
Arbitrary = 0,
Constant = 1,
RequestZero = 2,
RequireZero = 3,
}
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
#[repr(transparent)]
pub struct Clock(libc::clockid_t);
impl Clock {
pub const TAI: Self = Self::new(libc::CLOCK_TAI);
pub const REALTIME: Self = Self::new(libc::CLOCK_REALTIME);
pub const BOOTTIME: Self = Self::new(libc::CLOCK_BOOTTIME);
pub const MONOTONIC: Self = Self::new(libc::CLOCK_MONOTONIC);
pub const MONOTONIC_RAW: Self = Self::new(libc::CLOCK_MONOTONIC_RAW);
}
impl Clock {
pub const fn new(clockid: libc::clockid_t) -> Self {
Self(clockid)
}
pub const fn into_raw(self) -> libc::clockid_t {
self.0
}
}
bitflags! {
pub struct SampleBranchFlag: u64 {
const USER = bindings::PERF_SAMPLE_BRANCH_USER as _;
const KERNEL = bindings::PERF_SAMPLE_BRANCH_KERNEL as _;
const HV = bindings::PERF_SAMPLE_BRANCH_HV as _;
const ANY = bindings::PERF_SAMPLE_BRANCH_ANY as _;
const ANY_CALL = bindings::PERF_SAMPLE_BRANCH_ANY_CALL as _;
const IND_CALL = bindings::PERF_SAMPLE_BRANCH_IND_CALL as _;
const CALL = bindings::PERF_SAMPLE_BRANCH_CALL as _;
const ANY_RETURN = bindings::PERF_SAMPLE_BRANCH_ANY_RETURN as _;
const IND_JUMP = bindings::PERF_SAMPLE_BRANCH_IND_JUMP as _;
const COND = bindings::PERF_SAMPLE_BRANCH_COND as _;
const ABORT_TX = bindings::PERF_SAMPLE_BRANCH_ABORT_TX as _;
const IN_TX = bindings::PERF_SAMPLE_BRANCH_IN_TX as _;
const NO_TX = bindings::PERF_SAMPLE_BRANCH_NO_TX as _;
const CALL_STACK = bindings::PERF_SAMPLE_BRANCH_CALL_STACK as _;
}
}
impl SampleBranchFlag {
pub const PLM_ALL: Self = Self::USER.union(Self::KERNEL).union(Self::HV);
}