Skip to content

Commit edc3373

Browse files
committed
Add trace_pipe utility
1 parent 18d62d6 commit edc3373

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed

BCC-Examples/hello_world.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from pythonbpf import bpf, section, bpfglobal, compile
1+
from pythonbpf import bpf, section, bpfglobal, BPF, trace_pipe
22
from ctypes import c_void_p, c_int64
33

44

@@ -15,4 +15,8 @@ def LICENSE() -> str:
1515
return "GPL"
1616

1717

18-
compile()
18+
# compile()
19+
b = BPF()
20+
b.load_and_attach()
21+
22+
trace_pipe()

BCC-Examples/sys_sync.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from pythonbpf import bpf, section, bpfglobal, compile
2+
from ctypes import c_void_p, c_int64
3+
4+
5+
@bpf
6+
@section("tracepoint/syscalls/sys_enter_sync")
7+
def hello_world(ctx: c_void_p) -> c_int64:
8+
print("sys_sync() called")
9+
return c_int64(0)
10+
11+
12+
@bpf
13+
@bpfglobal
14+
def LICENSE() -> str:
15+
return "GPL"
16+
17+
18+
compile()
19+
print("Tracing sys_sync()... Ctrl-C to end.")

pythonbpf/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from .decorators import bpf, map, section, bpfglobal, struct
22
from .codegen import compile_to_ir, compile, BPF
3+
from .utils import trace_pipe
34

45
__all__ = [
56
"bpf",
@@ -10,4 +11,5 @@
1011
"compile_to_ir",
1112
"compile",
1213
"BPF",
14+
"trace_pipe",
1315
]

pythonbpf/utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import subprocess
2+
3+
4+
def trace_pipe():
5+
"""Util to read from the trace pipe."""
6+
try:
7+
subprocess.run(["cat", "/sys/kernel/tracing/trace_pipe"])
8+
except KeyboardInterrupt:
9+
print("Tracing stopped.")

0 commit comments

Comments
 (0)