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
e2a03777
Commit
e2a03777
authored
Apr 06, 2017
by
4ast
Committed by
GitHub
Apr 06, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1099 from palmtenor/stylefix
Miscellaneous style and code layout improvements
parents
0a24ba41
37c9f74a
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
40 additions
and
36 deletions
+40
-36
src/cc/BPF.cc
src/cc/BPF.cc
+24
-16
src/cc/BPF.h
src/cc/BPF.h
+3
-8
src/cc/perf_reader.c
src/cc/perf_reader.c
+2
-1
tools/offwaketime_example.txt
tools/offwaketime_example.txt
+11
-11
No files found.
src/cc/BPF.cc
View file @
e2a03777
...
...
@@ -53,7 +53,8 @@ std::string sanitize_str(std::string str, bool (*validator)(char),
}
StatusTuple
BPF
::
init
(
const
std
::
string
&
bpf_program
,
std
::
vector
<
std
::
string
>
cflags
,
std
::
vector
<
USDT
>
usdt
)
{
const
std
::
vector
<
std
::
string
>&
cflags
,
const
std
::
vector
<
USDT
>&
usdt
)
{
std
::
string
all_bpf_program
;
for
(
auto
u
:
usdt
)
{
...
...
@@ -86,7 +87,7 @@ StatusTuple BPF::detach_all() {
bool
has_error
=
false
;
std
::
string
error_msg
;
for
(
auto
it
:
kprobes_
)
{
for
(
auto
&
it
:
kprobes_
)
{
auto
res
=
detach_kprobe_event
(
it
.
first
,
it
.
second
);
if
(
res
.
code
()
!=
0
)
{
error_msg
+=
"Failed to detach kprobe event "
+
it
.
first
+
": "
;
...
...
@@ -95,7 +96,7 @@ StatusTuple BPF::detach_all() {
}
}
for
(
auto
it
:
uprobes_
)
{
for
(
auto
&
it
:
uprobes_
)
{
auto
res
=
detach_uprobe_event
(
it
.
first
,
it
.
second
);
if
(
res
.
code
()
!=
0
)
{
error_msg
+=
"Failed to detach uprobe event "
+
it
.
first
+
": "
;
...
...
@@ -104,7 +105,7 @@ StatusTuple BPF::detach_all() {
}
}
for
(
auto
it
:
tracepoints_
)
{
for
(
auto
&
it
:
tracepoints_
)
{
auto
res
=
detach_tracepoint_event
(
it
.
first
,
it
.
second
);
if
(
res
.
code
()
!=
0
)
{
error_msg
+=
"Failed to detach Tracepoint "
+
it
.
first
+
": "
;
...
...
@@ -113,7 +114,7 @@ StatusTuple BPF::detach_all() {
}
}
for
(
auto
it
:
perf_buffers_
)
{
for
(
auto
&
it
:
perf_buffers_
)
{
auto
res
=
it
.
second
->
close_all_cpu
();
if
(
res
.
code
()
!=
0
)
{
error_msg
+=
"Failed to close perf buffer "
+
it
.
first
+
": "
;
...
...
@@ -123,7 +124,7 @@ StatusTuple BPF::detach_all() {
delete
it
.
second
;
}
for
(
auto
it
:
perf_events_
)
{
for
(
auto
&
it
:
perf_events_
)
{
auto
res
=
detach_perf_event_all_cpu
(
it
.
second
);
if
(
res
.
code
()
!=
0
)
{
error_msg
+=
res
.
msg
()
+
"
\n
"
;
...
...
@@ -131,7 +132,7 @@ StatusTuple BPF::detach_all() {
}
}
for
(
auto
it
:
funcs_
)
{
for
(
auto
&
it
:
funcs_
)
{
int
res
=
close
(
it
.
second
);
if
(
res
!=
0
)
{
error_msg
+=
"Failed to unload BPF program for "
+
it
.
first
+
": "
;
...
...
@@ -216,7 +217,7 @@ StatusTuple BPF::attach_uprobe(const std::string& binary_path,
StatusTuple
BPF
::
attach_usdt
(
const
USDT
&
usdt
,
pid_t
pid
,
int
cpu
,
int
group_fd
)
{
for
(
auto
&
u
:
usdt_
)
for
(
const
auto
&
u
:
usdt_
)
if
(
u
==
usdt
)
{
bool
failed
=
false
;
std
::
string
err_msg
;
...
...
@@ -301,7 +302,7 @@ StatusTuple BPF::attach_perf_event(uint32_t ev_type, uint32_t ev_config,
int
fd
=
bpf_attach_perf_event
(
probe_fd
,
ev_type
,
ev_config
,
sample_period
,
sample_freq
,
pid
,
i
,
group_fd
);
if
(
fd
<
0
)
{
for
(
auto
it
:
*
fds
)
for
(
const
auto
&
it
:
*
fds
)
close
(
it
.
second
);
delete
fds
;
TRY2
(
unload_func
(
probe_func
));
...
...
@@ -352,7 +353,7 @@ StatusTuple BPF::detach_uprobe(const std::string& binary_path,
}
StatusTuple
BPF
::
detach_usdt
(
const
USDT
&
usdt
)
{
for
(
auto
&
u
:
usdt_
)
for
(
const
auto
&
u
:
usdt_
)
if
(
u
==
usdt
)
{
bool
failed
=
false
;
std
::
string
err_msg
;
...
...
@@ -491,6 +492,13 @@ BPFProgTable BPF::get_prog_table(const std::string& name) {
return
BPFProgTable
({});
}
BPFStackTable
BPF
::
get_stack_table
(
const
std
::
string
&
name
)
{
TableStorage
::
iterator
it
;
if
(
bpf_module_
->
table_storage
().
Find
(
Path
({
bpf_module_
->
id
(),
name
}),
it
))
return
BPFStackTable
(
it
->
second
);
return
BPFStackTable
({});
}
std
::
string
BPF
::
get_uprobe_event
(
const
std
::
string
&
binary_path
,
uint64_t
offset
,
bpf_probe_attach_type
type
)
{
std
::
string
res
=
attach_type_prefix
(
type
)
+
"_"
;
...
...
@@ -538,7 +546,7 @@ StatusTuple BPF::detach_tracepoint_event(const std::string& tracepoint,
StatusTuple
BPF
::
detach_perf_event_all_cpu
(
open_probe_t
&
attr
)
{
bool
has_error
=
false
;
std
::
string
err_msg
;
for
(
auto
it
:
*
attr
.
per_cpu_fd
)
{
for
(
const
auto
&
it
:
*
attr
.
per_cpu_fd
)
{
int
res
=
close
(
it
.
second
);
if
(
res
<
0
)
{
has_error
=
true
;
...
...
@@ -556,11 +564,10 @@ StatusTuple BPF::detach_perf_event_all_cpu(open_probe_t& attr) {
}
StatusTuple
USDT
::
init
()
{
auto
ctx
=
std
::
unique_ptr
<::
USDT
::
Context
>
(
new
::
USDT
::
Context
(
binary_path_
));
if
(
!
ctx
->
loaded
())
::
USDT
::
Context
ctx
(
binary_path_
);
if
(
!
ctx
.
loaded
())
return
StatusTuple
(
-
1
,
"Unable to load USDT "
+
print_name
());
auto
probe
=
ctx
->
get
(
name_
);
auto
probe
=
ctx
.
get
(
name_
);
if
(
probe
==
nullptr
)
return
StatusTuple
(
-
1
,
"Unable to find USDT "
+
print_name
());
...
...
@@ -572,8 +579,9 @@ StatusTuple USDT::init() {
-
1
,
"Unable to generate program text for USDT "
+
print_name
());
program_text_
=
::
USDT
::
USDT_PROGRAM_HEADER
+
stream
.
str
();
addresses_
.
reserve
(
probe
->
num_locations
());
for
(
size_t
i
=
0
;
i
<
probe
->
num_locations
();
i
++
)
addresses_
.
push
_back
(
probe
->
address
(
i
));
addresses_
.
emplace
_back
(
probe
->
address
(
i
));
initialized_
=
true
;
return
StatusTuple
(
0
);
...
...
src/cc/BPF.h
View file @
e2a03777
...
...
@@ -47,8 +47,8 @@ public:
explicit
BPF
(
unsigned
int
flag
=
0
,
TableStorage
*
ts
=
nullptr
)
:
bpf_module_
(
new
BPFModule
(
flag
,
ts
))
{}
StatusTuple
init
(
const
std
::
string
&
bpf_program
,
std
::
vector
<
std
::
string
>
cflags
=
{},
std
::
vector
<
USDT
>
usdt
=
{});
const
std
::
vector
<
std
::
string
>&
cflags
=
{},
const
std
::
vector
<
USDT
>&
usdt
=
{});
~
BPF
();
StatusTuple
detach_all
();
...
...
@@ -108,12 +108,7 @@ public:
BPFProgTable
get_prog_table
(
const
std
::
string
&
name
);
BPFStackTable
get_stack_table
(
const
std
::
string
&
name
)
{
TableStorage
::
iterator
it
;
if
(
bpf_module_
->
table_storage
().
Find
(
Path
({
bpf_module_
->
id
(),
name
}),
it
))
return
BPFStackTable
(
it
->
second
);
return
BPFStackTable
({});
}
BPFStackTable
get_stack_table
(
const
std
::
string
&
name
);
StatusTuple
open_perf_buffer
(
const
std
::
string
&
name
,
perf_reader_raw_cb
cb
,
...
...
src/cc/perf_reader.c
View file @
e2a03777
...
...
@@ -14,6 +14,7 @@
* limitations under the License.
*/
#include <inttypes.h>
#include <poll.h>
#include <stdio.h>
#include <stdint.h>
...
...
@@ -243,7 +244,7 @@ void perf_reader_event_read(struct perf_reader *reader) {
if
(
reader
->
lost_cb
)
{
reader
->
lost_cb
(
lost
);
}
else
{
fprintf
(
stderr
,
"Possibly lost
%llu
samples
\n
"
,
lost
);
fprintf
(
stderr
,
"Possibly lost
"
PRIu64
"
samples
\n
"
,
lost
);
}
}
else
if
(
e
->
type
==
PERF_RECORD_SAMPLE
)
{
if
(
reader
->
type
==
PERF_TYPE_TRACEPOINT
)
...
...
tools/offwaketime_example.txt
View file @
e2a03777
...
...
@@ -4,7 +4,7 @@ Demonstrations of offwaketime, the Linux eBPF/bcc version.
This program shows kernel stack traces and task names that were blocked and
"off-CPU", along with the stack traces and task names for the threads that woke
them, and the total elapsed time from when they blocked to when they were woken
up. This combines the summaries from both the off
cpu
time and wakeuptime tools.
up. This combines the summaries from both the off
wake
time and wakeuptime tools.
The time measurement will be very similar to off-CPU time, however, off-CPU time
may include a little extra time spent waiting on a run queue to be scheduled.
The combined stacks, task names, and total time is summarized in kernel context
...
...
@@ -343,13 +343,13 @@ optional arguments:
examples:
./offwaketime # trace off-CPU + waker stack time until Ctrl-C
./off
cpu
time 5 # trace for 5 seconds only
./off
cpu
time -f 5 # 5 seconds, and output in folded format
./off
cpu
time -m 1000 # trace only events that last more than 1000 usec
./off
cpu
time -M 10000 # trace only events that last less than 10000 usec
./off
cpu
time -p 185 # only trace threads for PID 185
./off
cpu
time -t 188 # only trace thread 188
./off
cpu
time -u # only trace user threads (no kernel)
./off
cpu
time -k # only trace kernel threads (no user)
./off
cpu
time -U # only show user space stacks (no kernel)
./off
cpu
time -K # only show kernel space stacks (no user)
./off
wake
time 5 # trace for 5 seconds only
./off
wake
time -f 5 # 5 seconds, and output in folded format
./off
wake
time -m 1000 # trace only events that last more than 1000 usec
./off
wake
time -M 10000 # trace only events that last less than 10000 usec
./off
wake
time -p 185 # only trace threads for PID 185
./off
wake
time -t 188 # only trace thread 188
./off
wake
time -u # only trace user threads (no kernel)
./off
wake
time -k # only trace kernel threads (no user)
./off
wake
time -U # only show user space stacks (no kernel)
./off
wake
time -K # only show kernel space stacks (no user)
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