xref: /aosp_15_r20/external/bcc/tests/python/test_trace2.c (revision 387f9dfdfa2baef462e92476d413c7bc2470293e)
1*387f9dfdSAndroid Build Coastguard Worker // Copyright (c) PLUMgrid, Inc.
2*387f9dfdSAndroid Build Coastguard Worker // Licensed under the Apache License, Version 2.0 (the "License")
3*387f9dfdSAndroid Build Coastguard Worker #include <linux/ptrace.h>
4*387f9dfdSAndroid Build Coastguard Worker struct Ptr { u64 ptr; };
5*387f9dfdSAndroid Build Coastguard Worker struct Counters { u64 stat1; };
6*387f9dfdSAndroid Build Coastguard Worker BPF_HASH(stats, struct Ptr, struct Counters, 1024);
7*387f9dfdSAndroid Build Coastguard Worker 
count_sched(struct pt_regs * ctx)8*387f9dfdSAndroid Build Coastguard Worker int count_sched(struct pt_regs *ctx) {
9*387f9dfdSAndroid Build Coastguard Worker   struct Ptr key = {.ptr = PT_REGS_PARM1(ctx)};
10*387f9dfdSAndroid Build Coastguard Worker   struct Counters zleaf = {0};
11*387f9dfdSAndroid Build Coastguard Worker   struct Counters *val = stats.lookup_or_try_init(&key, &zleaf);
12*387f9dfdSAndroid Build Coastguard Worker   if (val) {
13*387f9dfdSAndroid Build Coastguard Worker     val->stat1++;
14*387f9dfdSAndroid Build Coastguard Worker   }
15*387f9dfdSAndroid Build Coastguard Worker   return 0;
16*387f9dfdSAndroid Build Coastguard Worker }
17