mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2025-12-31 21:06:25 +00:00
Merge branch 'master' into helper-refactor
This commit is contained in:
@ -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:
|
||||
|
||||
@ -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)
|
||||
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@ import time
|
||||
from pythonbpf import bpf, map, section, bpfglobal, BPF
|
||||
from pythonbpf.helpers import pid
|
||||
from pythonbpf.maps import HashMap
|
||||
from pylibbpf import *
|
||||
from pylibbpf import BpfMap
|
||||
from ctypes import c_void_p, c_int64, c_uint64, c_int32
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -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():
|
||||
|
||||
@ -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
|
||||
@ -27,7 +27,10 @@ def hello(ctx: c_void_p) -> c_int32:
|
||||
dataobj.pid = pid()
|
||||
dataobj.ts = ktime()
|
||||
# dataobj.comm = strobj
|
||||
print(f"clone called at {dataobj.ts} by pid {dataobj.pid}, comm {strobj}")
|
||||
print(
|
||||
f"clone called at {dataobj.ts} by pid {
|
||||
dataobj.pid}, comm {strobj} at time {ts}"
|
||||
)
|
||||
events.output(dataobj)
|
||||
return c_int32(0)
|
||||
|
||||
|
||||
@ -24,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:
|
||||
|
||||
@ -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 = {}
|
||||
|
||||
@ -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()
|
||||
|
||||
Reference in New Issue
Block a user