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
d3b9d6a1
Commit
d3b9d6a1
authored
Dec 15, 2017
by
Teng Qin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean C++ interface arguments for tracing events
parent
fd244056
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
67 deletions
+49
-67
src/cc/api/BPF.cc
src/cc/api/BPF.cc
+24
-37
src/cc/api/BPF.h
src/cc/api/BPF.h
+25
-30
No files found.
src/cc/api/BPF.cc
View file @
d3b9d6a1
...
...
@@ -161,7 +161,6 @@ StatusTuple BPF::detach_all() {
StatusTuple
BPF
::
attach_kprobe
(
const
std
::
string
&
kernel_func
,
const
std
::
string
&
probe_func
,
bpf_probe_attach_type
attach_type
,
pid_t
pid
,
int
cpu
,
int
group_fd
,
perf_reader_cb
cb
,
void
*
cb_cookie
)
{
std
::
string
probe_event
=
get_kprobe_event
(
kernel_func
,
attach_type
);
if
(
kprobes_
.
find
(
probe_event
)
!=
kprobes_
.
end
())
...
...
@@ -170,9 +169,8 @@ StatusTuple BPF::attach_kprobe(const std::string& kernel_func,
int
probe_fd
;
TRY2
(
load_func
(
probe_func
,
BPF_PROG_TYPE_KPROBE
,
probe_fd
));
void
*
res
=
bpf_attach_kprobe
(
probe_fd
,
attach_type
,
probe_event
.
c_str
(),
kernel_func
.
c_str
(),
cb
,
cb_cookie
);
void
*
res
=
bpf_attach_kprobe
(
probe_fd
,
attach_type
,
probe_event
.
c_str
(),
kernel_func
.
c_str
(),
cb
,
cb_cookie
);
if
(
!
res
)
{
TRY2
(
unload_func
(
probe_func
));
...
...
@@ -192,8 +190,7 @@ StatusTuple BPF::attach_uprobe(const std::string& binary_path,
const
std
::
string
&
symbol
,
const
std
::
string
&
probe_func
,
uint64_t
symbol_addr
,
bpf_probe_attach_type
attach_type
,
pid_t
pid
,
int
cpu
,
int
group_fd
,
bpf_probe_attach_type
attach_type
,
pid_t
pid
,
perf_reader_cb
cb
,
void
*
cb_cookie
)
{
std
::
string
module
;
uint64_t
offset
;
...
...
@@ -207,8 +204,8 @@ StatusTuple BPF::attach_uprobe(const std::string& binary_path,
TRY2
(
load_func
(
probe_func
,
BPF_PROG_TYPE_KPROBE
,
probe_fd
));
void
*
res
=
bpf_attach_uprobe
(
probe_fd
,
attach_type
,
probe_event
.
c_str
(),
binary_path
.
c_str
(),
offset
,
pid
,
cb
,
cb_cookie
);
bpf_attach_uprobe
(
probe_fd
,
attach_type
,
probe_event
.
c_str
(),
binary_path
.
c_str
(),
offset
,
pid
,
cb
,
cb_cookie
);
if
(
!
res
)
{
TRY2
(
unload_func
(
probe_func
));
...
...
@@ -226,8 +223,7 @@ StatusTuple BPF::attach_uprobe(const std::string& binary_path,
return
StatusTuple
(
0
);
}
StatusTuple
BPF
::
attach_usdt
(
const
USDT
&
usdt
,
pid_t
pid
,
int
cpu
,
int
group_fd
)
{
StatusTuple
BPF
::
attach_usdt
(
const
USDT
&
usdt
,
pid_t
pid
)
{
for
(
const
auto
&
u
:
usdt_
)
if
(
u
==
usdt
)
{
bool
failed
=
false
;
...
...
@@ -259,7 +255,6 @@ StatusTuple BPF::attach_usdt(const USDT& usdt, pid_t pid, int cpu,
StatusTuple
BPF
::
attach_tracepoint
(
const
std
::
string
&
tracepoint
,
const
std
::
string
&
probe_func
,
pid_t
pid
,
int
cpu
,
int
group_fd
,
perf_reader_cb
cb
,
void
*
cb_cookie
)
{
if
(
tracepoints_
.
find
(
tracepoint
)
!=
tracepoints_
.
end
())
return
StatusTuple
(
-
1
,
"Tracepoint %s already attached"
,
...
...
@@ -274,9 +269,8 @@ StatusTuple BPF::attach_tracepoint(const std::string& tracepoint,
int
probe_fd
;
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
(),
cb
,
cb_cookie
);
void
*
res
=
bpf_attach_tracepoint
(
probe_fd
,
tp_category
.
c_str
(),
tp_name
.
c_str
(),
cb
,
cb_cookie
);
if
(
!
res
)
{
TRY2
(
unload_func
(
probe_func
));
...
...
@@ -309,7 +303,7 @@ StatusTuple BPF::attach_perf_event(uint32_t ev_type, uint32_t ev_config,
cpus
.
push_back
(
cpu
);
else
cpus
=
get_online_cpus
();
for
(
int
i
:
cpus
)
{
for
(
int
i
:
cpus
)
{
int
fd
=
bpf_attach_perf_event
(
probe_fd
,
ev_type
,
ev_config
,
sample_period
,
sample_freq
,
pid
,
i
,
group_fd
);
if
(
fd
<
0
)
{
...
...
@@ -347,8 +341,7 @@ StatusTuple BPF::detach_kprobe(const std::string& kernel_func,
StatusTuple
BPF
::
detach_uprobe
(
const
std
::
string
&
binary_path
,
const
std
::
string
&
symbol
,
uint64_t
symbol_addr
,
bpf_probe_attach_type
attach_type
,
pid_t
pid
)
{
bpf_probe_attach_type
attach_type
,
pid_t
pid
)
{
std
::
string
module
;
uint64_t
offset
;
TRY2
(
check_binary_symbol
(
binary_path
,
symbol
,
symbol_addr
,
module
,
offset
));
...
...
@@ -399,21 +392,19 @@ StatusTuple BPF::detach_tracepoint(const std::string& tracepoint) {
StatusTuple
BPF
::
detach_perf_event
(
uint32_t
ev_type
,
uint32_t
ev_config
)
{
auto
it
=
perf_events_
.
find
(
std
::
make_pair
(
ev_type
,
ev_config
));
if
(
it
==
perf_events_
.
end
())
return
StatusTuple
(
-
1
,
"Perf Event type %d config %d not attached"
,
ev_
type
,
ev_
config
);
return
StatusTuple
(
-
1
,
"Perf Event type %d config %d not attached"
,
ev_type
,
ev_config
);
TRY2
(
detach_perf_event_all_cpu
(
it
->
second
));
perf_events_
.
erase
(
it
);
return
StatusTuple
(
0
);
}
StatusTuple
BPF
::
open_perf_event
(
const
std
::
string
&
name
,
uint32_t
type
,
StatusTuple
BPF
::
open_perf_event
(
const
std
::
string
&
name
,
uint32_t
type
,
uint64_t
config
)
{
if
(
perf_event_arrays_
.
find
(
name
)
==
perf_event_arrays_
.
end
())
{
TableStorage
::
iterator
it
;
if
(
!
bpf_module_
->
table_storage
().
Find
(
Path
({
bpf_module_
->
id
(),
name
}),
it
))
return
StatusTuple
(
-
1
,
"open_perf_event: unable to find table_storage %s"
,
return
StatusTuple
(
-
1
,
"open_perf_event: unable to find table_storage %s"
,
name
.
c_str
());
perf_event_arrays_
[
name
]
=
new
BPFPerfEventArray
(
it
->
second
);
}
...
...
@@ -434,8 +425,7 @@ StatusTuple BPF::close_perf_event(const std::string& name) {
StatusTuple
BPF
::
open_perf_buffer
(
const
std
::
string
&
name
,
perf_reader_raw_cb
cb
,
perf_reader_lost_cb
lost_cb
,
void
*
cb_cookie
,
perf_reader_lost_cb
lost_cb
,
void
*
cb_cookie
,
int
page_cnt
)
{
if
(
perf_buffers_
.
find
(
name
)
==
perf_buffers_
.
end
())
{
TableStorage
::
iterator
it
;
...
...
@@ -467,8 +457,8 @@ void BPF::poll_perf_buffer(const std::string& name, int timeout) {
it
->
second
->
poll
(
timeout
);
}
StatusTuple
BPF
::
load_func
(
const
std
::
string
&
func_name
,
bpf_prog_type
type
,
int
&
fd
)
{
StatusTuple
BPF
::
load_func
(
const
std
::
string
&
func_name
,
bpf_prog_type
type
,
int
&
fd
)
{
if
(
funcs_
.
find
(
func_name
)
!=
funcs_
.
end
())
{
fd
=
funcs_
[
func_name
];
return
StatusTuple
(
0
);
...
...
@@ -487,17 +477,15 @@ StatusTuple BPF::load_func(const std::string& func_name,
log_level
=
1
;
fd
=
bpf_prog_load
(
type
,
func_name
.
c_str
(),
reinterpret_cast
<
struct
bpf_insn
*>
(
func_start
),
func_size
,
bpf_module_
->
license
(),
bpf_module_
->
kern_version
(),
reinterpret_cast
<
struct
bpf_insn
*>
(
func_start
),
func_size
,
bpf_module_
->
license
(),
bpf_module_
->
kern_version
(),
log_level
,
nullptr
,
0
);
if
(
fd
<
0
)
return
StatusTuple
(
-
1
,
"Failed to load %s: %d"
,
func_name
.
c_str
(),
fd
);
bpf_module_
->
annotate_prog_tag
(
func_name
,
fd
,
reinterpret_cast
<
struct
bpf_insn
*>
(
func_start
),
func_size
);
bpf_module_
->
annotate_prog_tag
(
func_name
,
fd
,
reinterpret_cast
<
struct
bpf_insn
*>
(
func_start
),
func_size
);
funcs_
[
func_name
]
=
fd
;
return
StatusTuple
(
0
);
}
...
...
@@ -518,8 +506,8 @@ StatusTuple BPF::unload_func(const std::string& func_name) {
StatusTuple
BPF
::
check_binary_symbol
(
const
std
::
string
&
binary_path
,
const
std
::
string
&
symbol
,
uint64_t
symbol_addr
,
std
::
string
&
module_res
,
uint64_t
&
offset_res
)
{
std
::
string
&
module_res
,
uint64_t
&
offset_res
)
{
bcc_symbol
output
;
int
res
=
bcc_resolve_symname
(
binary_path
.
c_str
(),
symbol
.
c_str
(),
symbol_addr
,
-
1
,
nullptr
,
&
output
);
...
...
@@ -552,8 +540,7 @@ BPFProgTable BPF::get_prog_table(const std::string& name) {
return
BPFProgTable
({});
}
BPFStackTable
BPF
::
get_stack_table
(
const
std
::
string
&
name
,
bool
use_debug_file
,
BPFStackTable
BPF
::
get_stack_table
(
const
std
::
string
&
name
,
bool
use_debug_file
,
bool
check_debug_file_crc
)
{
TableStorage
::
iterator
it
;
if
(
bpf_module_
->
table_storage
().
Find
(
Path
({
bpf_module_
->
id
(),
name
}),
it
))
...
...
src/cc/api/BPF.h
View file @
d3b9d6a1
...
...
@@ -42,7 +42,7 @@ struct open_probe_t {
class
USDT
;
class
BPF
{
public:
public:
static
const
int
BPF_MAX_STACK_DEPTH
=
127
;
explicit
BPF
(
unsigned
int
flag
=
0
,
TableStorage
*
ts
=
nullptr
)
...
...
@@ -54,33 +54,31 @@ public:
~
BPF
();
StatusTuple
detach_all
();
StatusTuple
attach_kprobe
(
const
std
::
string
&
kernel_func
,
const
std
::
string
&
probe_func
,
bpf_probe_attach_type
=
BPF_PROBE_ENTRY
,
pid_t
pid
=
-
1
,
int
cpu
=
0
,
int
group_fd
=
-
1
,
perf_reader_cb
cb
=
nullptr
,
void
*
cb_cookie
=
nullptr
);
StatusTuple
attach_kprobe
(
const
std
::
string
&
kernel_func
,
const
std
::
string
&
probe_func
,
bpf_probe_attach_type
=
BPF_PROBE_ENTRY
,
perf_reader_cb
cb
=
nullptr
,
void
*
cb_cookie
=
nullptr
);
StatusTuple
detach_kprobe
(
const
std
::
string
&
kernel_func
,
bpf_probe_attach_type
attach_type
=
BPF_PROBE_ENTRY
);
StatusTuple
attach_uprobe
(
const
std
::
string
&
binary_path
,
const
std
::
string
&
symbol
,
const
std
::
string
&
probe_func
,
uint64_t
symbol_addr
=
0
,
bpf_probe_attach_type
attach_type
=
BPF_PROBE_ENTRY
,
pid_t
pid
=
-
1
,
int
cpu
=
0
,
int
group_fd
=
-
1
,
perf_reader_cb
cb
=
nullptr
,
void
*
cb_cookie
=
nullptr
);
StatusTuple
detach_uprobe
(
const
std
::
string
&
binary_path
,
const
std
::
string
&
symbol
,
uint64_t
symbol_addr
=
0
,
bpf_probe_attach_type
attach_type
=
BPF_PROBE_ENTRY
,
pid_t
pid
=
-
1
);
StatusTuple
attach_usdt
(
const
USDT
&
usdt
,
pid_t
pid
=
-
1
,
int
cpu
=
0
,
int
group_fd
=
-
1
);
StatusTuple
attach_uprobe
(
const
std
::
string
&
binary_path
,
const
std
::
string
&
symbol
,
const
std
::
string
&
probe_func
,
uint64_t
symbol_addr
=
0
,
bpf_probe_attach_type
attach_type
=
BPF_PROBE_ENTRY
,
pid_t
pid
=
-
1
,
perf_reader_cb
cb
=
nullptr
,
void
*
cb_cookie
=
nullptr
);
StatusTuple
detach_uprobe
(
const
std
::
string
&
binary_path
,
const
std
::
string
&
symbol
,
uint64_t
symbol_addr
=
0
,
bpf_probe_attach_type
attach_type
=
BPF_PROBE_ENTRY
,
pid_t
pid
=
-
1
);
StatusTuple
attach_usdt
(
const
USDT
&
usdt
,
pid_t
pid
=
-
1
);
StatusTuple
detach_usdt
(
const
USDT
&
usdt
);
StatusTuple
attach_tracepoint
(
const
std
::
string
&
tracepoint
,
const
std
::
string
&
probe_func
,
pid_t
pid
=
-
1
,
int
cpu
=
0
,
int
group_fd
=
-
1
,
perf_reader_cb
cb
=
nullptr
,
void
*
cb_cookie
=
nullptr
);
StatusTuple
detach_tracepoint
(
const
std
::
string
&
tracepoint
);
...
...
@@ -121,14 +119,12 @@ public:
bool
use_debug_file
=
true
,
bool
check_debug_file_crc
=
true
);
StatusTuple
open_perf_event
(
const
std
::
string
&
name
,
uint32_t
type
,
StatusTuple
open_perf_event
(
const
std
::
string
&
name
,
uint32_t
type
,
uint64_t
config
);
StatusTuple
close_perf_event
(
const
std
::
string
&
name
);
StatusTuple
open_perf_buffer
(
const
std
::
string
&
name
,
perf_reader_raw_cb
cb
,
StatusTuple
open_perf_buffer
(
const
std
::
string
&
name
,
perf_reader_raw_cb
cb
,
perf_reader_lost_cb
lost_cb
=
nullptr
,
void
*
cb_cookie
=
nullptr
,
int
page_cnt
=
DEFAULT_PERF_BUFFER_PAGE_CNT
);
...
...
@@ -139,7 +135,7 @@ public:
int
&
fd
);
StatusTuple
unload_func
(
const
std
::
string
&
func_name
);
private:
private:
std
::
string
get_kprobe_event
(
const
std
::
string
&
kernel_func
,
bpf_probe_attach_type
type
);
std
::
string
get_uprobe_event
(
const
std
::
string
&
binary_path
,
uint64_t
offset
,
...
...
@@ -181,9 +177,8 @@ private:
StatusTuple
check_binary_symbol
(
const
std
::
string
&
binary_path
,
const
std
::
string
&
symbol
,
uint64_t
symbol_addr
,
std
::
string
&
module_res
,
uint64_t
&
offset_res
);
uint64_t
symbol_addr
,
std
::
string
&
module_res
,
uint64_t
&
offset_res
);
int
flag_
;
...
...
@@ -202,7 +197,7 @@ private:
};
class
USDT
{
public:
public:
USDT
(
const
std
::
string
&
binary_path
,
const
std
::
string
&
provider
,
const
std
::
string
&
name
,
const
std
::
string
&
probe_func
)
:
initialized_
(
false
),
...
...
@@ -221,7 +216,7 @@ public:
return
provider_
+
":"
+
name_
+
" from "
+
binary_path_
;
}
private:
private:
StatusTuple
init
();
bool
initialized_
;
...
...
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