Add ringbuf type hinting.

This commit is contained in:
2025-10-01 21:14:20 +05:30
parent 5c8b132cb9
commit 84ad58b775
7 changed files with 119 additions and 50 deletions

View File

@ -1,4 +1,4 @@
from .maps import HashMap, PerfEventArray
from .maps import HashMap, PerfEventArray, RingBuf
from .maps_pass import maps_proc
__all__ = ["HashMap", "PerfEventArray", "maps_proc"]
__all__ = ["HashMap", "PerfEventArray", "maps_proc", "RingBuf"]

View File

@ -1,3 +1,4 @@
# This file provides type and function hints only and does not actually give any functionality.
class HashMap:
def __init__(self, key, value, max_entries):
self.key = key
@ -33,3 +34,18 @@ class PerfEventArray:
def output(self, data):
pass # Placeholder for output method
class RingBuf:
def __init__(self, max_entries):
self.max_entries = max_entries
def reserve(self, size: int, flags=0):
if size > self.max_entries:
raise ValueError("size cannot be greater than set maximum entries")
return 0
def submit(self, data, flags=0):
pass
# add discard, output and also give names to flags and stuff

View File

@ -51,7 +51,7 @@ def create_bpf_map(module, map_name, map_params):
def create_map_debug_info(module, map_global, map_name, map_params):
"""Generate debug information metadata for BPF map"""
"""Generate debug information metadata for BPF maps HASH and PERF_EVENT_ARRAY"""
generator = DebugInfoGenerator(module)
uint_type = generator.get_uint32_type()