Commit fd244056 authored by Teng Qin's avatar Teng Qin

Clean Python interface arguments for tracing events

parent b68e67b4
......@@ -499,8 +499,7 @@ class BPF(object):
del self.open_kprobes[name]
_num_open_probes -= 1
def attach_kprobe(self, event="", fn_name="", event_re="",
pid=-1, cpu=0, group_fd=-1):
def attach_kprobe(self, event="", fn_name="", event_re=""):
# allow the caller to glob multiple functions together
if event_re:
......@@ -508,8 +507,7 @@ class BPF(object):
self._check_probe_quota(len(matches))
for line in matches:
try:
self.attach_kprobe(event=line, fn_name=fn_name, pid=pid,
cpu=cpu, group_fd=group_fd)
self.attach_kprobe(event=line, fn_name=fn_name)
except:
pass
return
......@@ -538,15 +536,13 @@ class BPF(object):
raise Exception("Failed to detach BPF from kprobe")
self._del_kprobe(ev_name)
def attach_kretprobe(self, event="", fn_name="", event_re="",
pid=-1, cpu=0, group_fd=-1):
def attach_kretprobe(self, event="", fn_name="", event_re=""):
# allow the caller to glob multiple functions together
if event_re:
for line in BPF.get_kprobe_functions(event_re):
try:
self.attach_kretprobe(event=line, fn_name=fn_name, pid=pid,
cpu=cpu, group_fd=group_fd)
self.attach_kretprobe(event=line, fn_name=fn_name)
except:
pass
return
......@@ -648,10 +644,8 @@ class BPF(object):
results.append(tp)
return results
def attach_tracepoint(self, tp="", tp_re="", fn_name="", pid=-1,
cpu=0, group_fd=-1):
"""attach_tracepoint(tp="", tp_re="", fn_name="", pid=-1,
cpu=0, group_fd=-1)
def attach_tracepoint(self, tp="", tp_re="", fn_name=""):
"""attach_tracepoint(tp="", tp_re="", fn_name="")
Run the bpf function denoted by fn_name every time the kernel tracepoint
specified by 'tp' is hit. The optional parameters pid, cpu, and group_fd
......@@ -673,8 +667,7 @@ class BPF(object):
if tp_re:
for tp in BPF.get_tracepoints(tp_re):
self.attach_tracepoint(tp=tp, fn_name=fn_name, pid=pid,
cpu=cpu, group_fd=group_fd)
self.attach_tracepoint(tp=tp, fn_name=fn_name)
return
fn = self.load_func(fn_name, BPF.TRACEPOINT)
......@@ -794,9 +787,9 @@ class BPF(object):
return "%s_%s_0x%x_%d" % (prefix, self._probe_repl.sub("_", path), addr, pid)
def attach_uprobe(self, name="", sym="", sym_re="", addr=None,
fn_name="", pid=-1, cpu=0, group_fd=-1):
fn_name="", pid=-1):
"""attach_uprobe(name="", sym="", sym_re="", addr=None, fn_name=""
pid=-1, cpu=0, group_fd=-1)
pid=-1)
Run the bpf function denoted by fn_name every time the symbol sym in
the library or binary 'name' is encountered. The real address addr may
......@@ -823,8 +816,7 @@ class BPF(object):
self._check_probe_quota(len(addresses))
for sym_addr in addresses:
self.attach_uprobe(name=name, addr=sym_addr,
fn_name=fn_name, pid=pid, cpu=cpu,
group_fd=group_fd)
fn_name=fn_name, pid=pid)
return
(path, addr) = BPF._check_path_symbol(name, sym, addr, pid)
......@@ -860,9 +852,9 @@ class BPF(object):
self._del_uprobe(ev_name)
def attach_uretprobe(self, name="", sym="", sym_re="", addr=None,
fn_name="", pid=-1, cpu=0, group_fd=-1):
fn_name="", pid=-1):
"""attach_uretprobe(name="", sym="", sym_re="", addr=None, fn_name=""
pid=-1, cpu=0, group_fd=-1)
pid=-1)
Run the bpf function denoted by fn_name every time the symbol sym in
the library or binary 'name' finishes execution. See attach_uprobe for
......@@ -872,8 +864,7 @@ class BPF(object):
if sym_re:
for sym_addr in BPF.get_user_addresses(name, sym_re):
self.attach_uretprobe(name=name, addr=sym_addr,
fn_name=fn_name, pid=pid, cpu=cpu,
group_fd=group_fd)
fn_name=fn_name, pid=pid)
return
name = str(name)
......
......@@ -27,9 +27,9 @@ class TestKprobe(TestCase):
def setUp(self):
b = BPF(arg1, arg2, debug=0)
self.stats = b.get_table("stats", Key, Leaf)
b.attach_kprobe(event="sys_write", fn_name="sys_wr", pid=0, cpu=-1)
b.attach_kprobe(event="sys_read", fn_name="sys_rd", pid=0, cpu=-1)
b.attach_kprobe(event="htab_map_get_next_key", fn_name="sys_rd", pid=0, cpu=-1)
b.attach_kprobe(event="sys_write", fn_name="sys_wr")
b.attach_kprobe(event="sys_read", fn_name="sys_rd")
b.attach_kprobe(event="htab_map_get_next_key", fn_name="sys_rd")
def test_trace1(self):
with open("/dev/null", "a") as f:
......
......@@ -28,7 +28,7 @@ class TestTracingEvent(TestCase):
def setUp(self):
b = BPF(text=text, debug=0)
self.stats = b.get_table("stats")
b.attach_kprobe(event="finish_task_switch", fn_name="count_sched", pid=0, cpu=-1)
b.attach_kprobe(event="finish_task_switch", fn_name="count_sched")
def test_sched1(self):
for i in range(0, 100):
......
......@@ -19,9 +19,9 @@ class TestBlkRequest(TestCase):
b = BPF(arg1, arg2, debug=0)
self.latency = b.get_table("latency", c_uint, c_ulong)
b.attach_kprobe(event="blk_start_request",
fn_name="probe_blk_start_request", pid=-1, cpu=0)
fn_name="probe_blk_start_request")
b.attach_kprobe(event="blk_update_request",
fn_name="probe_blk_update_request", pid=-1, cpu=0)
fn_name="probe_blk_update_request")
def test_blk1(self):
import subprocess
......
......@@ -468,9 +468,7 @@ def main():
bpf = BPF(src_file='deadlock_detector.c')
# Trace where threads are created
bpf.attach_kretprobe(
event='sys_clone', fn_name='trace_clone', pid=args.pid
)
bpf.attach_kretprobe(event='sys_clone', fn_name='trace_clone')
# We must trace unlock first, otherwise in the time we attached the probe
# on lock() and have not yet attached the probe on unlock(), a thread can
......
......@@ -90,8 +90,7 @@ class Probe(object):
for index, function in self.trace_functions.items():
self.bpf.attach_kprobe(
event=function,
fn_name="trace_count_%d" % index,
pid=self.pid or -1)
fn_name="trace_count_%d" % index)
elif self.type == "p" and self.library:
for index, function in self.trace_functions.items():
self.bpf.attach_uprobe(
......@@ -103,8 +102,7 @@ class Probe(object):
for index, function in self.trace_functions.items():
self.bpf.attach_tracepoint(
tp=function,
fn_name="trace_count_%d" % index,
pid=self.pid or -1)
fn_name="trace_count_%d" % index)
elif self.type == "u":
pass # Nothing to do -- attach already happened in `load`
......
......@@ -90,13 +90,11 @@ class Probe(object):
self.matched = self.bpf.num_open_uprobes()
else:
self.bpf.attach_kprobe(event_re=self.pattern,
fn_name="trace_count",
pid=self.pid or -1)
fn_name="trace_count")
self.matched = self.bpf.num_open_kprobes()
elif self.type == "t":
self.bpf.attach_tracepoint(tp_re=self.pattern,
fn_name="trace_count",
pid=self.pid or -1)
fn_name="trace_count")
self.matched = self.bpf.num_open_tracepoints()
elif self.type == "u":
pass # Nothing to do -- attach already happened in `load`
......
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