Alexei Starovoitov | b6e43a2 | 2015-06-18 14:41:17 -0700 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | # Copyright (c) PLUMgrid, Inc. |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License") |
| 4 | |
Brenden Blanco | c35989d | 2015-09-02 18:04:07 -0700 | [diff] [blame] | 5 | from bcc import BPF |
Alexei Starovoitov | b6e43a2 | 2015-06-18 14:41:17 -0700 | [diff] [blame] | 6 | from time import sleep |
| 7 | |
| 8 | b = BPF(src_file="task_switch.c") |
Brenden Blanco | 5eef65e | 2015-08-19 15:39:19 -0700 | [diff] [blame] | 9 | b.attach_kprobe(event="finish_task_switch", fn_name="count_sched") |
Alexei Starovoitov | b6e43a2 | 2015-06-18 14:41:17 -0700 | [diff] [blame] | 10 | |
| 11 | # generate many schedule events |
| 12 | for i in range(0, 100): sleep(0.01) |
| 13 | |
Brenden Blanco | c8b6698 | 2015-08-28 23:15:19 -0700 | [diff] [blame] | 14 | for k, v in b["stats"].items(): |
Alexei Starovoitov | b6e43a2 | 2015-06-18 14:41:17 -0700 | [diff] [blame] | 15 | print("task_switch[%5d->%5d]=%u" % (k.prev_pid, k.curr_pid, v.value)) |