Commit 619fc140 authored by Sasha Goldshtein's avatar Sasha Goldshtein

bcc: Auto-tracepoints similar to auto-kprobes

When a function in the BPF program starts with "tracepoint__", parse
the rest of the name as a tracepoint category and name and attach the
tracepoint automatically. For example:

```
int tracepoint__sched__sched_switch(...)
```

As a result, the sched:sched_switch tracepoint is enabled and the function
is attached to that tracepoint.
parent 52cd3713
...@@ -608,17 +608,21 @@ class BPF(object): ...@@ -608,17 +608,21 @@ class BPF(object):
del open_uprobes[ev_name] del open_uprobes[ev_name]
def _trace_autoload(self): def _trace_autoload(self):
# Cater to one-liner case where attach_kprobe is omitted and C function for i in range(0, lib.bpf_num_functions(self.module)):
# name matches that of the kprobe. func_name = lib.bpf_function_name(self.module, i).decode()
if len(open_kprobes) == 0: if func_name.startswith("kprobe__"):
for i in range(0, lib.bpf_num_functions(self.module)): fn = self.load_func(func_name, BPF.KPROBE)
func_name = lib.bpf_function_name(self.module, i).decode() self.attach_kprobe(event=fn.name[8:], fn_name=fn.name)
if func_name.startswith("kprobe__"): elif func_name.startswith("kretprobe__"):
fn = self.load_func(func_name, BPF.KPROBE) fn = self.load_func(func_name, BPF.KPROBE)
self.attach_kprobe(event=fn.name[8:], fn_name=fn.name) self.attach_kretprobe(event=fn.name[11:], fn_name=fn.name)
elif func_name.startswith("kretprobe__"): elif func_name.startswith("tracepoint__"):
fn = self.load_func(func_name, BPF.KPROBE) fn = self.load_func(func_name, BPF.TRACEPOINT)
self.attach_kretprobe(event=fn.name[11:], fn_name=fn.name) tp = fn.name[len("tracepoint__"):].replace("__", ":")
self.attach_tracepoint(tp=tp, fn_name=fn.name)
# It would be nice to automatically generate the tracepont
# structure here, but once we passed the load of the BPF program,
# we can't do that anymore. It will have to go in the clang rewriter.
def trace_open(self, nonblocking=False): def trace_open(self, nonblocking=False):
"""trace_open(nonblocking=False) """trace_open(nonblocking=False)
......
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