bcc/python: Add the support for detaching a single kprobe/kretprobe handler
authorHao Lee <haolee@didiglobal.com>
Fri, 27 Aug 2021 08:23:29 +0000 (04:23 -0400)
committeryonghong-song <ys114321@gmail.com>
Thu, 2 Sep 2021 05:31:39 +0000 (22:31 -0700)
commite984fe84fdd8ba1c6a2738532a59a6abf9bc45f4
tree35b2ca8d546d496d3285777d1a7f0e030ce7a35f
parent27f3987be60f3488fbdf17847099a67ada9282da
bcc/python: Add the support for detaching a single kprobe/kretprobe handler

_add_kprobe_fd() uses a <ev_name, fd> map to store fd of attached function, but
the current implementation can only store the last fd if we attach multiple
handler functions on the same kprobe event.

This patch uses a <ev_name, <fn_name, fd>> map to build the corresponding
relationship among the kprobe event, handler function names, and fds. Then we
can detach any single handler function, which is pretty helpful if the
developer wants to enable and disable kprobes/kretprobes dynamically.

For example:
We want to measure both the execution count, execution time, and some other
metrics of a kernel function. For flexibility, we want to use separate handlers
for each metric to disable them individually if any of them incur some
performance penalties. Without this interface, we have to disable all handlers
on the kernel function.

The uprobe also has a similar problem. I will fix it in a subsequent patch.

Signed-off-by: Hao Lee <haolee@didiglobal.com>
src/python/bcc/__init__.py