perf-event-open 0.5.0

Full-featured support for the `perf_event_open` syscall.
Documentation
pub mod bp;
pub mod dp;
pub mod hw;
pub mod raw;
pub mod sw;
pub mod tp;

/// Unified event type.
///
/// Different events can be converted to this type to get a unified representation.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct Event(pub(super) EventConfig);

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub(super) struct EventConfig {
    pub ty: u32,
    pub config: u64,
    pub config1: u64,
    pub config2: u64,
    pub config3: u64,
    pub bp_type: u32,
}

macro_rules! try_from {
    ($ty:ty, $value:ident, $impl: expr) => {
        impl TryFrom<&$ty> for crate::event::Event {
            type Error = std::io::Error;

            fn try_from($value: &$ty) -> std::result::Result<Self, Self::Error> {
                $impl
            }
        }

        impl TryFrom<$ty> for crate::event::Event {
            type Error = std::io::Error;

            fn try_from(value: $ty) -> std::result::Result<Self, Self::Error> {
                (&value).try_into()
            }
        }
    };
}
use try_from;