Skip to content

Commit b105c70

Browse files
committed
Add hello_perf_output BCC-Example skeleton
1 parent 0a1557e commit b105c70

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

BCC-Examples/hello_perf_output.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from pythonbpf import bpf, map, struct, section, bpfglobal, compile
2+
from pythonbpf.helper import ktime, pid
3+
from pythonbpf.maps import PerfEventArray
4+
5+
from ctypes import c_void_p, c_int64, c_uint64
6+
7+
8+
@bpf
9+
@struct
10+
class data_t:
11+
pid: c_uint64
12+
ts: c_uint64
13+
comm: str(16) # type: ignore [valid-type]
14+
15+
16+
@bpf
17+
@map
18+
def events() -> PerfEventArray:
19+
return PerfEventArray(key_size=c_int64, value_size=c_int64)
20+
21+
22+
@bpf
23+
@section("tracepoint/syscalls/sys_enter_clone")
24+
def hello(ctx: c_void_p) -> c_int64:
25+
dataobj = data_t()
26+
strobj = "hellohellohello"
27+
dataobj.pid, dataobj.ts = pid(), ktime()
28+
# get_curr_comm(dataobj.comm)
29+
print(f"clone called at {dataobj.ts} by pid {dataobj.pid}, comm {strobj}")
30+
events.output(dataobj)
31+
return 0 # type: ignore [return-value]
32+
33+
34+
@bpf
35+
@bpfglobal
36+
def LICENSE() -> str:
37+
return "GPL"
38+
39+
40+
compile()

0 commit comments

Comments
 (0)