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
b755c709
Commit
b755c709
authored
Jul 18, 2016
by
Brenden Blanco
Committed by
GitHub
Jul 18, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #614 from markdrayton/fix-auto-kprobe
Fix probe detaching and auto-kprobes
parents
a1333bcd
cb679d7b
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
170 additions
and
117 deletions
+170
-117
src/python/bcc/__init__.py
src/python/bcc/__init__.py
+121
-111
src/python/bcc/table.py
src/python/bcc/table.py
+3
-3
tests/python/test_histogram.py
tests/python/test_histogram.py
+3
-0
tests/python/test_probe_count.py
tests/python/test_probe_count.py
+41
-1
tools/argdist.py
tools/argdist.py
+2
-2
No files found.
src/python/bcc/__init__.py
View file @
b755c709
This diff is collapsed.
Click to expand it.
src/python/bcc/table.py
View file @
b755c709
...
...
@@ -393,15 +393,15 @@ class PerfEventArray(ArrayBase):
raise
Exception
(
"Could not open perf buffer"
)
fd
=
lib
.
perf_reader_fd
(
reader
)
self
[
self
.
Key
(
cpu
)]
=
self
.
Leaf
(
fd
)
self
.
bpf
.
open_kprobes
()[(
id
(
self
),
cpu
)]
=
reader
self
.
bpf
.
_add_kprobe
((
id
(
self
),
cpu
),
reader
)
# keep a refcnt
self
.
_cbs
[
cpu
]
=
fn
def
close_perf_buffer
(
self
,
key
):
reader
=
self
.
bpf
.
open_kprobes
()
.
get
((
id
(
self
),
key
))
reader
=
self
.
bpf
.
open_kprobes
.
get
((
id
(
self
),
key
))
if
reader
:
lib
.
perf_reader_free
(
reader
)
del
(
self
.
bpf
.
open_kprobes
()[(
id
(
self
),
key
)]
)
self
.
bpf
.
_del_kprobe
((
id
(
self
),
key
)
)
del
self
.
_cbs
[
key
]
class
PerCpuHash
(
HashTable
):
...
...
tests/python/test_histogram.py
View file @
b755c709
...
...
@@ -31,6 +31,7 @@ int kprobe__htab_map_delete_elem(struct pt_regs *ctx, struct bpf_map *map, u64 *
try
:
del
b
[
"stub"
][
c_ulonglong
(
1
<<
i
)]
except
:
pass
b
[
"hist1"
].
print_log2_hist
()
b
.
cleanup
()
def
test_struct
(
self
):
b
=
BPF
(
text
=
"""
...
...
@@ -52,6 +53,7 @@ int kprobe__htab_map_delete_elem(struct pt_regs *ctx, struct bpf_map *map, u64 *
try
:
del
b
[
"stub2"
][
c_ulonglong
(
1
<<
i
)]
except
:
pass
b
[
"hist1"
].
print_log2_hist
()
b
.
cleanup
()
def
test_chars
(
self
):
b
=
BPF
(
text
=
"""
...
...
@@ -68,6 +70,7 @@ int kprobe__finish_task_switch(struct pt_regs *ctx, struct task_struct *prev) {
"""
)
for
i
in
range
(
0
,
100
):
time
.
sleep
(
0.01
)
b
[
"hist1"
].
print_log2_hist
()
b
.
cleanup
()
if
__name__
==
"__main__"
:
...
...
tests/python/test_probe_count.py
View file @
b755c709
...
...
@@ -2,7 +2,7 @@
# Copyright (c) Suchakra Sharma <suchakrapani.sharma@polymtl.ca>
# Licensed under the Apache License, Version 2.0 (the "License")
from
bcc
import
BPF
from
bcc
import
BPF
,
_get_num_open_probes
import
os
import
sys
from
unittest
import
main
,
TestCase
...
...
@@ -25,6 +25,39 @@ class TestKprobeCnt(TestCase):
open_cnt
=
self
.
b
.
num_open_kprobes
()
self
.
assertEqual
(
actual_cnt
,
open_cnt
)
def
tearDown
(
self
):
self
.
b
.
cleanup
()
class
TestProbeGlobalCnt
(
TestCase
):
def
setUp
(
self
):
self
.
b1
=
BPF
(
text
=
"""int count(void *ctx) { return 0; }"""
)
self
.
b2
=
BPF
(
text
=
"""int count(void *ctx) { return 0; }"""
)
def
test_probe_quota
(
self
):
self
.
b1
.
attach_kprobe
(
event
=
"schedule"
,
fn_name
=
"count"
)
self
.
b2
.
attach_kprobe
(
event
=
"submit_bio"
,
fn_name
=
"count"
)
self
.
assertEqual
(
1
,
self
.
b1
.
num_open_kprobes
())
self
.
assertEqual
(
1
,
self
.
b2
.
num_open_kprobes
())
self
.
assertEqual
(
2
,
_get_num_open_probes
())
self
.
b1
.
cleanup
()
self
.
b2
.
cleanup
()
self
.
assertEqual
(
0
,
_get_num_open_probes
())
class
TestAutoKprobe
(
TestCase
):
def
setUp
(
self
):
self
.
b
=
BPF
(
text
=
"""
int kprobe__schedule(void *ctx) { return 0; }
int kretprobe__schedule(void *ctx) { return 0; }
"""
)
def
test_count
(
self
):
self
.
assertEqual
(
2
,
self
.
b
.
num_open_kprobes
())
def
tearDown
(
self
):
self
.
b
.
cleanup
()
class
TestProbeQuota
(
TestCase
):
def
setUp
(
self
):
...
...
@@ -34,6 +67,10 @@ class TestProbeQuota(TestCase):
with
self
.
assertRaises
(
Exception
):
self
.
b
.
attach_kprobe
(
event_re
=
".*"
,
fn_name
=
"count"
)
def
tearDown
(
self
):
self
.
b
.
cleanup
()
class
TestProbeNotExist
(
TestCase
):
def
setUp
(
self
):
self
.
b
=
BPF
(
text
=
"""int count(void *ctx) { return 0; }"""
)
...
...
@@ -42,6 +79,9 @@ class TestProbeNotExist(TestCase):
with
self
.
assertRaises
(
Exception
):
b
.
attach_kprobe
(
event
=
"___doesnotexist"
,
fn_name
=
"count"
)
def
tearDown
(
self
):
self
.
b
.
cleanup
()
if
__name__
==
"__main__"
:
main
()
tools/argdist.py
View file @
b755c709
...
...
@@ -640,8 +640,8 @@ struct __string_t { char s[%d]; };
for
probe
in
self
.
probes
:
probe
.
attach
(
self
.
bpf
)
if
self
.
args
.
verbose
:
print
(
"open uprobes: %s"
%
BPF
.
open_uprobes
()
)
print
(
"open kprobes: %s"
%
BPF
.
open_kprobes
()
)
print
(
"open uprobes: %s"
%
self
.
bpf
.
open_uprobes
)
print
(
"open kprobes: %s"
%
self
.
bpf
.
open_kprobes
)
def
_main_loop
(
self
):
count_so_far
=
0
...
...
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