1 #include <uapi/linux/ptrace.h>
2 #include <linux/sched.h>
4 typedef struct pdata_T {
6 char buf[TASK_COMM_LEN];
12 BPF_HASH(timestamp_b, u64);
13 BPF_HASH(timestamp_e, u64);
14 BPF_HASH(stats, u32, pdata_t, sizeof(pdata_t));
15 BPF_HASH(run_start, u32);
16 BPF_HASH(wait_start, u32);
19 #define TAKE_PROCESS_DATA u64 time = 0; pdata_t pdata;\
20 pdata_t new_pdata = {0, ' ', 0, 0, 0};\
22 u32 pid = bpf_get_current_pid_tgid();\
23 ts = bpf_ktime_get_ns() / 1000;\
26 int do_entry(struct pt_regs *ctx) {
28 timestamp_b.insert(&time, &ts);
29 timestamp_e.update(&time, &ts);
30 tsp = run_start.lookup(&pid);
31 run_start.delete(&pid);
32 wait_start.update(&pid, &ts);
37 pdata = *(stats.lookup_or_init(&pid, &new_pdata));
39 bpf_get_current_comm(&(pdata.buf), sizeof(pdata.buf));
40 stats.update(&pid, &pdata);
44 int do_return(struct pt_regs *ctx) {
46 timestamp_b.insert(&time, &ts);
47 timestamp_e.update(&time, &ts);
48 tsp = wait_start.lookup(&pid);
49 wait_start.delete(&pid);
50 run_start.update(&pid, &ts);
55 pdata = *(stats.lookup_or_init(&pid, &new_pdata));
57 bpf_get_current_comm(&(pdata.buf), sizeof(pdata.buf));
58 stats.update(&pid, &pdata);