Skip to content

Commit 8e23184

Browse files
committed
Add struct example and decorator
1 parent d01c7ad commit 8e23184

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

examples/execve5.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1-
from pythonbpf import bpf, map, section, bpfglobal, compile
1+
from pythonbpf import bpf, map, struct, section, bpfglobal, compile
22
from pythonbpf.helpers import ktime, pid
33
from pythonbpf.maps import PerfEventArray
44

55
from ctypes import c_void_p, c_int64, c_int32, c_uint64
66

7+
8+
@bpf
9+
@struct
10+
class data_t:
11+
pid: c_uint64
12+
ts: c_uint64
13+
714
@bpf
815
@map
916
def events() -> PerfEventArray:

pythonbpf/decorators.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,19 @@ def bpfglobal(func):
99
func._is_bpfglobal = True
1010
return func
1111

12+
1213
def map(func):
1314
"""Decorator to mark a function as a BPF map."""
1415
func._is_map = True
1516
return func
1617

18+
19+
def struct(cls):
20+
"""Decorator to mark a class as a BPF struct."""
21+
cls._is_struct = True
22+
return cls
23+
24+
1725
def section(name: str):
1826
def wrapper(fn):
1927
fn._section = name

0 commit comments

Comments
 (0)