use perf_event_open_sys::bindings::PERF_RECORD_MISC_SWITCH_OUT;
use crate::prelude::*;
#[derive(Copy, Clone, Debug)]
pub enum SwitchCpuWide {
In {
pid: u32,
tid: u32,
},
Out {
pid: u32,
tid: u32,
},
}
impl SwitchCpuWide {
pub fn pid(&self) -> u32 {
match *self {
Self::In { pid, .. } | Self::Out { pid, .. } => pid,
}
}
pub fn tid(&self) -> u32 {
match *self {
Self::In { tid, .. } | Self::Out { tid, .. } => tid,
}
}
}
impl<'p> Parse<'p> for SwitchCpuWide {
fn parse<B, E>(p: &mut Parser<B, E>) -> ParseResult<Self>
where
E: Endian,
B: ParseBuf<'p>,
{
let pid = p.parse()?;
let tid = p.parse()?;
if p.config().misc() & PERF_RECORD_MISC_SWITCH_OUT as u16 != 0 {
Ok(Self::Out { pid, tid })
} else {
Ok(Self::In { pid, tid })
}
}
}