fn ebpf_counters()

in nfm-controller/src/events/event_provider_ebpf.rs [310:329]


    fn ebpf_counters(&mut self) -> EventCounters {
        let data: PerCpuHashMap<&MapData, SingletonKey, EventCounters> =
            PerCpuHashMap::try_from(self.ebpf_handle.map(NFM_COUNTERS_MAP_NAME).unwrap())
                .unwrap_or_else(|_| panic!("Failed to load BPF map {}", NFM_COUNTERS_MAP_NAME));

        let mut new_counters = EventCounters::default();
        const EMPTY_FLAGS: u64 = 0;
        if let Ok(counters_per_cpu) = data.get(&SINGLETON_KEY, EMPTY_FLAGS) {
            for counters in (*counters_per_cpu).iter() {
                new_counters.add_from(counters);
            }
        }

        // eBPF counters continue accumulating.  The difference from our last set of counters
        // represents new counts.
        let delta_counts = new_counters.subtract(&self.ebpf_counters_latest);
        self.ebpf_counters_latest = new_counters;

        delta_counts
    }