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
ef67bb2a
Commit
ef67bb2a
authored
Aug 19, 2015
by
4ast
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #151 from iovisor/bblanco_dev
Change API of attach_kprobe to take a name argument
parents
307ac0b3
5eef65e6
Changes
13
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
31 additions
and
42 deletions
+31
-42
examples/bitehist.py
examples/bitehist.py
+1
-1
examples/disksnoop.py
examples/disksnoop.py
+2
-2
examples/hello_world.py
examples/hello_world.py
+1
-2
examples/task_switch.py
examples/task_switch.py
+1
-2
examples/vfsreadlat.py
examples/vfsreadlat.py
+2
-2
src/python/bpf/__init__.py
src/python/bpf/__init__.py
+4
-8
tests/cc/test_trace1.py
tests/cc/test_trace1.py
+3
-6
tests/cc/test_trace2.py
tests/cc/test_trace2.py
+1
-2
tests/cc/test_trace3.py
tests/cc/test_trace3.py
+4
-4
tools/pidpersec
tools/pidpersec
+1
-1
tools/syncsnoop
tools/syncsnoop
+1
-1
tools/vfscount
tools/vfscount
+5
-6
tools/vfsstat
tools/vfsstat
+5
-5
No files found.
examples/bitehist.py
View file @
ef67bb2a
...
@@ -39,7 +39,7 @@ if len(argv) > 1:
...
@@ -39,7 +39,7 @@ if len(argv) > 1:
# load BPF program
# load BPF program
b
=
BPF
(
src_file
=
"bitehist.c"
)
b
=
BPF
(
src_file
=
"bitehist.c"
)
BPF
.
attach_kprobe
(
b
.
load_func
(
"do_request"
,
BPF
.
KPROBE
),
"blk_start
_request"
)
b
.
attach_kprobe
(
event
=
"blk_start_request"
,
fn_name
=
"do
_request"
)
dist
=
b
.
get_table
(
"dist"
)
dist
=
b
.
get_table
(
"dist"
)
dist_max
=
64
dist_max
=
64
...
...
examples/disksnoop.py
View file @
ef67bb2a
...
@@ -18,8 +18,8 @@ REQ_WRITE = 1 # from include/linux/blk_types.h
...
@@ -18,8 +18,8 @@ REQ_WRITE = 1 # from include/linux/blk_types.h
# load BPF program
# load BPF program
b
=
BPF
(
src_file
=
"disksnoop.c"
)
b
=
BPF
(
src_file
=
"disksnoop.c"
)
BPF
.
attach_kprobe
(
b
.
load_func
(
"do_request"
,
BPF
.
KPROBE
),
"blk_start
_request"
)
b
.
attach_kprobe
(
event
=
"blk_start_request"
,
fn_name
=
"do
_request"
)
BPF
.
attach_kprobe
(
b
.
load_func
(
"do_completion"
,
BPF
.
KPROBE
),
"blk_update_request
"
)
b
.
attach_kprobe
(
event
=
"blk_update_request"
,
fn_name
=
"do_completion
"
)
# header
# header
print
(
"%-18s %-2s %-7s %8s"
%
(
"TIME(s)"
,
"T"
,
"BYTES"
,
"LAT(ms)"
))
print
(
"%-18s %-2s %-7s %8s"
%
(
"TIME(s)"
,
"T"
,
"BYTES"
,
"LAT(ms)"
))
...
...
examples/hello_world.py
View file @
ef67bb2a
...
@@ -15,8 +15,7 @@ int hello(void *ctx) {
...
@@ -15,8 +15,7 @@ int hello(void *ctx) {
};
};
"""
"""
b
=
BPF
(
text
=
prog
)
b
=
BPF
(
text
=
prog
)
fn
=
b
.
load_func
(
"hello"
,
BPF
.
KPROBE
)
b
.
attach_kprobe
(
event
=
"sys_clone"
,
fn_name
=
"hello"
)
BPF
.
attach_kprobe
(
fn
,
"sys_clone"
)
try
:
try
:
call
([
"cat"
,
"/sys/kernel/debug/tracing/trace_pipe"
])
call
([
"cat"
,
"/sys/kernel/debug/tracing/trace_pipe"
])
except
KeyboardInterrupt
:
except
KeyboardInterrupt
:
...
...
examples/task_switch.py
View file @
ef67bb2a
...
@@ -6,9 +6,8 @@ from bpf import BPF
...
@@ -6,9 +6,8 @@ from bpf import BPF
from
time
import
sleep
from
time
import
sleep
b
=
BPF
(
src_file
=
"task_switch.c"
)
b
=
BPF
(
src_file
=
"task_switch.c"
)
fn
=
b
.
load_func
(
"count_sched"
,
BPF
.
KPROBE
)
stats
=
b
.
get_table
(
"stats"
)
stats
=
b
.
get_table
(
"stats"
)
BPF
.
attach_kprobe
(
fn
,
"finish_task_switch
"
)
b
.
attach_kprobe
(
event
=
"finish_task_switch"
,
fn_name
=
"count_sched
"
)
# generate many schedule events
# generate many schedule events
for
i
in
range
(
0
,
100
):
sleep
(
0.01
)
for
i
in
range
(
0
,
100
):
sleep
(
0.01
)
...
...
examples/vfsreadlat.py
View file @
ef67bb2a
...
@@ -39,8 +39,8 @@ if len(argv) > 1:
...
@@ -39,8 +39,8 @@ if len(argv) > 1:
# load BPF program
# load BPF program
b
=
BPF
(
src_file
=
"vfsreadlat.c"
)
b
=
BPF
(
src_file
=
"vfsreadlat.c"
)
BPF
.
attach_kprobe
(
b
.
load_func
(
"do_entry"
,
BPF
.
KPROBE
),
"vfs_read
"
)
b
.
attach_kprobe
(
event
=
"vfs_read"
,
fn_name
=
"do_entry
"
)
BPF
.
attach_kretprobe
(
b
.
load_func
(
"do_return"
,
BPF
.
KPROBE
),
"vfs_read
"
)
b
.
attach_kretprobe
(
event
=
"vfs_read"
,
fn_name
=
"do_return
"
)
dist
=
b
.
get_table
(
"dist"
)
dist
=
b
.
get_table
(
"dist"
)
dist_max
=
64
dist_max
=
64
...
...
src/python/bpf/__init__.py
View file @
ef67bb2a
...
@@ -325,10 +325,8 @@ class BPF(object):
...
@@ -325,10 +325,8 @@ class BPF(object):
%
(
dev
,
errstr
))
%
(
dev
,
errstr
))
fn
.
sock
=
sock
fn
.
sock
=
sock
@
staticmethod
def
attach_kprobe
(
self
,
event
=
""
,
fn_name
=
""
,
pid
=
0
,
cpu
=-
1
,
group_fd
=-
1
):
def
attach_kprobe
(
fn
,
event
,
pid
=
0
,
cpu
=-
1
,
group_fd
=-
1
):
fn
=
self
.
load_func
(
fn_name
,
BPF
.
KPROBE
)
if
not
isinstance
(
fn
,
BPF
.
Function
):
raise
Exception
(
"arg 1 must be of type BPF.Function"
)
ev_name
=
"p_"
+
event
.
replace
(
"+"
,
"_"
)
ev_name
=
"p_"
+
event
.
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"
),
...
@@ -350,10 +348,8 @@ class BPF(object):
...
@@ -350,10 +348,8 @@ class BPF(object):
raise
Exception
(
"Failed to detach BPF from kprobe"
)
raise
Exception
(
"Failed to detach BPF from kprobe"
)
del
open_kprobes
[
ev_name
]
del
open_kprobes
[
ev_name
]
@
staticmethod
def
attach_kretprobe
(
self
,
event
=
""
,
fn_name
=
""
,
pid
=-
1
,
cpu
=
0
,
group_fd
=-
1
):
def
attach_kretprobe
(
fn
,
event
,
pid
=-
1
,
cpu
=
0
,
group_fd
=-
1
):
fn
=
self
.
load_func
(
fn_name
,
BPF
.
KPROBE
)
if
not
isinstance
(
fn
,
BPF
.
Function
):
raise
Exception
(
"arg 1 must be of type BPF.Function"
)
ev_name
=
"r_"
+
event
.
replace
(
"+"
,
"_"
)
ev_name
=
"r_"
+
event
.
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"
),
...
...
tests/cc/test_trace1.py
View file @
ef67bb2a
...
@@ -26,13 +26,10 @@ if arg1.endswith(".b"):
...
@@ -26,13 +26,10 @@ if arg1.endswith(".b"):
class
TestKprobe
(
TestCase
):
class
TestKprobe
(
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
b
=
BPF
(
arg1
,
arg2
,
debug
=
0
)
b
=
BPF
(
arg1
,
arg2
,
debug
=
0
)
fn1
=
b
.
load_func
(
"sys_wr"
,
BPF
.
KPROBE
)
fn2
=
b
.
load_func
(
"sys_rd"
,
BPF
.
KPROBE
)
fn3
=
b
.
load_func
(
"sys_bpf"
,
BPF
.
KPROBE
)
self
.
stats
=
b
.
get_table
(
"stats"
,
Key
,
Leaf
)
self
.
stats
=
b
.
get_table
(
"stats"
,
Key
,
Leaf
)
BPF
.
attach_kprobe
(
fn1
,
"sys_write"
,
0
,
-
1
)
b
.
attach_kprobe
(
event
=
"sys_write"
,
fn_name
=
"sys_wr"
,
pid
=
0
,
cpu
=
-
1
)
BPF
.
attach_kprobe
(
fn2
,
"sys_read"
,
0
,
-
1
)
b
.
attach_kprobe
(
event
=
"sys_read"
,
fn_name
=
"sys_rd"
,
pid
=
0
,
cpu
=
-
1
)
BPF
.
attach_kprobe
(
fn2
,
"htab_map_get_next_key"
,
0
,
-
1
)
b
.
attach_kprobe
(
event
=
"htab_map_get_next_key"
,
fn_name
=
"sys_rd"
,
pid
=
0
,
cpu
=
-
1
)
def
test_trace1
(
self
):
def
test_trace1
(
self
):
with
open
(
"/dev/null"
,
"a"
)
as
f
:
with
open
(
"/dev/null"
,
"a"
)
as
f
:
...
...
tests/cc/test_trace2.py
View file @
ef67bb2a
...
@@ -25,9 +25,8 @@ int count_sched(struct pt_regs *ctx) {
...
@@ -25,9 +25,8 @@ int count_sched(struct pt_regs *ctx) {
class
TestTracingEvent
(
TestCase
):
class
TestTracingEvent
(
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
b
=
BPF
(
text
=
text
,
debug
=
0
)
b
=
BPF
(
text
=
text
,
debug
=
0
)
fn
=
b
.
load_func
(
"count_sched"
,
BPF
.
KPROBE
)
self
.
stats
=
b
.
get_table
(
"stats"
)
self
.
stats
=
b
.
get_table
(
"stats"
)
BPF
.
attach_kprobe
(
fn
,
"schedule+50"
,
0
,
-
1
)
b
.
attach_kprobe
(
event
=
"schedule+50"
,
fn_name
=
"count_sched"
,
pid
=
0
,
cpu
=
-
1
)
def
test_sched1
(
self
):
def
test_sched1
(
self
):
for
i
in
range
(
0
,
100
):
for
i
in
range
(
0
,
100
):
...
...
tests/cc/test_trace3.py
View file @
ef67bb2a
...
@@ -17,11 +17,11 @@ if len(sys.argv) > 1:
...
@@ -17,11 +17,11 @@ if len(sys.argv) > 1:
class
TestBlkRequest
(
TestCase
):
class
TestBlkRequest
(
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
b
=
BPF
(
arg1
,
arg2
,
debug
=
0
)
b
=
BPF
(
arg1
,
arg2
,
debug
=
0
)
fn1
=
b
.
load_func
(
"probe_blk_start_request"
,
BPF
.
KPROBE
)
fn2
=
b
.
load_func
(
"probe_blk_update_request"
,
BPF
.
KPROBE
)
self
.
latency
=
b
.
get_table
(
"latency"
,
c_uint
,
c_ulong
)
self
.
latency
=
b
.
get_table
(
"latency"
,
c_uint
,
c_ulong
)
BPF
.
attach_kprobe
(
fn1
,
"blk_start_request"
,
-
1
,
0
)
b
.
attach_kprobe
(
event
=
"blk_start_request"
,
BPF
.
attach_kprobe
(
fn2
,
"blk_update_request"
,
-
1
,
0
)
fn_name
=
"probe_blk_start_request"
,
pid
=-
1
,
cpu
=
0
)
b
.
attach_kprobe
(
event
=
"blk_update_request"
,
fn_name
=
"probe_blk_update_request"
,
pid
=-
1
,
cpu
=
0
)
def
test_blk1
(
self
):
def
test_blk1
(
self
):
import
subprocess
import
subprocess
...
...
tools/pidpersec
View file @
ef67bb2a
...
@@ -18,7 +18,7 @@ from time import sleep, strftime
...
@@ -18,7 +18,7 @@ from time import sleep, strftime
# load BPF program
# load BPF program
b
=
BPF
(
src_file
=
"pidpersec.c"
)
b
=
BPF
(
src_file
=
"pidpersec.c"
)
BPF
.
attach_kprobe
(
b
.
load_func
(
"do_count"
,
BPF
.
KPROBE
),
"sched_fork
"
)
b
.
attach_kprobe
(
event
=
"sched_fork"
,
fn_name
=
"do_count
"
)
stats
=
b
.
get_table
(
"stats"
)
stats
=
b
.
get_table
(
"stats"
)
# stat indexes
# stat indexes
...
...
tools/syncsnoop
View file @
ef67bb2a
...
@@ -22,7 +22,7 @@ int do_sync(void *ctx) {
...
@@ -22,7 +22,7 @@ int do_sync(void *ctx) {
return 0;
return 0;
};
};
"""
)
"""
)
BPF
.
attach_kprobe
(
b
.
load_func
(
"do_sync"
,
BPF
.
KPROBE
),
"sys_sync"
)
b
.
attach_kprobe
(
event
=
"sys_sync"
)
# header
# header
print
(
"%-18s %s"
%
(
"TIME(s)"
,
"CALL"
))
print
(
"%-18s %s"
%
(
"TIME(s)"
,
"CALL"
))
...
...
tools/vfscount
View file @
ef67bb2a
...
@@ -52,12 +52,11 @@ load_kallsyms()
...
@@ -52,12 +52,11 @@ load_kallsyms()
# load BPF program
# load BPF program
b
=
BPF
(
src_file
=
"vfscount.c"
)
b
=
BPF
(
src_file
=
"vfscount.c"
)
fn
=
b
.
load_func
(
"do_count"
,
BPF
.
KPROBE
)
b
.
attach_kprobe
(
event
=
"vfs_read"
,
fn_name
=
"do_count"
)
BPF
.
attach_kprobe
(
fn
,
"vfs_read"
)
b
.
attach_kprobe
(
event
=
"vfs_write"
,
fn_name
=
"do_count"
)
BPF
.
attach_kprobe
(
fn
,
"vfs_write"
)
b
.
attach_kprobe
(
event
=
"vfs_fsync"
,
fn_name
=
"do_count"
)
BPF
.
attach_kprobe
(
fn
,
"vfs_fsync"
)
b
.
attach_kprobe
(
event
=
"vfs_open"
,
fn_name
=
"do_count"
)
BPF
.
attach_kprobe
(
fn
,
"vfs_open"
)
b
.
attach_kprobe
(
event
=
"vfs_create"
,
fn_name
=
"do_count"
)
BPF
.
attach_kprobe
(
fn
,
"vfs_create"
)
counts
=
b
.
get_table
(
"counts"
)
counts
=
b
.
get_table
(
"counts"
)
# header
# header
...
...
tools/vfsstat
View file @
ef67bb2a
...
@@ -37,11 +37,11 @@ if len(argv) > 1:
...
@@ -37,11 +37,11 @@ if len(argv) > 1:
# load BPF program
# load BPF program
b
=
BPF
(
src_file
=
"vfsstat.c"
)
b
=
BPF
(
src_file
=
"vfsstat.c"
)
BPF
.
attach_kprobe
(
b
.
load_func
(
"do_read"
,
BPF
.
KPROBE
),
"vfs
_read"
)
b
.
attach_kprobe
(
event
=
"vfs_read"
,
fn_name
=
"do
_read"
)
BPF
.
attach_kprobe
(
b
.
load_func
(
"do_write"
,
BPF
.
KPROBE
),
"vfs
_write"
)
b
.
attach_kprobe
(
event
=
"vfs_write"
,
fn_name
=
"do
_write"
)
BPF
.
attach_kprobe
(
b
.
load_func
(
"do_fsync"
,
BPF
.
KPROBE
),
"vfs
_fsync"
)
b
.
attach_kprobe
(
event
=
"vfs_fsync"
,
fn_name
=
"do
_fsync"
)
BPF
.
attach_kprobe
(
b
.
load_func
(
"do_open"
,
BPF
.
KPROBE
),
"vfs
_open"
)
b
.
attach_kprobe
(
event
=
"vfs_open"
,
fn_name
=
"do
_open"
)
BPF
.
attach_kprobe
(
b
.
load_func
(
"do_create"
,
BPF
.
KPROBE
),
"vfs
_create"
)
b
.
attach_kprobe
(
event
=
"vfs_create"
,
fn_name
=
"do
_create"
)
stats
=
b
.
get_table
(
"stats"
)
stats
=
b
.
get_table
(
"stats"
)
# stat column labels and indexes
# stat column labels and indexes
...
...
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