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
ed85df7d
Commit
ed85df7d
authored
Sep 10, 2015
by
4ast
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #200 from iovisor/bblanco_dev
Improve coverage for kprobe event_re
parents
076e8ab2
7e71aef9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
10 deletions
+28
-10
src/cc/libbpf.c
src/cc/libbpf.c
+3
-1
src/python/bcc/__init__.py
src/python/bcc/__init__.py
+18
-9
tests/cc/test_trace4.py
tests/cc/test_trace4.py
+7
-0
No files found.
src/cc/libbpf.c
View file @
ed85df7d
...
@@ -239,7 +239,9 @@ int bpf_attach_kprobe(int progfd, const char *event,
...
@@ -239,7 +239,9 @@ int bpf_attach_kprobe(int progfd, const char *event,
}
}
if
(
write
(
kfd
,
event_desc
,
strlen
(
event_desc
))
<
0
)
{
if
(
write
(
kfd
,
event_desc
,
strlen
(
event_desc
))
<
0
)
{
perror
(
"write(kprobe_events)"
);
fprintf
(
stderr
,
"write of
\"
%s
\"
into kprobe_events failed: %s
\n
"
,
event_desc
,
strerror
(
errno
));
if
(
errno
==
EINVAL
)
fprintf
(
stderr
,
"check dmesg output for possible cause
\n
"
);
goto
cleanup
;
goto
cleanup
;
}
}
...
...
src/python/bcc/__init__.py
View file @
ed85df7d
...
@@ -473,7 +473,10 @@ class BPF(object):
...
@@ -473,7 +473,10 @@ class BPF(object):
p
=
Popen
([
"awk"
,
"$1 ~ /%s/ { print $1 }"
%
event_re
,
p
=
Popen
([
"awk"
,
"$1 ~ /%s/ { print $1 }"
%
event_re
,
"%s/available_filter_functions"
%
TRACEFS
],
stdout
=
PIPE
)
"%s/available_filter_functions"
%
TRACEFS
],
stdout
=
PIPE
)
lines
=
p
.
communicate
()[
0
].
decode
().
split
()
lines
=
p
.
communicate
()[
0
].
decode
().
split
()
return
[
line
.
rstrip
()
for
line
in
lines
if
line
!=
"
\
n
"
]
with
open
(
"%s/../kprobes/blacklist"
%
TRACEFS
)
as
f
:
blacklist
=
[
line
.
split
()[
1
]
for
line
in
f
.
readlines
()]
return
[
line
.
rstrip
()
for
line
in
lines
if
(
line
!=
"
\
n
"
and
line
not
in
blacklist
)]
def
attach_kprobe
(
self
,
event
=
""
,
fn_name
=
""
,
event_re
=
""
,
def
attach_kprobe
(
self
,
event
=
""
,
fn_name
=
""
,
event_re
=
""
,
pid
=
0
,
cpu
=-
1
,
group_fd
=-
1
):
pid
=
0
,
cpu
=-
1
,
group_fd
=-
1
):
...
@@ -481,12 +484,15 @@ class BPF(object):
...
@@ -481,12 +484,15 @@ class BPF(object):
# allow the caller to glob multiple functions together
# allow the caller to glob multiple functions together
if
event_re
:
if
event_re
:
for
line
in
BPF
.
_get_kprobe_functions
(
event_re
):
for
line
in
BPF
.
_get_kprobe_functions
(
event_re
):
self
.
attach_kprobe
(
event
=
line
,
fn_name
=
fn_name
,
pid
=
pid
,
try
:
cpu
=
cpu
,
group_fd
=
group_fd
)
self
.
attach_kprobe
(
event
=
line
,
fn_name
=
fn_name
,
pid
=
pid
,
cpu
=
cpu
,
group_fd
=
group_fd
)
except
:
pass
return
return
fn
=
self
.
load_func
(
fn_name
,
BPF
.
KPROBE
)
fn
=
self
.
load_func
(
fn_name
,
BPF
.
KPROBE
)
ev_name
=
"p_"
+
event
.
replace
(
"+"
,
"_"
)
ev_name
=
"p_"
+
event
.
replace
(
"+"
,
"_"
)
.
replace
(
"."
,
"_"
)
desc
=
"p:kprobes/%s %s"
%
(
ev_name
,
event
)
desc
=
"p:kprobes/%s %s"
%
(
ev_name
,
event
)
res
=
lib
.
bpf_attach_kprobe
(
fn
.
fd
,
ev_name
.
encode
(
"ascii"
),
res
=
lib
.
bpf_attach_kprobe
(
fn
.
fd
,
ev_name
.
encode
(
"ascii"
),
desc
.
encode
(
"ascii"
),
pid
,
cpu
,
group_fd
)
desc
.
encode
(
"ascii"
),
pid
,
cpu
,
group_fd
)
...
@@ -497,7 +503,7 @@ class BPF(object):
...
@@ -497,7 +503,7 @@ class BPF(object):
@
staticmethod
@
staticmethod
def
detach_kprobe
(
event
):
def
detach_kprobe
(
event
):
ev_name
=
"p_"
+
event
.
replace
(
"+"
,
"_"
)
ev_name
=
"p_"
+
event
.
replace
(
"+"
,
"_"
)
.
replace
(
"."
,
"_"
)
if
ev_name
not
in
open_kprobes
:
if
ev_name
not
in
open_kprobes
:
raise
Exception
(
"Kprobe %s is not attached"
%
event
)
raise
Exception
(
"Kprobe %s is not attached"
%
event
)
os
.
close
(
open_kprobes
[
ev_name
])
os
.
close
(
open_kprobes
[
ev_name
])
...
@@ -513,12 +519,15 @@ class BPF(object):
...
@@ -513,12 +519,15 @@ class BPF(object):
# allow the caller to glob multiple functions together
# allow the caller to glob multiple functions together
if
event_re
:
if
event_re
:
for
line
in
BPF
.
_get_kprobe_functions
(
event_re
):
for
line
in
BPF
.
_get_kprobe_functions
(
event_re
):
self
.
attach_kretprobe
(
event
=
line
,
fn_name
=
fn_name
,
pid
=
pid
,
try
:
cpu
=
cpu
,
group_fd
=
group_fd
)
self
.
attach_kretprobe
(
event
=
line
,
fn_name
=
fn_name
,
pid
=
pid
,
cpu
=
cpu
,
group_fd
=
group_fd
)
except
:
pass
return
return
fn
=
self
.
load_func
(
fn_name
,
BPF
.
KPROBE
)
fn
=
self
.
load_func
(
fn_name
,
BPF
.
KPROBE
)
ev_name
=
"r_"
+
event
.
replace
(
"+"
,
"_"
)
ev_name
=
"r_"
+
event
.
replace
(
"+"
,
"_"
)
.
replace
(
"."
,
"_"
)
desc
=
"r:kprobes/%s %s"
%
(
ev_name
,
event
)
desc
=
"r:kprobes/%s %s"
%
(
ev_name
,
event
)
res
=
lib
.
bpf_attach_kprobe
(
fn
.
fd
,
ev_name
.
encode
(
"ascii"
),
res
=
lib
.
bpf_attach_kprobe
(
fn
.
fd
,
ev_name
.
encode
(
"ascii"
),
desc
.
encode
(
"ascii"
),
pid
,
cpu
,
group_fd
)
desc
.
encode
(
"ascii"
),
pid
,
cpu
,
group_fd
)
...
@@ -529,7 +538,7 @@ class BPF(object):
...
@@ -529,7 +538,7 @@ class BPF(object):
@
staticmethod
@
staticmethod
def
detach_kretprobe
(
event
):
def
detach_kretprobe
(
event
):
ev_name
=
"r_"
+
event
.
replace
(
"+"
,
"_"
)
ev_name
=
"r_"
+
event
.
replace
(
"+"
,
"_"
)
.
replace
(
"."
,
"_"
)
if
ev_name
not
in
open_kprobes
:
if
ev_name
not
in
open_kprobes
:
raise
Exception
(
"Kretprobe %s is not attached"
%
event
)
raise
Exception
(
"Kretprobe %s is not attached"
%
event
)
os
.
close
(
open_kprobes
[
ev_name
])
os
.
close
(
open_kprobes
[
ev_name
])
...
...
tests/cc/test_trace4.py
View file @
ed85df7d
...
@@ -30,5 +30,12 @@ class TestKprobeRgx(TestCase):
...
@@ -30,5 +30,12 @@ class TestKprobeRgx(TestCase):
k2
=
self
.
b
[
"stats"
].
Key
(
2
)
k2
=
self
.
b
[
"stats"
].
Key
(
2
)
self
.
assertEqual
(
self
.
b
[
"stats"
][
k1
].
val
,
self
.
b
[
"stats"
][
k2
].
val
+
1
)
self
.
assertEqual
(
self
.
b
[
"stats"
][
k1
].
val
,
self
.
b
[
"stats"
][
k2
].
val
+
1
)
class
TestKprobeReplace
(
TestCase
):
def
setUp
(
self
):
self
.
b
=
BPF
(
text
=
"int empty(void *ctx) { return 0; }"
)
def
test_periods
(
self
):
self
.
b
.
attach_kprobe
(
event_re
=
"^tcp_enter_cwr.*"
,
fn_name
=
"empty"
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
main
()
main
()
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