in src/samplers/cpu/mod.rs [54:92]
fn new(common: Common) -> Result<Self, anyhow::Error> {
let statistics = common.config().samplers().cpu().statistics();
#[allow(unused_mut)]
let mut sampler = Self {
common,
cpus: HashSet::new(),
cstates: HashMap::new(),
cstate_files: HashMap::new(),
perf: None,
tick_duration: nanos_per_tick(),
proc_cpuinfo: None,
proc_stat: None,
statistics,
};
if sampler.sampler_config().enabled() {
sampler.register();
}
// we initialize perf last so we can delay
if sampler.sampler_config().enabled() && sampler.sampler_config().perf_events() {
#[cfg(feature = "bpf")]
{
if let Err(e) = sampler.initialize_bpf_perf() {
if !sampler.common().config().general().fault_tolerant() {
return Err(format_err!("bpf perf init failure: {}", e));
}
}
}
}
// delay by half the sample interval so that we land between perf
// counter updates
std::thread::sleep(std::time::Duration::from_micros(
(1000 * sampler.interval()) as u64 / 2,
));
Ok(sampler)
}