Commit f52dc883 authored by 4ast's avatar 4ast

Merge pull request #171 from iovisor/bblanco_dev

Minor change to task_switch example syntax
parents b186900f c8b66980
...@@ -162,14 +162,12 @@ from bpf import BPF ...@@ -162,14 +162,12 @@ from bpf import BPF
from time import sleep from time import sleep
b = BPF(src_file="task_switch.c") b = BPF(src_file="task_switch.c")
fn = b.load_func("count_sched", BPF.KPROBE) b.attach_kprobe(event="finish_task_switch", fn_name="count_sched")
stats = b.get_table("stats")
BPF.attach_kprobe(fn, "finish_task_switch")
# generate many schedule events # generate many schedule events
for i in range(0, 100): sleep(0.01) 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)) print("task_switch[%5d->%5d]=%u" % (k.prev_pid, k.curr_pid, v.value))
``` ```
[Source code listing](examples/task_switch.py) [Source code listing](examples/task_switch.py)
......
...@@ -6,11 +6,10 @@ from bpf import BPF ...@@ -6,11 +6,10 @@ from bpf import BPF
from time import sleep from time import sleep
b = BPF(src_file="task_switch.c") b = BPF(src_file="task_switch.c")
stats = b.get_table("stats")
b.attach_kprobe(event="finish_task_switch", fn_name="count_sched") b.attach_kprobe(event="finish_task_switch", fn_name="count_sched")
# generate many schedule events # generate many schedule events
for i in range(0, 100): sleep(0.01) 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)) print("task_switch[%5d->%5d]=%u" % (k.prev_pid, k.curr_pid, v.value))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment