Skip to content

Commit 576fa2f

Browse files
committed
Add interactive Python notebook for hello_world BCC Example
1 parent 76a873c commit 576fa2f

File tree

1 file changed

+116
-0
lines changed

1 file changed

+116
-0
lines changed

BCC-Examples/hello_world.ipynb

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 9,
6+
"id": "7d5d3cfb-39ba-4516-9856-b3bed47a0cef",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"from pythonbpf import bpf, section, bpfglobal, BPF, trace_pipe\n",
11+
"from ctypes import c_void_p, c_int64"
12+
]
13+
},
14+
{
15+
"cell_type": "code",
16+
"execution_count": 10,
17+
"id": "cf1c87aa-e173-4156-8f2d-762225bc6d19",
18+
"metadata": {},
19+
"outputs": [],
20+
"source": [
21+
"@bpf\n",
22+
"@section(\"tracepoint/syscalls/sys_enter_clone\")\n",
23+
"def hello_world(ctx: c_void_p) -> c_int64:\n",
24+
" print(\"Hello, World!\")\n",
25+
" return 0\n",
26+
"\n",
27+
"\n",
28+
"@bpf\n",
29+
"@bpfglobal\n",
30+
"def LICENSE() -> str:\n",
31+
" return \"GPL\"\n",
32+
"\n",
33+
"\n",
34+
"b = BPF()"
35+
]
36+
},
37+
{
38+
"cell_type": "code",
39+
"execution_count": null,
40+
"id": "bd81383d-f75a-4269-8451-3d985d85b124",
41+
"metadata": {
42+
"scrolled": true
43+
},
44+
"outputs": [
45+
{
46+
"name": "stdout",
47+
"output_type": "stream",
48+
"text": [
49+
" Cache2 I/O-4716 [003] ...21 8218.000492: bpf_trace_printk: count: 11 with 4716\n",
50+
"\n",
51+
" Cache2 I/O-4716 [003] ...21 8218.000499: bpf_trace_printk: Hello, World!\n",
52+
"\n",
53+
" WebExtensions-5168 [002] ...21 8219.320392: bpf_trace_printk: count: 13 with 5168\n",
54+
"\n",
55+
" WebExtensions-5168 [002] ...21 8219.320399: bpf_trace_printk: Hello, World!\n",
56+
"\n",
57+
" python-21155 [001] ...21 8220.933716: bpf_trace_printk: count: 5 with 21155\n",
58+
"\n",
59+
" python-21155 [001] ...21 8220.933721: bpf_trace_printk: Hello, World!\n",
60+
"\n",
61+
" python-21155 [002] ...21 8221.341290: bpf_trace_printk: count: 6 with 21155\n",
62+
"\n",
63+
" python-21155 [002] ...21 8221.341295: bpf_trace_printk: Hello, World!\n",
64+
"\n",
65+
" Isolated Web Co-5462 [000] ...21 8223.095033: bpf_trace_printk: count: 7 with 5462\n",
66+
"\n",
67+
" Isolated Web Co-5462 [000] ...21 8223.095043: bpf_trace_printk: Hello, World!\n",
68+
"\n",
69+
" firefox-4542 [000] ...21 8227.760067: bpf_trace_printk: count: 8 with 4542\n",
70+
"\n",
71+
" firefox-4542 [000] ...21 8227.760080: bpf_trace_printk: Hello, World!\n",
72+
"\n",
73+
" Isolated Web Co-12404 [003] ...21 8227.917086: bpf_trace_printk: count: 7 with 12404\n",
74+
"\n",
75+
" Isolated Web Co-12404 [003] ...21 8227.917095: bpf_trace_printk: Hello, World!\n",
76+
"\n"
77+
]
78+
}
79+
],
80+
"source": [
81+
"b.load()\n",
82+
"b.attach_all()\n",
83+
"trace_pipe()"
84+
]
85+
},
86+
{
87+
"cell_type": "code",
88+
"execution_count": null,
89+
"id": "01e1f25b-decc-425b-a1aa-a5e701082574",
90+
"metadata": {},
91+
"outputs": [],
92+
"source": []
93+
}
94+
],
95+
"metadata": {
96+
"kernelspec": {
97+
"display_name": "Python 3 (ipykernel)",
98+
"language": "python",
99+
"name": "python3"
100+
},
101+
"language_info": {
102+
"codemirror_mode": {
103+
"name": "ipython",
104+
"version": 3
105+
},
106+
"file_extension": ".py",
107+
"mimetype": "text/x-python",
108+
"name": "python",
109+
"nbconvert_exporter": "python",
110+
"pygments_lexer": "ipython3",
111+
"version": "3.13.3"
112+
}
113+
},
114+
"nbformat": 4,
115+
"nbformat_minor": 5
116+
}

0 commit comments

Comments
 (0)