mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2025-12-31 21:06:25 +00:00
Fix examples/clone_plot to use new syntax and pylibbpf API
This commit is contained in:
@ -3,7 +3,6 @@ import time
|
|||||||
from pythonbpf import bpf, map, section, bpfglobal, BPF
|
from pythonbpf import bpf, map, section, bpfglobal, BPF
|
||||||
from pythonbpf.helper import pid
|
from pythonbpf.helper import pid
|
||||||
from pythonbpf.maps import HashMap
|
from pythonbpf.maps import HashMap
|
||||||
from pylibbpf import BpfMap
|
|
||||||
from ctypes import c_void_p, c_int64, c_uint64, c_int32
|
from ctypes import c_void_p, c_int64, c_uint64, c_int32
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
@ -26,14 +25,14 @@ def hist() -> HashMap:
|
|||||||
def hello(ctx: c_void_p) -> c_int64:
|
def hello(ctx: c_void_p) -> c_int64:
|
||||||
process_id = pid()
|
process_id = pid()
|
||||||
one = 1
|
one = 1
|
||||||
prev = hist().lookup(process_id)
|
prev = hist.lookup(process_id)
|
||||||
if prev:
|
if prev:
|
||||||
previous_value = prev + 1
|
previous_value = prev + 1
|
||||||
print(f"count: {previous_value} with {process_id}")
|
print(f"count: {previous_value} with {process_id}")
|
||||||
hist().update(process_id, previous_value)
|
hist.update(process_id, previous_value)
|
||||||
return c_int64(0)
|
return c_int64(0)
|
||||||
else:
|
else:
|
||||||
hist().update(process_id, one)
|
hist.update(process_id, one)
|
||||||
return c_int64(0)
|
return c_int64(0)
|
||||||
|
|
||||||
|
|
||||||
@ -44,12 +43,12 @@ def LICENSE() -> str:
|
|||||||
|
|
||||||
|
|
||||||
b = BPF()
|
b = BPF()
|
||||||
b.load_and_attach()
|
b.load()
|
||||||
hist = BpfMap(b, hist)
|
b.attach_all()
|
||||||
print("Recording")
|
print("Recording")
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
|
|
||||||
counts = list(hist.values())
|
counts = list(b["hist"].values())
|
||||||
|
|
||||||
plt.hist(counts, bins=20)
|
plt.hist(counts, bins=20)
|
||||||
plt.xlabel("Clone calls per PID")
|
plt.xlabel("Clone calls per PID")
|
||||||
|
|||||||
Reference in New Issue
Block a user