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
b68e67b4
Commit
b68e67b4
authored
Dec 15, 2017
by
Teng Qin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean libbpf interface arguments for tracing events
parent
bebb9c8c
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
57 additions
and
57 deletions
+57
-57
src/cc/api/BPF.cc
src/cc/api/BPF.cc
+4
-4
src/cc/libbpf.c
src/cc/libbpf.c
+23
-16
src/cc/libbpf.h
src/cc/libbpf.h
+8
-9
src/lua/bcc/bpf.lua
src/lua/bcc/bpf.lua
+2
-6
src/lua/bcc/libbcc.lua
src/lua/bcc/libbcc.lua
+5
-7
src/python/bcc/__init__.py
src/python/bcc/__init__.py
+10
-10
src/python/bcc/libbcc.py
src/python/bcc/libbcc.py
+5
-5
No files found.
src/cc/api/BPF.cc
View file @
b68e67b4
...
...
@@ -172,7 +172,7 @@ StatusTuple BPF::attach_kprobe(const std::string& kernel_func,
void
*
res
=
bpf_attach_kprobe
(
probe_fd
,
attach_type
,
probe_event
.
c_str
(),
kernel_func
.
c_str
(),
pid
,
cpu
,
group_fd
,
cb
,
cb_cookie
);
cb
,
cb_cookie
);
if
(
!
res
)
{
TRY2
(
unload_func
(
probe_func
));
...
...
@@ -208,7 +208,7 @@ StatusTuple BPF::attach_uprobe(const std::string& binary_path,
void
*
res
=
bpf_attach_uprobe
(
probe_fd
,
attach_type
,
probe_event
.
c_str
(),
binary_path
.
c_str
(),
offset
,
pid
,
c
pu
,
group_fd
,
c
b
,
cb_cookie
);
offset
,
pid
,
cb
,
cb_cookie
);
if
(
!
res
)
{
TRY2
(
unload_func
(
probe_func
));
...
...
@@ -275,8 +275,8 @@ StatusTuple BPF::attach_tracepoint(const std::string& tracepoint,
TRY2
(
load_func
(
probe_func
,
BPF_PROG_TYPE_TRACEPOINT
,
probe_fd
));
void
*
res
=
bpf_attach_tracepoint
(
probe_fd
,
tp_category
.
c_str
(),
tp_name
.
c_str
(),
pid
,
c
pu
,
group_fd
,
cb
,
c
b_cookie
);
bpf_attach_tracepoint
(
probe_fd
,
tp_category
.
c_str
(),
tp_name
.
c_str
(),
cb
,
cb_cookie
);
if
(
!
res
)
{
TRY2
(
unload_func
(
probe_func
));
...
...
src/cc/libbpf.c
View file @
b68e67b4
...
...
@@ -529,8 +529,8 @@ int bpf_attach_socket(int sock, int prog) {
}
static
int
bpf_attach_tracing_event
(
int
progfd
,
const
char
*
event_path
,
struct
perf_reader
*
reader
,
int
pid
,
int
cpu
,
int
group_f
d
)
{
int
efd
,
pfd
;
struct
perf_reader
*
reader
,
int
pi
d
)
{
int
efd
,
pfd
,
cpu
=
0
;
ssize_t
bytes
;
char
buf
[
256
];
struct
perf_event_attr
attr
=
{};
...
...
@@ -555,7 +555,15 @@ static int bpf_attach_tracing_event(int progfd, const char *event_path,
attr
.
sample_type
=
PERF_SAMPLE_RAW
|
PERF_SAMPLE_CALLCHAIN
;
attr
.
sample_period
=
1
;
attr
.
wakeup_events
=
1
;
pfd
=
syscall
(
__NR_perf_event_open
,
&
attr
,
pid
,
cpu
,
group_fd
,
PERF_FLAG_FD_CLOEXEC
);
// PID filter is only possible for uprobe events.
if
(
pid
<
0
)
pid
=
-
1
;
// perf_event_open API doesn't allow both pid and cpu to be -1.
// So only set it to -1 when PID is not -1.
// Tracing events do not do CPU filtering in any cases.
if
(
pid
!=
-
1
)
cpu
=
-
1
;
pfd
=
syscall
(
__NR_perf_event_open
,
&
attr
,
pid
,
cpu
,
-
1
/* group_fd */
,
PERF_FLAG_FD_CLOEXEC
);
if
(
pfd
<
0
)
{
fprintf
(
stderr
,
"perf_event_open(%s/id): %s
\n
"
,
event_path
,
strerror
(
errno
));
return
-
1
;
...
...
@@ -577,9 +585,8 @@ static int bpf_attach_tracing_event(int progfd, const char *event_path,
return
0
;
}
void
*
bpf_attach_kprobe
(
int
progfd
,
enum
bpf_probe_attach_type
attach_type
,
const
char
*
ev_name
,
const
char
*
fn_name
,
pid_t
pid
,
int
cpu
,
int
group_fd
,
void
*
bpf_attach_kprobe
(
int
progfd
,
enum
bpf_probe_attach_type
attach_type
,
const
char
*
ev_name
,
const
char
*
fn_name
,
perf_reader_cb
cb
,
void
*
cb_cookie
)
{
int
kfd
;
...
...
@@ -611,7 +618,7 @@ void * bpf_attach_kprobe(int progfd, enum bpf_probe_attach_type attach_type, con
close
(
kfd
);
snprintf
(
buf
,
sizeof
(
buf
),
"/sys/kernel/debug/tracing/events/%ss/%s"
,
event_type
,
event_alias
);
if
(
bpf_attach_tracing_event
(
progfd
,
buf
,
reader
,
pid
,
cpu
,
group_fd
)
<
0
)
if
(
bpf_attach_tracing_event
(
progfd
,
buf
,
reader
,
-
1
/* PID */
)
<
0
)
goto
error
;
return
reader
;
...
...
@@ -683,10 +690,10 @@ static void exit_mount_ns(int fd) {
perror
(
"setns"
);
}
void
*
bpf_attach_uprobe
(
int
progfd
,
enum
bpf_probe_attach_type
attach_type
,
const
char
*
ev_nam
e
,
const
char
*
binary_path
,
uint64_t
offset
,
pid_t
pid
,
int
cpu
,
int
group_fd
,
perf_reader_cb
cb
,
void
*
cb_cookie
)
void
*
bpf_attach_uprobe
(
int
progfd
,
enum
bpf_probe_attach_type
attach_typ
e
,
const
char
*
ev_name
,
const
char
*
binary_path
,
uint64_t
offset
,
pid_t
pid
,
perf_reader_cb
cb
,
void
*
cb_cookie
)
{
char
buf
[
PATH_MAX
];
char
event_alias
[
PATH_MAX
];
...
...
@@ -728,7 +735,7 @@ void * bpf_attach_uprobe(int progfd, enum bpf_probe_attach_type attach_type, con
ns_fd
=
-
1
;
snprintf
(
buf
,
sizeof
(
buf
),
"/sys/kernel/debug/tracing/events/%ss/%s"
,
event_type
,
event_alias
);
if
(
bpf_attach_tracing_event
(
progfd
,
buf
,
reader
,
pid
,
cpu
,
group_fd
)
<
0
)
if
(
bpf_attach_tracing_event
(
progfd
,
buf
,
reader
,
pid
)
<
0
)
goto
error
;
return
reader
;
...
...
@@ -782,9 +789,9 @@ int bpf_detach_uprobe(const char *ev_name)
}
void
*
bpf_attach_tracepoint
(
int
progfd
,
const
char
*
tp_category
,
const
char
*
tp_name
,
int
pid
,
int
cpu
,
int
group_fd
,
perf_reader_cb
cb
,
void
*
cb_cookie
)
{
void
*
bpf_attach_tracepoint
(
int
progfd
,
const
char
*
tp_category
,
const
char
*
tp_name
,
perf_reader_cb
cb
,
void
*
cb_cookie
)
{
char
buf
[
256
];
struct
perf_reader
*
reader
=
NULL
;
...
...
@@ -794,7 +801,7 @@ void * bpf_attach_tracepoint(int progfd, const char *tp_category,
snprintf
(
buf
,
sizeof
(
buf
),
"/sys/kernel/debug/tracing/events/%s/%s"
,
tp_category
,
tp_name
);
if
(
bpf_attach_tracing_event
(
progfd
,
buf
,
reader
,
pid
,
cpu
,
group_fd
)
<
0
)
if
(
bpf_attach_tracing_event
(
progfd
,
buf
,
reader
,
-
1
/* PID */
)
<
0
)
goto
error
;
return
reader
;
...
...
src/cc/libbpf.h
View file @
b68e67b4
...
...
@@ -70,23 +70,22 @@ typedef void (*perf_reader_cb)(void *cb_cookie, int pid, uint64_t callchain_num,
typedef
void
(
*
perf_reader_raw_cb
)(
void
*
cb_cookie
,
void
*
raw
,
int
raw_size
);
typedef
void
(
*
perf_reader_lost_cb
)(
uint64_t
lost
);
void
*
bpf_attach_kprobe
(
int
progfd
,
enum
bpf_probe_attach_type
attach_type
,
void
*
bpf_attach_kprobe
(
int
progfd
,
enum
bpf_probe_attach_type
attach_type
,
const
char
*
ev_name
,
const
char
*
fn_name
,
pid_t
pid
,
int
cpu
,
int
group_fd
,
perf_reader_cb
cb
,
void
*
cb_cookie
);
int
bpf_detach_kprobe
(
const
char
*
ev_name
);
void
*
bpf_attach_uprobe
(
int
progfd
,
enum
bpf_probe_attach_type
attach_type
,
const
char
*
ev_name
,
const
char
*
binary_path
,
uint64_t
offset
,
pid_t
pid
,
int
cpu
,
int
group_fd
,
perf_reader_cb
cb
,
void
*
cb_cookie
);
void
*
bpf_attach_uprobe
(
int
progfd
,
enum
bpf_probe_attach_type
attach_type
,
const
char
*
ev_name
,
const
char
*
binary_path
,
uint64_t
offset
,
pid_t
pid
,
perf_reader_cb
cb
,
void
*
cb_cookie
);
int
bpf_detach_uprobe
(
const
char
*
ev_name
);
void
*
bpf_attach_tracepoint
(
int
progfd
,
const
char
*
tp_category
,
const
char
*
tp_name
,
int
pid
,
int
cpu
,
int
group_fd
,
perf_reader_cb
cb
,
void
*
cb_cookie
);
void
*
bpf_attach_tracepoint
(
int
progfd
,
const
char
*
tp_category
,
const
char
*
tp_name
,
perf_reader_cb
cb
,
void
*
cb_cookie
);
int
bpf_detach_tracepoint
(
const
char
*
tp_category
,
const
char
*
tp_name
);
void
*
bpf_open_perf_buffer
(
perf_reader_raw_cb
raw_cb
,
...
...
src/lua/bcc/bpf.lua
View file @
b68e67b4
...
...
@@ -189,9 +189,7 @@ function Bpf:attach_uprobe(args)
local
retprobe
=
args
.
retprobe
and
1
or
0
local
res
=
libbcc
.
bpf_attach_uprobe
(
fn
.
fd
,
retprobe
,
ev_name
,
path
,
addr
,
args
.
pid
or
-
1
,
args
.
cpu
or
0
,
args
.
group_fd
or
-
1
,
nil
,
nil
)
-- TODO; reader callback
args
.
pid
or
-
1
,
nil
,
nil
)
-- TODO; reader callback
assert
(
res
~=
nil
,
"failed to attach BPF to uprobe"
)
self
:
probe_store
(
"uprobe"
,
ev_name
,
res
)
...
...
@@ -209,9 +207,7 @@ function Bpf:attach_kprobe(args)
local
retprobe
=
args
.
retprobe
and
1
or
0
local
res
=
libbcc
.
bpf_attach_kprobe
(
fn
.
fd
,
retprobe
,
ev_name
,
event
,
args
.
pid
or
-
1
,
args
.
cpu
or
0
,
args
.
group_fd
or
-
1
,
nil
,
nil
)
-- TODO; reader callback
nil
,
nil
)
-- TODO; reader callback
assert
(
res
~=
nil
,
"failed to attach BPF to kprobe"
)
self
:
probe_store
(
"kprobe"
,
ev_name
,
res
)
...
...
src/lua/bcc/libbcc.lua
View file @
b68e67b4
...
...
@@ -43,16 +43,14 @@ typedef void (*perf_reader_cb)(void *cb_cookie, int pid, uint64_t callchain_num,
typedef void (*perf_reader_raw_cb)(void *cb_cookie, void *raw, int raw_size);
typedef void (*perf_reader_lost_cb)(uint64_t lost);
void * bpf_attach_kprobe(int progfd, int attach_type, const char *ev_name,
const char *fn_name,
int pid, int cpu, int group_fd,
perf_reader_cb cb, void *cb_cookie);
void *bpf_attach_kprobe(int progfd, int attach_type, const char *ev_name,
const char *fn_name, perf_reader_cb cb,
void *cb_cookie);
int bpf_detach_kprobe(const char *ev_name);
void * bpf_attach_uprobe(int progfd, int attach_type, const char *ev_name,
const char *binary_path, uint64_t offset,
int pid, int cpu, int group_fd,
void *bpf_attach_uprobe(int progfd, int attach_type, const char *ev_name,
const char *binary_path, uint64_t offset, int pid,
perf_reader_cb cb, void *cb_cookie);
int bpf_detach_uprobe(const char *ev_name);
...
...
src/python/bcc/__init__.py
View file @
b68e67b4
...
...
@@ -519,8 +519,8 @@ class BPF(object):
fn
=
self
.
load_func
(
fn_name
,
BPF
.
KPROBE
)
ev_name
=
"p_"
+
event
.
replace
(
"+"
,
"_"
).
replace
(
"."
,
"_"
)
res
=
lib
.
bpf_attach_kprobe
(
fn
.
fd
,
0
,
ev_name
.
encode
(
"ascii"
),
event
.
encode
(
"ascii"
),
pid
,
cpu
,
group_fd
,
self
.
_reader_cb_impl
,
ct
.
cast
(
id
(
self
),
ct
.
py_object
))
event
.
encode
(
"ascii"
),
self
.
_reader_cb_impl
,
ct
.
cast
(
id
(
self
),
ct
.
py_object
))
res
=
ct
.
cast
(
res
,
ct
.
c_void_p
)
if
not
res
:
raise
Exception
(
"Failed to attach BPF to kprobe"
)
...
...
@@ -556,8 +556,8 @@ class BPF(object):
fn
=
self
.
load_func
(
fn_name
,
BPF
.
KPROBE
)
ev_name
=
"r_"
+
event
.
replace
(
"+"
,
"_"
).
replace
(
"."
,
"_"
)
res
=
lib
.
bpf_attach_kprobe
(
fn
.
fd
,
1
,
ev_name
.
encode
(
"ascii"
),
event
.
encode
(
"ascii"
),
pid
,
cpu
,
group_fd
,
self
.
_reader_cb_impl
,
ct
.
cast
(
id
(
self
),
ct
.
py_object
))
event
.
encode
(
"ascii"
),
self
.
_reader_cb_impl
,
ct
.
cast
(
id
(
self
),
ct
.
py_object
))
res
=
ct
.
cast
(
res
,
ct
.
c_void_p
)
if
not
res
:
raise
Exception
(
"Failed to attach BPF to kprobe"
)
...
...
@@ -680,8 +680,8 @@ class BPF(object):
fn
=
self
.
load_func
(
fn_name
,
BPF
.
TRACEPOINT
)
(
tp_category
,
tp_name
)
=
tp
.
split
(
':'
)
res
=
lib
.
bpf_attach_tracepoint
(
fn
.
fd
,
tp_category
.
encode
(
"ascii"
),
tp_name
.
encode
(
"ascii"
),
pid
,
cpu
,
group_fd
,
self
.
_reader_cb_impl
,
ct
.
cast
(
id
(
self
),
ct
.
py_object
))
tp_name
.
encode
(
"ascii"
),
self
.
_reader_cb_impl
,
ct
.
cast
(
id
(
self
),
ct
.
py_object
))
res
=
ct
.
cast
(
res
,
ct
.
c_void_p
)
if
not
res
:
raise
Exception
(
"Failed to attach BPF to tracepoint"
)
...
...
@@ -833,8 +833,8 @@ class BPF(object):
fn
=
self
.
load_func
(
fn_name
,
BPF
.
KPROBE
)
ev_name
=
self
.
_get_uprobe_evname
(
"p"
,
path
,
addr
,
pid
)
res
=
lib
.
bpf_attach_uprobe
(
fn
.
fd
,
0
,
ev_name
.
encode
(
"ascii"
),
path
.
encode
(
"ascii"
),
addr
,
pid
,
cpu
,
group_fd
,
self
.
_reader_cb_impl
,
ct
.
cast
(
id
(
self
),
ct
.
py_object
))
path
.
encode
(
"ascii"
),
addr
,
pid
,
self
.
_reader_cb_impl
,
ct
.
cast
(
id
(
self
),
ct
.
py_object
))
res
=
ct
.
cast
(
res
,
ct
.
c_void_p
)
if
not
res
:
raise
Exception
(
"Failed to attach BPF to uprobe"
)
...
...
@@ -883,8 +883,8 @@ class BPF(object):
fn
=
self
.
load_func
(
fn_name
,
BPF
.
KPROBE
)
ev_name
=
self
.
_get_uprobe_evname
(
"r"
,
path
,
addr
,
pid
)
res
=
lib
.
bpf_attach_uprobe
(
fn
.
fd
,
1
,
ev_name
.
encode
(
"ascii"
),
path
.
encode
(
"ascii"
),
addr
,
pid
,
cpu
,
group_fd
,
self
.
_reader_cb_impl
,
ct
.
cast
(
id
(
self
),
ct
.
py_object
))
path
.
encode
(
"ascii"
),
addr
,
pid
,
self
.
_reader_cb_impl
,
ct
.
cast
(
id
(
self
),
ct
.
py_object
))
res
=
ct
.
cast
(
res
,
ct
.
c_void_p
)
if
not
res
:
raise
Exception
(
"Failed to attach BPF to uprobe"
)
...
...
src/python/bcc/libbcc.py
View file @
b68e67b4
...
...
@@ -90,18 +90,18 @@ _CB_TYPE = ct.CFUNCTYPE(None, ct.py_object, ct.c_int,
ct
.
c_ulonglong
,
ct
.
POINTER
(
ct
.
c_ulonglong
))
_RAW_CB_TYPE
=
ct
.
CFUNCTYPE
(
None
,
ct
.
py_object
,
ct
.
c_void_p
,
ct
.
c_int
)
_LOST_CB_TYPE
=
ct
.
CFUNCTYPE
(
None
,
ct
.
c_ulonglong
)
lib
.
bpf_attach_kprobe
.
argtypes
=
[
ct
.
c_int
,
ct
.
c_int
,
ct
.
c_char_p
,
ct
.
c_char_p
,
ct
.
c_int
,
ct
.
c_int
,
ct
.
c_int
,
_CB_TYPE
,
ct
.
py_object
]
lib
.
bpf_attach_kprobe
.
argtypes
=
[
ct
.
c_int
,
ct
.
c_int
,
ct
.
c_char_p
,
ct
.
c_char_p
,
_CB_TYPE
,
ct
.
py_object
]
lib
.
bpf_detach_kprobe
.
restype
=
ct
.
c_int
lib
.
bpf_detach_kprobe
.
argtypes
=
[
ct
.
c_char_p
]
lib
.
bpf_attach_uprobe
.
restype
=
ct
.
c_void_p
lib
.
bpf_attach_uprobe
.
argtypes
=
[
ct
.
c_int
,
ct
.
c_int
,
ct
.
c_char_p
,
ct
.
c_char_p
,
ct
.
c_ulonglong
,
ct
.
c_int
,
ct
.
c_int
,
ct
.
c_int
,
_CB_TYPE
,
ct
.
py_object
]
ct
.
c_ulonglong
,
ct
.
c_int
,
_CB_TYPE
,
ct
.
py_object
]
lib
.
bpf_detach_uprobe
.
restype
=
ct
.
c_int
lib
.
bpf_detach_uprobe
.
argtypes
=
[
ct
.
c_char_p
]
lib
.
bpf_attach_tracepoint
.
restype
=
ct
.
c_void_p
lib
.
bpf_attach_tracepoint
.
argtypes
=
[
ct
.
c_int
,
ct
.
c_char_p
,
ct
.
c_char_p
,
ct
.
c_int
,
ct
.
c_int
,
ct
.
c_int
,
_CB_TYPE
,
ct
.
py_object
]
lib
.
bpf_attach_tracepoint
.
argtypes
=
[
ct
.
c_int
,
ct
.
c_char_p
,
ct
.
c_char_p
,
_CB_TYPE
,
ct
.
py_object
]
lib
.
bpf_detach_tracepoint
.
restype
=
ct
.
c_int
lib
.
bpf_detach_tracepoint
.
argtypes
=
[
ct
.
c_char_p
,
ct
.
c_char_p
]
lib
.
bpf_open_perf_buffer
.
restype
=
ct
.
c_void_p
...
...
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