in src/samplers/scheduler/mod.rs [44:89]
fn new(common: Common) -> Result<Self, anyhow::Error> {
let fault_tolerant = common.config.general().fault_tolerant();
let statistics = common.config().samplers().scheduler().statistics();
#[allow(unused_mut)]
let mut sampler = Self {
bpf: None,
bpf_last: Arc::new(Mutex::new(Instant::now())),
common,
perf: None,
proc_stat: None,
statistics,
};
if sampler.sampler_config().enabled() {
sampler.register();
}
if let Err(e) = sampler.initialize_bpf() {
error!("failed to initialize bpf: {}", e);
if !fault_tolerant {
return Err(e);
}
}
// 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() {
error!("failed to initializing bpf perf: {}", e);
if !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)
}