docs: Fix API reference

This commit is contained in:
Pragyansh Chaturvedi
2026-01-29 03:13:49 +05:30
parent aded125cba
commit 036830c200

View File

@ -24,12 +24,12 @@ from pythonbpf import (
section, section,
bpfglobal, bpfglobal,
struct, struct,
# Compilation # Compilation
compile_to_ir, compile_to_ir,
compile, compile,
BPF, BPF,
# Utilities # Utilities
trace_pipe, trace_pipe,
trace_fields, trace_fields,
@ -128,7 +128,7 @@ Decorator to mark a class as a BPF struct definition.
def compile_to_ir( def compile_to_ir(
filename: str, filename: str,
output: str, output: str,
loglevel=logging.INFO loglevel=logging.WARNING
) -> None ) -> None
``` ```
@ -137,7 +137,7 @@ Compile Python source to LLVM Intermediate Representation.
**Parameters:** **Parameters:**
* `filename` (str) - Path to the Python source file * `filename` (str) - Path to the Python source file
* `output` (str) - Path for the output LLVM IR file (.ll) * `output` (str) - Path for the output LLVM IR file (.ll)
* `loglevel` - Logging level (default: logging.INFO) * `loglevel` - Logging level (default: logging.WARNING)
**See also:** {doc}`../user-guide/compilation` **See also:** {doc}`../user-guide/compilation`
@ -147,7 +147,7 @@ Compile Python source to LLVM Intermediate Representation.
def compile( def compile(
filename: str = None, filename: str = None,
output: str = None, output: str = None,
loglevel=logging.INFO loglevel=logging.WARNING
) -> None ) -> None
``` ```
@ -156,7 +156,7 @@ Compile Python source to BPF object file.
**Parameters:** **Parameters:**
* `filename` (str, optional) - Path to the Python source file (default: calling file) * `filename` (str, optional) - Path to the Python source file (default: calling file)
* `output` (str, optional) - Path for the output object file (default: same name with .o extension) * `output` (str, optional) - Path for the output object file (default: same name with .o extension)
* `loglevel` - Logging level (default: logging.INFO) * `loglevel` - Logging level (default: logging.WARNING)
**See also:** {doc}`../user-guide/compilation` **See also:** {doc}`../user-guide/compilation`
@ -167,9 +167,9 @@ class BPF:
def __init__( def __init__(
self, self,
filename: str = None, filename: str = None,
loglevel=logging.INFO loglevel=logging.WARNING
) )
def load(self) -> BpfObject def load(self) -> BpfObject
def attach_all(self) -> None def attach_all(self) -> None
def load_and_attach(self) -> BpfObject def load_and_attach(self) -> BpfObject
@ -179,7 +179,7 @@ High-level interface to compile, load, and attach BPF programs.
**Parameters:** **Parameters:**
* `filename` (str, optional) - Path to Python source file (default: calling file) * `filename` (str, optional) - Path to Python source file (default: calling file)
* `loglevel` - Logging level (default: logging.INFO) * `loglevel` - Logging level (default: logging.WARNING)
**Methods:** **Methods:**
* `load()` - Load the compiled BPF program into the kernel * `load()` - Load the compiled BPF program into the kernel
@ -246,7 +246,7 @@ class HashMap:
value, value,
max_entries: int max_entries: int
) )
def lookup(self, key) def lookup(self, key)
def update(self, key, value, flags=None) def update(self, key, value, flags=None)
def delete(self, key) def delete(self, key)
@ -255,7 +255,7 @@ class HashMap:
Hash map for efficient key-value storage. Hash map for efficient key-value storage.
**Parameters:** **Parameters:**
* `key` - The type of the key (ctypes type) * `key` - The type of the key (ctypes type or struct)
* `value` - The type of the value (ctypes type or struct) * `value` - The type of the value (ctypes type or struct)
* `max_entries` (int) - Maximum number of entries * `max_entries` (int) - Maximum number of entries
@ -275,7 +275,7 @@ class PerfEventArray:
key_size, key_size,
value_size value_size
) )
def output(self, data) def output(self, data)
``` ```
@ -295,7 +295,7 @@ Perf event array for sending data to userspace.
```python ```python
class RingBuffer: class RingBuffer:
def __init__(self, max_entries: int) def __init__(self, max_entries: int)
def output(self, data, flags=0) def output(self, data, flags=0)
def reserve(self, size: int) def reserve(self, size: int)
def submit(self, data, flags=0) def submit(self, data, flags=0)
@ -377,7 +377,7 @@ from ctypes import c_void_p, c_int64
@section("tracepoint/syscalls/sys_enter_execve") @section("tracepoint/syscalls/sys_enter_execve")
def hello(ctx: c_void_p) -> c_int64: def hello(ctx: c_void_p) -> c_int64:
print("Hello, World!") print("Hello, World!")
return c_int64(0) return 0
@bpf @bpf
@bpfglobal @bpfglobal
@ -407,13 +407,13 @@ def counters() -> HashMap:
def count_clones(ctx: c_void_p) -> c_int64: def count_clones(ctx: c_void_p) -> c_int64:
process_id = pid() process_id = pid()
count = counters.lookup(process_id) count = counters.lookup(process_id)
if count: if count:
counters.update(process_id, count + 1) counters.update(process_id, count + 1)
else: else:
counters.update(process_id, c_uint64(1)) counters.update(process_id, 1)
return c_int64(0) return 0
@bpf @bpf
@bpfglobal @bpfglobal
@ -450,11 +450,10 @@ def track_exec(ctx: c_void_p) -> c_int64:
event = Event() event = Event()
event.timestamp = ktime() event.timestamp = ktime()
event.pid = pid() event.pid = pid()
# Note: comm() requires a buffer parameter comm(event.comm)
# comm(event.comm) # Fills event.comm with process name
events.output(event) events.output(event)
return c_int64(0) return 0
@bpf @bpf
@bpfglobal @bpfglobal