from time import sleep
b = BPF(src_file="task_switch.c")
-fn = b.load_func("count_sched", BPF.KPROBE)
-stats = b.get_table("stats")
-BPF.attach_kprobe(fn, "finish_task_switch")
+b.attach_kprobe(event="finish_task_switch", fn_name="count_sched")
# generate many schedule events
for i in range(0, 100): sleep(0.01)
-for k, v in stats.items():
+for k, v in b["stats"].items():
print("task_switch[%5d->%5d]=%u" % (k.prev_pid, k.curr_pid, v.value))
```
[Source code listing](examples/task_switch.py)
from time import sleep
b = BPF(src_file="task_switch.c")
-stats = b.get_table("stats")
b.attach_kprobe(event="finish_task_switch", fn_name="count_sched")
# generate many schedule events
for i in range(0, 100): sleep(0.01)
-for k, v in stats.items():
+for k, v in b["stats"].items():
print("task_switch[%5d->%5d]=%u" % (k.prev_pid, k.curr_pid, v.value))