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
f63f35bc
Commit
f63f35bc
authored
Sep 08, 2015
by
4ast
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #194 from iovisor/bblanco_dev
Support automatic kprobe event detection in common case
parents
8d0425cb
4fd308f9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
8 deletions
+21
-8
examples/hello_world.py
examples/hello_world.py
+1
-3
src/python/bcc/__init__.py
src/python/bcc/__init__.py
+20
-5
No files found.
examples/hello_world.py
View file @
f63f35bc
...
...
@@ -8,6 +8,4 @@
from
bcc
import
BPF
b
=
BPF
(
text
=
'void hello(void *ctx) { bpf_trace_printk("Hello, World!
\
\
n"); }'
)
b
.
attach_kprobe
(
event
=
"sys_clone"
,
fn_name
=
"hello"
)
b
.
trace_print
()
BPF
(
text
=
'void sys_clone(void *ctx) { bpf_trace_printk("Hello, World!
\
\
n"); }'
).
trace_print
()
src/python/bcc/__init__.py
View file @
f63f35bc
...
...
@@ -38,6 +38,10 @@ lib.bpf_module_license.restype = ct.c_char_p
lib
.
bpf_module_license
.
argtypes
=
[
ct
.
c_void_p
]
lib
.
bpf_module_kern_version
.
restype
=
ct
.
c_uint
lib
.
bpf_module_kern_version
.
argtypes
=
[
ct
.
c_void_p
]
lib
.
bpf_num_functions
.
restype
=
ct
.
c_ulonglong
lib
.
bpf_num_functions
.
argtypes
=
[
ct
.
c_void_p
]
lib
.
bpf_function_name
.
restype
=
ct
.
c_char_p
lib
.
bpf_function_name
.
argtypes
=
[
ct
.
c_void_p
,
ct
.
c_ulonglong
]
lib
.
bpf_function_start
.
restype
=
ct
.
c_void_p
lib
.
bpf_function_start
.
argtypes
=
[
ct
.
c_void_p
,
ct
.
c_char_p
]
lib
.
bpf_function_size
.
restype
=
ct
.
c_size_t
...
...
@@ -345,6 +349,12 @@ class BPF(object):
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
()
if
func_name
in
self
.
funcs
:
return
self
.
funcs
[
func_name
]
...
...
@@ -578,9 +588,8 @@ class BPF(object):
exit
()
return
line
@
staticmethod
def
trace_print
(
fmt
=
None
):
"""trace_print(fmt=None)
def
trace_print
(
self
,
fmt
=
None
):
"""trace_print(self, fmt=None)
Read from the kernel debug trace pipe and print on stdout.
If fmt is specified, apply as a format string to the output. See
...
...
@@ -588,13 +597,19 @@ class BPF(object):
example: trace_print(fmt="pid {1}, msg = {5}")
"""
# 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
)
while
True
:
if
fmt
:
fields
=
BPF
.
trace_fields
(
nonblocking
=
False
)
fields
=
self
.
trace_fields
(
nonblocking
=
False
)
if
not
fields
:
continue
line
=
fmt
.
format
(
*
fields
)
else
:
line
=
BPF
.
trace_readline
(
nonblocking
=
False
)
line
=
self
.
trace_readline
(
nonblocking
=
False
)
print
(
line
)
sys
.
stdout
.
flush
()
...
...
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