Add hello_fields BCC Example

This commit is contained in:
Pragyansh Chaturvedi
2025-10-14 04:42:12 +05:30
parent 263402d137
commit 903654daff
3 changed files with 68 additions and 11 deletions

View File

@ -0,0 +1,33 @@
from pythonbpf import bpf, section, bpfglobal, BPF, trace_fields
from ctypes import c_void_p, c_int64
@bpf
@section("tracepoint/syscalls/sys_enter_clone")
def hello_world(ctx: c_void_p) -> c_int64:
print("Hello, World!")
return c_int64(0)
@bpf
@bpfglobal
def LICENSE() -> str:
return "GPL"
# compile
b = BPF()
b.load_and_attach()
# header
print(f"{'TIME(s)':<18} {'COMM':<16} {'PID':<6} {'MESSAGE'}")
# format output
while True:
try:
(task, pid, cpu, flags, ts, msg) = trace_fields()
except ValueError:
continue
except KeyboardInterrupt:
exit()
print(f"{ts:<18} {task:<16} {pid:<6} {msg}")

View File

@ -15,7 +15,6 @@ def LICENSE() -> str:
return "GPL"
# compile()
b = BPF()
b.load_and_attach()