Change API of attach_kprobe to take a name argument
Per feedback on the attach_kprobe api, change up the arguments to remove
the load_func that typically preceeds the call. Instead, move this
inside the attach_kprobe implementation. Also, this makes attach_kprobe
need to be non-static. The same applies to attach_kretprobe.
Old:
fn = b.load_func("hello", BPF.KPROBE)
BPF.attach_kprobe(fn, "sys_clone")
New:
b.attach_kprobe(event="sys_clone", fn_name="hello")
Note that the kwarg style is not required, but I fixed up the current
usages to provide readability.
Signed-off-by: Brenden Blanco <bblanco@plumgrid.com>
diff --git a/examples/bitehist.py b/examples/bitehist.py
index 5662d4e..af4bb3b 100755
--- a/examples/bitehist.py
+++ b/examples/bitehist.py
@@ -39,7 +39,7 @@
# load BPF program
b = BPF(src_file = "bitehist.c")
-BPF.attach_kprobe(b.load_func("do_request", BPF.KPROBE), "blk_start_request")
+b.attach_kprobe(event="blk_start_request", fn_name="do_request")
dist = b.get_table("dist")
dist_max = 64
diff --git a/examples/disksnoop.py b/examples/disksnoop.py
index c9f4fb0..3dede56 100755
--- a/examples/disksnoop.py
+++ b/examples/disksnoop.py
@@ -18,8 +18,8 @@
# load BPF program
b = BPF(src_file="disksnoop.c")
-BPF.attach_kprobe(b.load_func("do_request", BPF.KPROBE), "blk_start_request")
-BPF.attach_kprobe(b.load_func("do_completion", BPF.KPROBE), "blk_update_request")
+b.attach_kprobe(event="blk_start_request", fn_name="do_request")
+b.attach_kprobe(event="blk_update_request", fn_name="do_completion")
# header
print("%-18s %-2s %-7s %8s" % ("TIME(s)", "T", "BYTES", "LAT(ms)"))
diff --git a/examples/hello_world.py b/examples/hello_world.py
index 00859b6..e46b2ca 100755
--- a/examples/hello_world.py
+++ b/examples/hello_world.py
@@ -15,8 +15,7 @@
};
"""
b = BPF(text=prog)
-fn = b.load_func("hello", BPF.KPROBE)
-BPF.attach_kprobe(fn, "sys_clone")
+b.attach_kprobe(event="sys_clone", fn_name="hello")
try:
call(["cat", "/sys/kernel/debug/tracing/trace_pipe"])
except KeyboardInterrupt:
diff --git a/examples/task_switch.py b/examples/task_switch.py
index f25913f..9eb4811 100755
--- a/examples/task_switch.py
+++ b/examples/task_switch.py
@@ -6,9 +6,8 @@
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)
diff --git a/examples/vfsreadlat.py b/examples/vfsreadlat.py
index 4707b03..da6a0d4 100755
--- a/examples/vfsreadlat.py
+++ b/examples/vfsreadlat.py
@@ -39,8 +39,8 @@
# load BPF program
b = BPF(src_file = "vfsreadlat.c")
-BPF.attach_kprobe(b.load_func("do_entry", BPF.KPROBE), "vfs_read")
-BPF.attach_kretprobe(b.load_func("do_return", BPF.KPROBE), "vfs_read")
+b.attach_kprobe(event="vfs_read", fn_name="do_entry")
+b.attach_kretprobe(event="vfs_read", fn_name="do_return")
dist = b.get_table("dist")
dist_max = 64