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