FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
ebpf-apps/bcc-apps/python/python_functions.py at main · WormOn/ebpf-apps · GitHub
WormOn
/
ebpf-apps
Public
forked from
feiskyer/ebpf-apps
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
ebpf-apps
/
bcc-apps
/
python
/
python_functions.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
39 lines (32 loc) · 1000 Bytes
Breadcrumbs
ebpf-apps
/
bcc-apps
/
python
/
python_functions.py
Copy path
File metadata and controls
executable file
·
39 lines (32 loc) · 1000 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/python3
#
# Tracing Python functions
import
subprocess
from
bcc
import
BPF
,
USDT
from
bcc
.
utils
import
printb
# find the PID for "python3 -m http.server"
cmd
=
subprocess
.
Popen
(
[
"pgrep"
,
"-f"
,
"http.server"
],
stdout
=
subprocess
.
PIPE
,
shell
=
False
).
communicate
()
if
cmd
[
0
]:
pid
=
int
(
cmd
[
0
].
decode
(
"ascii"
).
strip
())
else
:
print
(
"ERROR: cannot find PID for python3 -m http.server"
)
exit
()
# load BPF program
u
=
USDT
(
pid
=
pid
)
u
.
enable_probe
(
probe
=
"function__entry"
,
fn_name
=
"print_functions"
)
b
=
BPF
(
src_file
=
"python-functions.c"
,
usdt_contexts
=
[
u
])
# callback for perf event
def
print_event
(
cpu
,
data
,
size
):
event
=
b
[
"events"
].
event
(
data
)
printb
(
b"%-9s %-6d %s"
%
(
event
.
filename
,
event
.
lineno
,
event
.
funcname
))
# print header
print
(
"%-9s %-6s %s"
%
(
"FILENAME"
,
"LINENO"
,
"FUNCTION"
))
# loop with callback to print_event
b
[
"events"
].
open_perf_buffer
(
print_event
)
while
1
:
try
:
b
.
perf_buffer_poll
()
except
KeyboardInterrupt
:
exit
()
Back
|
FazBrowse Home
|
New Git URL