You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
499 B
24 lines
499 B
#include <uapi/linux/ptrace.h>
|
|
#include <linux/sched.h>
|
|
|
|
struct key_t {
|
|
u32 prev_pid;
|
|
u32 curr_pid;
|
|
};
|
|
|
|
BPF_HASH(stats, struct key_t, u64, 1024);
|
|
int count_sched(struct pt_regs *ctx, struct task_struct *prev) {
|
|
struct key_t key = {};
|
|
u64 zero = 0, *val;
|
|
|
|
key.curr_pid = bpf_get_current_pid_tgid();
|
|
key.prev_pid = prev->pid;
|
|
|
|
// could also use `stats.increment(key);`
|
|
val = stats.lookup_or_try_init(&key, &zero);
|
|
if (val) {
|
|
(*val)++;
|
|
}
|
|
return 0;
|
|
}
|