move helper annotations to helpers module

This commit is contained in:
2025-10-02 01:55:32 +05:30
parent 23f3cbcea7
commit 1a66887f48
12 changed files with 22 additions and 11 deletions

View File

@ -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:

View File

@ -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

View File

@ -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

View File

@ -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",

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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",
]

View File

@ -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

View File

@ -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