format chore and pre commit hook addition

This commit is contained in:
2025-10-01 00:41:00 +05:30
parent 8658143b16
commit 8d5067996f
37 changed files with 83187 additions and 82671 deletions

View File

@ -10,6 +10,7 @@ from ctypes import c_void_p, c_int64, c_uint64
# 3. Run the program with sudo: sudo tools/check.sh run examples/binops_demo.py
# 4. Start up any program and watch the output
@bpf
@map
def last() -> HashMap:
@ -23,9 +24,9 @@ def do_trace(ctx: c_void_p) -> c_int64:
tsp = last().lookup(key)
if tsp:
kt = ktime()
delta = (kt - tsp)
delta = kt - tsp
if delta < 1000000000:
time_ms = (delta // 1000000)
time_ms = delta // 1000000
print(f"Execve syscall entered within last second, last {time_ms} ms ago")
last().delete(key)
else:
@ -33,16 +34,18 @@ def do_trace(ctx: c_void_p) -> c_int64:
last().update(key, kt)
return c_int64(0)
@bpf
@section("tracepoint/syscalls/sys_exit_execve")
def do_exit(ctx: c_void_p) -> c_int64:
va = 8
nm = 5 ^ va
al = 6 & 3
ru = (nm + al)
ru = nm + al
print(f"this is a variable {ru}")
return c_int64(0)
@bpf
@bpfglobal
def LICENSE() -> str:

View File

@ -1,8 +1,8 @@
from pythonbpf import bpf, map, section, bpfglobal, compile
from pythonbpf.helpers import ktime, deref
from pythonbpf.helpers import ktime
from pythonbpf.maps import HashMap
from ctypes import c_void_p, c_int64, c_int32, c_uint64
from ctypes import c_void_p, c_int32, c_uint64
@bpf
@ -10,11 +10,12 @@ from ctypes import c_void_p, c_int64, c_int32, c_uint64
def last() -> HashMap:
return HashMap(key=c_uint64, value=c_uint64, max_entries=3)
@bpf
@section("blk_start_request")
def trace_start(ctx: c_void_p) -> c_int32:
ts = ktime()
print("req started")
print(f"req started {ts}")
return c_int32(0)

View File

@ -14,11 +14,13 @@ import matplotlib.pyplot as plt
# Everything is done with Python only code and with the new pylibbpf library.
# Run `sudo /path/to/python/binary/ clone_plot.py`
@bpf
@map
def hist() -> HashMap:
return HashMap(key=c_int32, value=c_uint64, max_entries=4096)
@bpf
@section("tracepoint/syscalls/sys_enter_clone")
def hello(ctx: c_void_p) -> c_int64:

View File

@ -1,4 +1,4 @@
from pythonbpf import bpf, section, bpfglobal, compile, BPF
from pythonbpf import bpf, section, bpfglobal, BPF
from ctypes import c_void_p, c_int64
# Instructions to how to run this program
@ -13,11 +13,13 @@ def hello_world(ctx: c_void_p) -> c_int64:
print("Hello, World!")
return c_int64(0)
@bpf
@bpfglobal
def LICENSE() -> str:
return "GPL"
b = BPF()
b.load_and_attach()
if b.is_loaded() and b.is_attached():

View File

@ -2,7 +2,7 @@ from pythonbpf import bpf, map, struct, section, bpfglobal, compile
from pythonbpf.helpers import ktime, pid
from pythonbpf.maps import PerfEventArray
from ctypes import c_void_p, c_int64, c_int32, c_uint64
from ctypes import c_void_p, c_int32, c_uint64
@bpf

View File

@ -10,6 +10,7 @@ from ctypes import c_void_p, c_int64, c_uint64
# 3. Run the program with sudo: sudo tools/check.sh run examples/sys_sync.o
# 4. Start a Python repl and `import os` and then keep entering `os.sync()` to see reponses.
@bpf
@map
def last() -> HashMap:
@ -23,9 +24,9 @@ def do_trace(ctx: c_void_p) -> c_int64:
tsp = last().lookup(key)
if tsp:
kt = ktime()
delta = (kt - tsp)
delta = kt - tsp
if delta < 1000000000:
time_ms = (delta // 1000000)
time_ms = delta // 1000000
print(f"sync called within last second, last {time_ms} ms ago")
last().delete(key)
else:

View File

@ -149,7 +149,7 @@ class FunctionFactoryStub:
# libraries['FIXME_STUB'] explanation
# As you did not list (-l libraryname.so) a library that exports this function
# This is a non-working stub instead.
# This is a non-working stub instead.
# You can either re-run clan2py with -l /path/to/library.so
# Or manually fix this by comment the ctypes.CDLL loading
_libraries = {}

View File

@ -11,6 +11,7 @@ from ctypes import c_void_p, c_int64
# 4. Attach object file to any network device with something like ./check.sh xdp examples/xdp_pass.o tailscale0
# 5. send traffic through the device and observe effects
@bpf
@map
def count() -> HashMap:
@ -33,9 +34,11 @@ def hello_world(ctx: c_void_p) -> c_int64:
return XDP_PASS
@bpf
@bpfglobal
def LICENSE() -> str:
return "GPL"
compile()