add ringbuf map type

This commit is contained in:
2025-10-01 23:51:18 +05:30
parent 8ceb1d1ac3
commit da9df2e6bf
3 changed files with 114 additions and 28 deletions

View File

@ -1,5 +1,5 @@
from pythonbpf import bpf, map, bpfglobal, section
from pythonbpf.maps import RingBuf
from pythonbpf import bpf, BPF, map, bpfglobal, section, compile, compile_to_ir
from pythonbpf.maps import RingBuf, HashMap
from ctypes import c_int32, c_void_p
@ -7,12 +7,19 @@ from ctypes import c_int32, c_void_p
@bpf
@map
def mymap() -> RingBuf:
return RingBuf(max_entries=(1 << 24))
return RingBuf(max_entries=(1024))
@bpf
@map
def mymap2() -> HashMap:
return HashMap(key=c_int32, value=c_int32, max_entries=1024)
@bpf
@section("tracepoint/syscalls/sys_enter_clone")
def testing(ctx: c_void_p) -> c_int32:
def random_section(ctx: c_void_p) -> c_int32:
print("Hello")
return c_int32(0)
@ -22,4 +29,7 @@ def LICENSE() -> str:
return "GPL"
compile_to_ir("ringbuf.py", "ringbuf.ll")
compile()
b = BPF()
b.load_and_attach()