fn sample_bpf()

in src/samplers/tcp/mod.rs [215:258]


    fn sample_bpf(&self) -> Result<(), std::io::Error> {
        if self.bpf_last.lock().unwrap().elapsed()
            >= Duration::from_secs(self.general_config().window() as u64)
        {
            if let Some(ref bpf) = self.bpf {
                let bpf = bpf.lock().unwrap();
                let time = Instant::now();
                for statistic in self.statistics.iter().filter(|s| s.bpf_table().is_some()) {
                    // if statistic is Counter
                    match statistic.source() {
                        Source::Counter => {
                            if let Ok(table) = &(*bpf).inner.table(statistic.bpf_table().unwrap()) {
                                let count = crate::common::bpf::parse_u64(
                                    table.iter().next().unwrap().value,
                                );
                                let _ = self.metrics().record_counter(statistic, time, count);
                            }
                        }
                        // if it's distribution
                        Source::Distribution => {
                            if let Ok(mut table) =
                                (*bpf).inner.table(statistic.bpf_table().unwrap())
                            {
                                for (&value, &count) in &map_from_table(&mut table) {
                                    if count > 0 {
                                        let _ = self.metrics().record_bucket(
                                            statistic,
                                            time,
                                            // in bpf everything is in micro, we convert it back to nano for alignment.
                                            value * 1000,
                                            count,
                                        );
                                    }
                                }
                            }
                        }
                        _ => (), // we do not support other types
                    }
                }
            }
            *self.bpf_last.lock().unwrap() = Instant::now();
        }
        Ok(())
    }