mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2025-12-31 21:06:25 +00:00
Add trace_pipe utility
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
from pythonbpf import bpf, section, bpfglobal, compile
|
||||
from pythonbpf import bpf, section, bpfglobal, BPF, trace_pipe
|
||||
from ctypes import c_void_p, c_int64
|
||||
|
||||
|
||||
@ -15,4 +15,8 @@ def LICENSE() -> str:
|
||||
return "GPL"
|
||||
|
||||
|
||||
compile()
|
||||
# compile()
|
||||
b = BPF()
|
||||
b.load_and_attach()
|
||||
|
||||
trace_pipe()
|
||||
|
||||
19
BCC-Examples/sys_sync.py
Normal file
19
BCC-Examples/sys_sync.py
Normal file
@ -0,0 +1,19 @@
|
||||
from pythonbpf import bpf, section, bpfglobal, compile
|
||||
from ctypes import c_void_p, c_int64
|
||||
|
||||
|
||||
@bpf
|
||||
@section("tracepoint/syscalls/sys_enter_sync")
|
||||
def hello_world(ctx: c_void_p) -> c_int64:
|
||||
print("sys_sync() called")
|
||||
return c_int64(0)
|
||||
|
||||
|
||||
@bpf
|
||||
@bpfglobal
|
||||
def LICENSE() -> str:
|
||||
return "GPL"
|
||||
|
||||
|
||||
compile()
|
||||
print("Tracing sys_sync()... Ctrl-C to end.")
|
||||
@ -1,5 +1,6 @@
|
||||
from .decorators import bpf, map, section, bpfglobal, struct
|
||||
from .codegen import compile_to_ir, compile, BPF
|
||||
from .utils import trace_pipe
|
||||
|
||||
__all__ = [
|
||||
"bpf",
|
||||
@ -10,4 +11,5 @@ __all__ = [
|
||||
"compile_to_ir",
|
||||
"compile",
|
||||
"BPF",
|
||||
"trace_pipe",
|
||||
]
|
||||
|
||||
9
pythonbpf/utils.py
Normal file
9
pythonbpf/utils.py
Normal file
@ -0,0 +1,9 @@
|
||||
import subprocess
|
||||
|
||||
|
||||
def trace_pipe():
|
||||
"""Util to read from the trace pipe."""
|
||||
try:
|
||||
subprocess.run(["cat", "/sys/kernel/tracing/trace_pipe"])
|
||||
except KeyboardInterrupt:
|
||||
print("Tracing stopped.")
|
||||
Reference in New Issue
Block a user