Commit c7edcd5e authored by 4ast's avatar 4ast

Merge pull request #201 from iovisor/bblanco_dev

Always autoload k[ret]probe__ prefixed functions
parents ed85df7d 32097d90
...@@ -38,7 +38,7 @@ static unsigned int log2l(unsigned long v) ...@@ -38,7 +38,7 @@ static unsigned int log2l(unsigned long v)
return log2(v) + 1; return log2(v) + 1;
} }
int do_request(struct pt_regs *ctx, struct request *req) int kprobe__blk_start_request(struct pt_regs *ctx, struct request *req)
{ {
int index = log2l(req->__data_len / 1024); int index = log2l(req->__data_len / 1024);
u64 *leaf = dist.lookup(&index); u64 *leaf = dist.lookup(&index);
......
...@@ -18,7 +18,6 @@ from time import sleep ...@@ -18,7 +18,6 @@ from time import sleep
# load BPF program # load BPF program
b = BPF(src_file = "bitehist.c") b = BPF(src_file = "bitehist.c")
b.attach_kprobe(event="blk_start_request", fn_name="do_request")
# header # header
print("Tracing... Hit Ctrl-C to end.") print("Tracing... Hit Ctrl-C to end.")
......
...@@ -348,6 +348,10 @@ class BPF(object): ...@@ -348,6 +348,10 @@ class BPF(object):
if self.module == None: if self.module == None:
raise Exception("Failed to compile BPF module %s" % src_file) raise Exception("Failed to compile BPF module %s" % src_file)
# If any "kprobe__" prefixed functions were defined, they will be
# loaded and attached here.
self._trace_autoload()
def load_funcs(self, prog_type=KPROBE): def load_funcs(self, prog_type=KPROBE):
"""load_funcs(prog_type=KPROBE) """load_funcs(prog_type=KPROBE)
...@@ -552,11 +556,13 @@ class BPF(object): ...@@ -552,11 +556,13 @@ class BPF(object):
# Cater to one-liner case where attach_kprobe is omitted and C function # Cater to one-liner case where attach_kprobe is omitted and C function
# name matches that of the kprobe. # name matches that of the kprobe.
if len(open_kprobes) == 0: if len(open_kprobes) == 0:
fns = self.load_funcs(BPF.KPROBE) for i in range(0, lib.bpf_num_functions(self.module)):
for fn in fns: func_name = lib.bpf_function_name(self.module, i).decode()
if fn.name.startswith("kprobe__"): if func_name.startswith("kprobe__"):
fn = self.load_func(func_name, BPF.KPROBE)
self.attach_kprobe(event=fn.name[8:], fn_name=fn.name) self.attach_kprobe(event=fn.name[8:], fn_name=fn.name)
elif fn.name.startswith("kretprobe__"): elif func_name.startswith("kretprobe__"):
fn = self.load_func(func_name, BPF.KPROBE)
self.attach_kretprobe(event=fn.name[11:], fn_name=fn.name) self.attach_kretprobe(event=fn.name[11:], fn_name=fn.name)
def trace_open(self, nonblocking=False): def trace_open(self, nonblocking=False):
...@@ -564,7 +570,6 @@ class BPF(object): ...@@ -564,7 +570,6 @@ class BPF(object):
Open the trace_pipe if not already open Open the trace_pipe if not already open
""" """
self._trace_autoload()
global tracefile global tracefile
if not tracefile: if not tracefile:
tracefile = open("%s/trace_pipe" % TRACEFS) tracefile = open("%s/trace_pipe" % TRACEFS)
......
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