Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
bcc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
bcc
Commits
841a4940
Commit
841a4940
authored
Sep 09, 2015
by
4ast
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #195 from iovisor/bblanco_dev
Change auto-loading behavior of trace_print
parents
f63f35bc
e12a95da
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
9 deletions
+20
-9
examples/hello_world.py
examples/hello_world.py
+1
-1
src/python/bcc/__init__.py
src/python/bcc/__init__.py
+19
-8
No files found.
examples/hello_world.py
View file @
841a4940
...
...
@@ -8,4 +8,4 @@
from
bcc
import
BPF
BPF
(
text
=
'void sys_clone(void *ctx) { bpf_trace_printk("Hello, World!
\
\
n"); }'
).
trace_print
()
BPF
(
text
=
'void
kprobe__
sys_clone(void *ctx) { bpf_trace_printk("Hello, World!
\
\
n"); }'
).
trace_print
()
src/python/bcc/__init__.py
View file @
841a4940
...
...
@@ -348,13 +348,20 @@ class BPF(object):
if
self
.
module
==
None
:
raise
Exception
(
"Failed to compile BPF module %s"
%
src_file
)
def
load_func
(
self
,
func_name
,
prog_type
):
# empty func_name signifies auto-detection...works when only 1 fn exists
if
not
func_name
:
if
lib
.
bpf_num_functions
(
self
.
module
)
!=
1
:
raise
Exception
(
"Param func_name is None but num_functions > 1, ambiguous"
)
func_name
=
lib
.
bpf_function_name
(
self
.
module
,
0
).
decode
()
def
load_funcs
(
self
,
prog_type
=
KPROBE
):
"""load_funcs(prog_type=KPROBE)
Load all functions in this BPF module with the given type.
Returns a list of the function handles."""
fns
=
[]
for
i
in
range
(
0
,
lib
.
bpf_num_functions
(
self
.
module
)):
func_name
=
lib
.
bpf_function_name
(
self
.
module
,
i
).
decode
()
fns
.
append
(
self
.
load_func
(
func_name
,
prog_type
))
return
fns
def
load_func
(
self
,
func_name
,
prog_type
):
if
func_name
in
self
.
funcs
:
return
self
.
funcs
[
func_name
]
...
...
@@ -600,8 +607,12 @@ class BPF(object):
# Cater to one-liner case where attach_kprobe is omitted and C function
# name matches that of the kprobe.
if
len
(
open_kprobes
)
==
0
:
fn
=
self
.
load_func
(
None
,
BPF
.
KPROBE
)
self
.
attach_kprobe
(
event
=
fn
.
name
,
fn_name
=
fn
.
name
)
fns
=
self
.
load_funcs
(
BPF
.
KPROBE
)
for
fn
in
fns
:
if
fn
.
name
.
startswith
(
"kprobe__"
):
self
.
attach_kprobe
(
event
=
fn
.
name
[
8
:],
fn_name
=
fn
.
name
)
elif
fn
.
name
.
startswith
(
"kretprobe__"
):
self
.
attach_kprobe
(
event
=
fn
.
name
[
11
:],
fn_name
=
fn
.
name
)
while
True
:
if
fmt
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment