diff --git a/README.md b/README.md index a21ffde..17e4de4 100644 --- a/README.md +++ b/README.md @@ -60,12 +60,13 @@ pip install pythonbpf pylibbpf ```python import time from pythonbpf import bpf, map, section, bpfglobal, BPF -from pythonbpf.helpers import pid +from pythonbpf.helper import pid from pythonbpf.maps import HashMap from pylibbpf import * from ctypes import c_void_p, c_int64, c_uint64, c_int32 import matplotlib.pyplot as plt + # This program attaches an eBPF tracepoint to sys_enter_clone, # counts per-PID clone syscalls, stores them in a hash map, # and then plots the distribution as a histogram using matplotlib. @@ -76,6 +77,7 @@ import matplotlib.pyplot as plt def hist() -> HashMap: return HashMap(key=c_int32, value=c_uint64, max_entries=4096) + @bpf @section("tracepoint/syscalls/sys_enter_clone") def hello(ctx: c_void_p) -> c_int64: diff --git a/examples/binops_demo.py b/examples/binops_demo.py index 95b8cf8..ed15772 100644 --- a/examples/binops_demo.py +++ b/examples/binops_demo.py @@ -1,5 +1,5 @@ from pythonbpf import bpf, map, section, bpfglobal, compile -from pythonbpf.helpers import ktime +from pythonbpf.helper import ktime from pythonbpf.maps import HashMap from ctypes import c_void_p, c_int64, c_uint64 diff --git a/examples/blk_request.py b/examples/blk_request.py index 62b9097..73af9ac 100644 --- a/examples/blk_request.py +++ b/examples/blk_request.py @@ -1,5 +1,5 @@ from pythonbpf import bpf, map, section, bpfglobal, compile -from pythonbpf.helpers import ktime +from pythonbpf.helper import ktime from pythonbpf.maps import HashMap from ctypes import c_void_p, c_int32, c_uint64 diff --git a/examples/clone-matplotlib.ipynb b/examples/clone-matplotlib.ipynb index 414dbc9..8cfcb9c 100644 --- a/examples/clone-matplotlib.ipynb +++ b/examples/clone-matplotlib.ipynb @@ -10,7 +10,7 @@ "import time\n", "\n", "from pythonbpf import bpf, map, section, bpfglobal, BPF\n", - "from pythonbpf.helpers import pid\n", + "from pythonbpf.helper import pid\n", "from pythonbpf.maps import HashMap\n", "from pylibbpf import *\n", "from ctypes import c_void_p, c_int64, c_uint64, c_int32\n", diff --git a/examples/clone_plot.py b/examples/clone_plot.py index 2888f22..ee355d4 100644 --- a/examples/clone_plot.py +++ b/examples/clone_plot.py @@ -1,7 +1,7 @@ import time from pythonbpf import bpf, map, section, bpfglobal, BPF -from pythonbpf.helpers import pid +from pythonbpf.helper import pid from pythonbpf.maps import HashMap from pylibbpf import BpfMap from ctypes import c_void_p, c_int64, c_uint64, c_int32 diff --git a/examples/struct_and_perf.py b/examples/struct_and_perf.py index a94a198..9c8f652 100644 --- a/examples/struct_and_perf.py +++ b/examples/struct_and_perf.py @@ -1,5 +1,5 @@ from pythonbpf import bpf, map, struct, section, bpfglobal, compile -from pythonbpf.helpers import ktime, pid +from pythonbpf.helper import ktime, pid from pythonbpf.maps import PerfEventArray from ctypes import c_void_p, c_int32, c_uint64 diff --git a/examples/sys_sync.py b/examples/sys_sync.py index 1f42a58..3b65f46 100644 --- a/examples/sys_sync.py +++ b/examples/sys_sync.py @@ -1,5 +1,5 @@ from pythonbpf import bpf, map, section, bpfglobal, compile -from pythonbpf.helpers import ktime +from pythonbpf.helper import ktime from pythonbpf.maps import HashMap from ctypes import c_void_p, c_int64, c_uint64 diff --git a/examples/xdp_pass.py b/examples/xdp_pass.py index 446a188..17de6c9 100644 --- a/examples/xdp_pass.py +++ b/examples/xdp_pass.py @@ -1,5 +1,5 @@ from pythonbpf import bpf, map, section, bpfglobal, compile -from pythonbpf.helpers import XDP_PASS +from pythonbpf.helper import XDP_PASS from pythonbpf.maps import HashMap from ctypes import c_void_p, c_int64 diff --git a/pythonbpf/helper/__init__.py b/pythonbpf/helper/__init__.py index 17f3198..a7ad169 100644 --- a/pythonbpf/helper/__init__.py +++ b/pythonbpf/helper/__init__.py @@ -1,4 +1,13 @@ from .helper_utils import HelperHandlerRegistry from .bpf_helper_handler import handle_helper_call +from .helpers import ktime, pid, deref, XDP_DROP, XDP_PASS -__all__ = ["HelperHandlerRegistry", "handle_helper_call"] +__all__ = [ + "HelperHandlerRegistry", + "handle_helper_call", + "ktime", + "pid", + "deref", + "XDP_DROP", + "XDP_PASS", +] diff --git a/pythonbpf/helpers.py b/pythonbpf/helper/helpers.py similarity index 100% rename from pythonbpf/helpers.py rename to pythonbpf/helper/helpers.py diff --git a/tests/failing_tests/direct_assign.py b/tests/failing_tests/direct_assign.py index 0963355..18ff266 100644 --- a/tests/failing_tests/direct_assign.py +++ b/tests/failing_tests/direct_assign.py @@ -1,5 +1,5 @@ from pythonbpf import bpf, map, section, bpfglobal, compile -from pythonbpf.helpers import XDP_PASS +from pythonbpf.helper import XDP_PASS from pythonbpf.maps import HashMap from ctypes import c_void_p, c_int64 diff --git a/tests/passing_tests/perf_buffer_map.py b/tests/passing_tests/perf_buffer_map.py index 5ae8ea1..0a3e5d1 100644 --- a/tests/passing_tests/perf_buffer_map.py +++ b/tests/passing_tests/perf_buffer_map.py @@ -1,5 +1,5 @@ from pythonbpf import bpf, map, struct, section, bpfglobal, compile, compile_to_ir, BPF -from pythonbpf.helpers import ktime, pid +from pythonbpf.helper import ktime, pid from pythonbpf.maps import PerfEventArray from ctypes import c_void_p, c_int32, c_uint64