mod kp;
mod up;
use std::fs::File;
use std::io::{Error, Read, Result, Seek, SeekFrom};
use std::path::Path;
pub use kp::*;
use thiserror::Error;
pub use up::*;
use super::EventConfig;
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct DynamicPmu {
pub ty: u32,
pub config: u64,
pub config1: u64,
pub config2: u64,
pub config3: u64,
}
fn get_type<P>(path: P) -> Result<u32>
where
P: AsRef<Path>,
{
let mut file = File::open(path)?;
let mut acc = Vec::with_capacity(1);
let mut buf = [0];
while file.read(&mut buf)? > 0 {
if buf[0] == b'\n' {
break;
}
acc.extend(buf);
}
let bit = unsafe { std::str::from_utf8_unchecked(&acc) };
bit.parse::<u32>().map_err(Error::other)
}
fn get_retprobe_bit<P>(path: P) -> Result<u8>
where
P: AsRef<Path>,
{
let mut file = File::open(path)?;
file.seek(SeekFrom::Start("config:".len() as _))?;
let mut acc = Vec::with_capacity(1);
let mut buf = [0];
while file.read(&mut buf)? > 0 {
if buf[0] == b'\n' {
break;
}
acc.extend(buf);
}
let bit = unsafe { std::str::from_utf8_unchecked(&acc) };
bit.parse::<u8>().map_err(Error::other)
}
super::try_from!(DynamicPmu, value, {
let event_cfg = EventConfig {
ty: value.ty,
config: value.config,
config1: value.config1,
config2: value.config2,
config3: value.config3,
bp_type: 0,
};
Ok(Self(event_cfg))
});