Skip to content

Commit cb1ad15

Browse files
committed
Fix examples/clone_plot to use new syntax and pylibbpf API
1 parent b24b3ed commit cb1ad15

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

examples/clone_plot.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from pythonbpf import bpf, map, section, bpfglobal, BPF
44
from pythonbpf.helper import pid
55
from pythonbpf.maps import HashMap
6-
from pylibbpf import BpfMap
76
from ctypes import c_void_p, c_int64, c_uint64, c_int32
87
import matplotlib.pyplot as plt
98

@@ -26,14 +25,14 @@ def hist() -> HashMap:
2625
def hello(ctx: c_void_p) -> c_int64:
2726
process_id = pid()
2827
one = 1
29-
prev = hist().lookup(process_id)
28+
prev = hist.lookup(process_id)
3029
if prev:
3130
previous_value = prev + 1
3231
print(f"count: {previous_value} with {process_id}")
33-
hist().update(process_id, previous_value)
32+
hist.update(process_id, previous_value)
3433
return c_int64(0)
3534
else:
36-
hist().update(process_id, one)
35+
hist.update(process_id, one)
3736
return c_int64(0)
3837

3938

@@ -44,12 +43,12 @@ def LICENSE() -> str:
4443

4544

4645
b = BPF()
47-
b.load_and_attach()
48-
hist = BpfMap(b, hist)
46+
b.load()
47+
b.attach_all()
4948
print("Recording")
5049
time.sleep(10)
5150

52-
counts = list(hist.values())
51+
counts = list(b["hist"].values())
5352

5453
plt.hist(counts, bins=20)
5554
plt.xlabel("Clone calls per PID")

0 commit comments

Comments
 (0)