mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2026-03-29 08:31:28 +00:00
format chore
This commit is contained in:
@ -6,19 +6,20 @@ These are used for type checking and map definition; the actual BPF maps
|
||||
are generated as LLVM IR during compilation.
|
||||
"""
|
||||
|
||||
|
||||
# This file provides type and function hints only and does not actually give any functionality.
|
||||
class HashMap:
|
||||
"""
|
||||
A BPF hash map for storing key-value pairs.
|
||||
|
||||
|
||||
This is a type hint class used during compilation. The actual BPF map
|
||||
implementation is generated as LLVM IR.
|
||||
"""
|
||||
|
||||
|
||||
def __init__(self, key, value, max_entries):
|
||||
"""
|
||||
Initialize a HashMap definition.
|
||||
|
||||
|
||||
Args:
|
||||
key: The ctypes type for keys (e.g., c_int64)
|
||||
value: The ctypes type for values (e.g., c_int64)
|
||||
@ -32,10 +33,10 @@ class HashMap:
|
||||
def lookup(self, key):
|
||||
"""
|
||||
Look up a value by key in the map.
|
||||
|
||||
|
||||
Args:
|
||||
key: The key to look up
|
||||
|
||||
|
||||
Returns:
|
||||
The value if found, None otherwise
|
||||
"""
|
||||
@ -47,10 +48,10 @@ class HashMap:
|
||||
def delete(self, key):
|
||||
"""
|
||||
Delete an entry from the map by key.
|
||||
|
||||
|
||||
Args:
|
||||
key: The key to delete
|
||||
|
||||
|
||||
Raises:
|
||||
KeyError: If the key is not found in the map
|
||||
"""
|
||||
@ -63,12 +64,12 @@ class HashMap:
|
||||
def update(self, key, value, flags=None):
|
||||
"""
|
||||
Update or insert a key-value pair in the map.
|
||||
|
||||
|
||||
Args:
|
||||
key: The key to update
|
||||
value: The new value
|
||||
flags: Optional flags for update behavior
|
||||
|
||||
|
||||
Raises:
|
||||
KeyError: If the key is not found in the map
|
||||
"""
|
||||
@ -81,14 +82,14 @@ class HashMap:
|
||||
class PerfEventArray:
|
||||
"""
|
||||
A BPF perf event array for sending data to userspace.
|
||||
|
||||
|
||||
This is a type hint class used during compilation.
|
||||
"""
|
||||
|
||||
|
||||
def __init__(self, key_size, value_size):
|
||||
"""
|
||||
Initialize a PerfEventArray definition.
|
||||
|
||||
|
||||
Args:
|
||||
key_size: The size/type for keys
|
||||
value_size: The size/type for values
|
||||
@ -100,7 +101,7 @@ class PerfEventArray:
|
||||
def output(self, data):
|
||||
"""
|
||||
Output data to the perf event array.
|
||||
|
||||
|
||||
Args:
|
||||
data: The data to output
|
||||
"""
|
||||
@ -110,14 +111,14 @@ class PerfEventArray:
|
||||
class RingBuf:
|
||||
"""
|
||||
A BPF ring buffer for efficient data transfer to userspace.
|
||||
|
||||
|
||||
This is a type hint class used during compilation.
|
||||
"""
|
||||
|
||||
|
||||
def __init__(self, max_entries):
|
||||
"""
|
||||
Initialize a RingBuf definition.
|
||||
|
||||
|
||||
Args:
|
||||
max_entries: Maximum number of entries the ring buffer can hold
|
||||
"""
|
||||
@ -126,14 +127,14 @@ class RingBuf:
|
||||
def reserve(self, size: int, flags=0):
|
||||
"""
|
||||
Reserve space in the ring buffer.
|
||||
|
||||
|
||||
Args:
|
||||
size: Size in bytes to reserve
|
||||
flags: Optional reservation flags
|
||||
|
||||
|
||||
Returns:
|
||||
0 as a placeholder (actual implementation is in BPF runtime)
|
||||
|
||||
|
||||
Raises:
|
||||
ValueError: If size exceeds max_entries
|
||||
"""
|
||||
@ -144,7 +145,7 @@ class RingBuf:
|
||||
def submit(self, data, flags=0):
|
||||
"""
|
||||
Submit data to the ring buffer.
|
||||
|
||||
|
||||
Args:
|
||||
data: The data to submit
|
||||
flags: Optional submission flags
|
||||
|
||||
@ -29,10 +29,10 @@ def maps_proc(tree, module, chunks):
|
||||
def is_map(func_node):
|
||||
"""
|
||||
Check if a function node is decorated with @map.
|
||||
|
||||
|
||||
Args:
|
||||
func_node: The AST function node to check
|
||||
|
||||
|
||||
Returns:
|
||||
True if the function is decorated with @map, False otherwise
|
||||
"""
|
||||
@ -44,6 +44,7 @@ def is_map(func_node):
|
||||
|
||||
class BPFMapType(Enum):
|
||||
"""Enumeration of BPF map types."""
|
||||
|
||||
UNSPEC = 0
|
||||
HASH = 1
|
||||
ARRAY = 2
|
||||
@ -84,12 +85,12 @@ class BPFMapType(Enum):
|
||||
def create_bpf_map(module, map_name, map_params):
|
||||
"""
|
||||
Create a BPF map in the module with given parameters and debug info.
|
||||
|
||||
|
||||
Args:
|
||||
module: The LLVM IR module to add the map to
|
||||
map_name: The name of the BPF map
|
||||
map_params: Dictionary of map parameters (type, key_size, value_size, max_entries)
|
||||
|
||||
|
||||
Returns:
|
||||
The created global variable representing the map
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user