Skip to content

Commit f489129

Browse files
Merge pull request #9 from pythonbpf/refactor
Cleanup and rename examples
2 parents 912d0c8 + 0d0a318 commit f489129

24 files changed

Lines changed: 20 additions & 167 deletions
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
# Instructions to how to run this program
88
# 1. Install PythonBPF: pip install pythonbpf
9-
# 2. Run the program: python demo/pybpf3.py
10-
# 3. Run the program with sudo: sudo examples/check.sh run demo/pybpf3.o
9+
# 2. Run the program: python examples/binops_demo.py
10+
# 3. Run the program with sudo: sudo tools/check.sh run examples/binops_demo.py
1111
# 4. Start up any program and watch the output
1212

1313
@bpf
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# and then plots the distribution as a histogram using matplotlib.
1313
# It provides a quick view of process creation activity over 10 seconds.
1414
# Everything is done with Python only code and with the new pylibbpf library.
15-
# Run `sudo /path/to/python/binary/ pybpf4.py`
15+
# Run `sudo /path/to/python/binary/ clone_plot.py`
1616

1717
@bpf
1818
@map

examples/execve2.py

Lines changed: 0 additions & 35 deletions
This file was deleted.

examples/execve3.py

Lines changed: 0 additions & 45 deletions
This file was deleted.
Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
from pythonbpf import bpf, section, bpfglobal, compile
2-
1+
from pythonbpf import bpf, section, bpfglobal, compile, BPF
32
from ctypes import c_void_p, c_int64
43

54
# Instructions to how to run this program
65
# 1. Install PythonBPF: pip install pythonbpf
7-
# 2. Run the program: python demo/pybpf0.py
8-
# 3. Run the program with sudo: sudo examples/check.sh run demo/pybpf0.o
6+
# 2. Run the program: sudo python examples/hello_world.py
97
# 4. Start up any program and watch the output
108

119

@@ -20,4 +18,11 @@ def hello_world(ctx: c_void_p) -> c_int64:
2018
def LICENSE() -> str:
2119
return "GPL"
2220

23-
compile()
21+
b = BPF()
22+
b.load_and_attach()
23+
if b.is_loaded() and b.is_attached():
24+
print("Successfully loaded and attached")
25+
else:
26+
print("Could not load successfully")
27+
28+
# Now cat /sys/kernel/debug/tracing/trace_pipe to see results of the execve syscall.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
# Instructions to how to run this program
88
# 1. Install PythonBPF: pip install pythonbpf
9-
# 2. Run the program: python demo/pybpf2.py
10-
# 3. Run the program with sudo: sudo examples/check.sh run demo/pybpf2.o
9+
# 2. Run the program: python examples/sys_sync.py
10+
# 3. Run the program with sudo: sudo tools/check.sh run examples/sys_sync.o
1111
# 4. Start a Python repl and `import os` and then keep entering `os.sync()` to see reponses.
1212

1313
@bpf
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
# Instructions to how to run this program
88
# 1. Install PythonBPF: pip install pythonbpf
9-
# 2. Run the program: python demo/pybpf1.py
10-
# 3. Run the program with sudo: sudo examples/check.sh run demo/pybpf1.o
11-
# 4. Attach object file to any network device with something like ./check.sh xdp ../demo/pybpf1.o tailscale0
9+
# 2. Run the program: python examples/xdp_pass.py
10+
# 3. Run the program with sudo: sudo tools/check.sh run examples/xdp_pass.o
11+
# 4. Attach object file to any network device with something like ./check.sh xdp examples/xdp_pass.o tailscale0
1212
# 5. send traffic through the device and observe effects
1313

1414
@bpf

pythonbpf/bpf_helper_handler.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ def bpf_printk_emitter(call, map_ptr, module, builder, func, local_sym_tab=None,
219219

220220
builder.call(fn_ptr, [fmt_ptr, ir.Constant(
221221
ir.IntType(32), len(fmt_str))], tail=True)
222+
return None
222223

223224

224225
def bpf_map_update_elem_emitter(call, map_ptr, module, builder, func, local_sym_tab=None, struct_sym_tab=None, local_var_metadata=None):
@@ -496,3 +497,4 @@ def handle_helper_call(call, module, builder, func, local_sym_tab=None, map_sym_
496497
else:
497498
raise NotImplementedError(
498499
"Attribute not supported for map method calls.")
500+
return None

0 commit comments

Comments
 (0)