Skip to content

Commit

Permalink
python binding: allow fully-specified probe names for enable_probe()
Browse files Browse the repository at this point in the history
  • Loading branch information
gfx authored and yonghong-song committed Mar 9, 2020
1 parent b7541d0 commit 37cd183
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/python/bcc/libbcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ class bcc_symbol_option(ct.Structure):
lib.bcc_usdt_enable_probe.restype = ct.c_int
lib.bcc_usdt_enable_probe.argtypes = [ct.c_void_p, ct.c_char_p, ct.c_char_p]

lib.bcc_usdt_enable_fully_specified_probe.restype = ct.c_int
lib.bcc_usdt_enable_fully_specified_probe.argtypes = [ct.c_void_p, ct.c_char_p, ct.c_char_p, ct.c_char_p]

lib.bcc_usdt_genargs.restype = ct.c_char_p
lib.bcc_usdt_genargs.argtypes = [ct.POINTER(ct.c_void_p), ct.c_int]

Expand Down
13 changes: 11 additions & 2 deletions src/python/bcc/usdt.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,17 @@ def __del__(self):
lib.bcc_usdt_close(self.context)

def enable_probe(self, probe, fn_name):
if lib.bcc_usdt_enable_probe(self.context, probe.encode('ascii'),
fn_name.encode('ascii')) != 0:
probe_parts = probe.split(":", 1)
if len(probe_parts) == 1:
ret = lib.bcc_usdt_enable_probe(
self.context, probe.encode('ascii'), fn_name.encode('ascii'))
else:
(provider_name, probe_name) = probe_parts
ret = lib.bcc_usdt_enable_fully_specified_probe(
self.context, provider_name.encode('ascii'), probe_name.encode('ascii'),
fn_name.encode('ascii'))

if ret != 0:
raise USDTException(
"""Failed to enable USDT probe '%s':
the specified pid might not contain the given language's runtime,
Expand Down
3 changes: 2 additions & 1 deletion tests/python/test_usdt3.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def setUp(self):
static inline void record_val(int val)
{
FOLLY_SDT(test, probe, val);
FOLLY_SDT(test_dup_name, probe, val);
}
extern void record_a(int val);
Expand Down Expand Up @@ -110,7 +111,7 @@ def _create_file(name, text):
def test_attach1(self):
# enable USDT probe from given PID and verifier generated BPF programs
u = USDT(pid=int(self.app.pid))
u.enable_probe(probe="probe", fn_name="do_trace")
u.enable_probe(probe="test:probe", fn_name="do_trace")
b = BPF(text=self.bpf_text, usdt_contexts=[u])

# processing events
Expand Down

0 comments on commit 37cd183

Please sign in to comment.