Skip to content

Commit 036830c

Browse files
committed
docs: Fix API reference
1 parent aded125 commit 036830c

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

docs/api/index.md

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ from pythonbpf import (
2424
section,
2525
bpfglobal,
2626
struct,
27-
27+
2828
# Compilation
2929
compile_to_ir,
3030
compile,
3131
BPF,
32-
32+
3333
# Utilities
3434
trace_pipe,
3535
trace_fields,
@@ -128,7 +128,7 @@ Decorator to mark a class as a BPF struct definition.
128128
def compile_to_ir(
129129
filename: str,
130130
output: str,
131-
loglevel=logging.INFO
131+
loglevel=logging.WARNING
132132
) -> None
133133
```
134134

@@ -137,7 +137,7 @@ Compile Python source to LLVM Intermediate Representation.
137137
**Parameters:**
138138
* `filename` (str) - Path to the Python source file
139139
* `output` (str) - Path for the output LLVM IR file (.ll)
140-
* `loglevel` - Logging level (default: logging.INFO)
140+
* `loglevel` - Logging level (default: logging.WARNING)
141141

142142
**See also:** {doc}`../user-guide/compilation`
143143

@@ -147,7 +147,7 @@ Compile Python source to LLVM Intermediate Representation.
147147
def compile(
148148
filename: str = None,
149149
output: str = None,
150-
loglevel=logging.INFO
150+
loglevel=logging.WARNING
151151
) -> None
152152
```
153153

@@ -156,7 +156,7 @@ Compile Python source to BPF object file.
156156
**Parameters:**
157157
* `filename` (str, optional) - Path to the Python source file (default: calling file)
158158
* `output` (str, optional) - Path for the output object file (default: same name with .o extension)
159-
* `loglevel` - Logging level (default: logging.INFO)
159+
* `loglevel` - Logging level (default: logging.WARNING)
160160

161161
**See also:** {doc}`../user-guide/compilation`
162162

@@ -167,9 +167,9 @@ class BPF:
167167
def __init__(
168168
self,
169169
filename: str = None,
170-
loglevel=logging.INFO
170+
loglevel=logging.WARNING
171171
)
172-
172+
173173
def load(self) -> BpfObject
174174
def attach_all(self) -> None
175175
def load_and_attach(self) -> BpfObject
@@ -179,7 +179,7 @@ High-level interface to compile, load, and attach BPF programs.
179179

180180
**Parameters:**
181181
* `filename` (str, optional) - Path to Python source file (default: calling file)
182-
* `loglevel` - Logging level (default: logging.INFO)
182+
* `loglevel` - Logging level (default: logging.WARNING)
183183

184184
**Methods:**
185185
* `load()` - Load the compiled BPF program into the kernel
@@ -246,7 +246,7 @@ class HashMap:
246246
value,
247247
max_entries: int
248248
)
249-
249+
250250
def lookup(self, key)
251251
def update(self, key, value, flags=None)
252252
def delete(self, key)
@@ -255,7 +255,7 @@ class HashMap:
255255
Hash map for efficient key-value storage.
256256

257257
**Parameters:**
258-
* `key` - The type of the key (ctypes type)
258+
* `key` - The type of the key (ctypes type or struct)
259259
* `value` - The type of the value (ctypes type or struct)
260260
* `max_entries` (int) - Maximum number of entries
261261

@@ -275,7 +275,7 @@ class PerfEventArray:
275275
key_size,
276276
value_size
277277
)
278-
278+
279279
def output(self, data)
280280
```
281281

@@ -295,7 +295,7 @@ Perf event array for sending data to userspace.
295295
```python
296296
class RingBuffer:
297297
def __init__(self, max_entries: int)
298-
298+
299299
def output(self, data, flags=0)
300300
def reserve(self, size: int)
301301
def submit(self, data, flags=0)
@@ -377,7 +377,7 @@ from ctypes import c_void_p, c_int64
377377
@section("tracepoint/syscalls/sys_enter_execve")
378378
def hello(ctx: c_void_p) -> c_int64:
379379
print("Hello, World!")
380-
return c_int64(0)
380+
return 0
381381

382382
@bpf
383383
@bpfglobal
@@ -407,13 +407,13 @@ def counters() -> HashMap:
407407
def count_clones(ctx: c_void_p) -> c_int64:
408408
process_id = pid()
409409
count = counters.lookup(process_id)
410-
410+
411411
if count:
412412
counters.update(process_id, count + 1)
413413
else:
414-
counters.update(process_id, c_uint64(1))
415-
416-
return c_int64(0)
414+
counters.update(process_id, 1)
415+
416+
return 0
417417

418418
@bpf
419419
@bpfglobal
@@ -450,11 +450,10 @@ def track_exec(ctx: c_void_p) -> c_int64:
450450
event = Event()
451451
event.timestamp = ktime()
452452
event.pid = pid()
453-
# Note: comm() requires a buffer parameter
454-
# comm(event.comm) # Fills event.comm with process name
455-
453+
comm(event.comm)
454+
456455
events.output(event)
457-
return c_int64(0)
456+
return 0
458457

459458
@bpf
460459
@bpfglobal

0 commit comments

Comments
 (0)