github.com/castai/kvisor@v1.7.1-0.20240516114728-b3572a2607b5/pkg/ebpftracer/c/headers/common/stats.h (about)

     1  #ifndef __STATS_H__
     2  #define __STATS_H__
     3  
     4  #include <vmlinux.h>
     5  
     6  #include <types.h>
     7  #include <common/common.h>
     8  
     9  statfunc int update_syscall_stats(void *ctx, u64 cgroup_id, u64 syscall_id)
    10  {
    11      syscall_stats_key_t key = {};
    12      key.cgroup_id = cgroup_id;
    13      key.id = syscall_id;
    14  
    15      u64 *count = bpf_map_lookup_elem(&syscall_stats_map, &key);
    16      if (!count) {
    17          u64 initial_val = 1;
    18          bpf_map_update_elem(&syscall_stats_map, &key, &initial_val, BPF_ANY);
    19          return 0;
    20      }
    21      __sync_fetch_and_add(count, 1);
    22      return 0;
    23  }
    24  
    25  #endif