Skip to content

Commit

Permalink
bcc: Auto-tracepoints similar to auto-kprobes
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
goldshtn committed Jul 9, 2016
1 parent 52cd371 commit 619fc14
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/python/bcc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,17 +608,21 @@ def detach_uretprobe(cls, name="", sym="", addr=None):
del open_uprobes[ev_name]

def _trace_autoload(self):
# Cater to one-liner case where attach_kprobe is omitted and C function
# name matches that of the kprobe.
if len(open_kprobes) == 0:
for i in range(0, lib.bpf_num_functions(self.module)):
func_name = lib.bpf_function_name(self.module, i).decode()
if func_name.startswith("kprobe__"):
fn = self.load_func(func_name, BPF.KPROBE)
self.attach_kprobe(event=fn.name[8:], fn_name=fn.name)
elif func_name.startswith("kretprobe__"):
fn = self.load_func(func_name, BPF.KPROBE)
self.attach_kretprobe(event=fn.name[11:], fn_name=fn.name)
for i in range(0, lib.bpf_num_functions(self.module)):
func_name = lib.bpf_function_name(self.module, i).decode()
if func_name.startswith("kprobe__"):
fn = self.load_func(func_name, BPF.KPROBE)
self.attach_kprobe(event=fn.name[8:], fn_name=fn.name)
elif func_name.startswith("kretprobe__"):
fn = self.load_func(func_name, BPF.KPROBE)
self.attach_kretprobe(event=fn.name[11:], fn_name=fn.name)
elif func_name.startswith("tracepoint__"):
fn = self.load_func(func_name, BPF.TRACEPOINT)
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):
"""trace_open(nonblocking=False)
Expand Down

0 comments on commit 619fc14

Please sign in to comment.