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
7f22495b
Commit
7f22495b
authored
Apr 20, 2018
by
yonghong-song
Committed by
GitHub
Apr 20, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1692 from palmtenor/stack_flag
Refactor offcputime stack id error handling
parents
9d1bdaa5
ea72805b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
23 deletions
+42
-23
tools/offcputime.py
tools/offcputime.py
+42
-23
No files found.
tools/offcputime.py
View file @
7f22495b
...
...
@@ -35,6 +35,11 @@ def positive_nonzero_int(val):
raise
argparse
.
ArgumentTypeError
(
"must be nonzero"
)
return
ival
def
stack_id_err
(
stack_id
):
# -EFAULT in get_stackid normally means the stack-trace is not availible,
# Such as getting kernel stack trace in userspace code
return
(
stack_id
<
0
)
and
(
stack_id
!=
-
errno
.
EFAULT
)
# arguments
examples
=
"""examples:
./offcputime # trace off-CPU stack time until Ctrl-C
...
...
@@ -199,9 +204,8 @@ bpf_text = bpf_text.replace('MINBLOCK_US_VALUE', str(args.min_block_time))
bpf_text
=
bpf_text
.
replace
(
'MAXBLOCK_US_VALUE'
,
str
(
args
.
max_block_time
))
# handle stack args
kernel_stack_get
=
"stack_traces.get_stackid(ctx, BPF_F_REUSE_STACKID)"
user_stack_get
=
\
"stack_traces.get_stackid(ctx, BPF_F_REUSE_STACKID | BPF_F_USER_STACK)"
kernel_stack_get
=
"stack_traces.get_stackid(ctx, 0)"
user_stack_get
=
"stack_traces.get_stackid(ctx, BPF_F_USER_STACK)"
stack_context
=
""
if
args
.
user_stacks_only
:
stack_context
=
"user"
...
...
@@ -260,16 +264,13 @@ has_enomem = False
counts
=
b
.
get_table
(
"counts"
)
stack_traces
=
b
.
get_table
(
"stack_traces"
)
for
k
,
v
in
sorted
(
counts
.
items
(),
key
=
lambda
counts
:
counts
[
1
].
value
):
# handle get_stackid erorrs
if
(
not
args
.
user_stacks_only
and
k
.
kernel_stack_id
<
0
)
or
\
(
not
args
.
kernel_stacks_only
and
k
.
user_stack_id
<
0
and
k
.
user_stack_id
!=
-
errno
.
EFAULT
):
# handle get_stackid errors
if
not
args
.
user_stacks_only
and
stack_id_err
(
k
.
kernel_stack_id
):
missing_stacks
+=
1
has_enomem
=
has_enomem
or
k
.
kernel_stack_id
==
-
errno
.
ENOMEM
if
not
args
.
kernel_stacks_only
and
stack_id_err
(
k
.
user_stack_id
):
missing_stacks
+=
1
# check for an ENOMEM error
if
k
.
kernel_stack_id
==
-
errno
.
ENOMEM
or
\
k
.
user_stack_id
==
-
errno
.
ENOMEM
:
has_enomem
=
True
continue
has_enomem
=
has_enomem
or
k
.
user_stack_id
==
-
errno
.
ENOMEM
# user stacks will be symbolized by tgid, not pid, to avoid the overhead
# of one symbol resolver per thread
...
...
@@ -282,25 +283,43 @@ for k, v in sorted(counts.items(), key=lambda counts: counts[1].value):
# print folded stack output
user_stack
=
list
(
user_stack
)
kernel_stack
=
list
(
kernel_stack
)
line
=
[
k
.
name
.
decode
()]
+
\
[
b
.
sym
(
addr
,
k
.
tgid
)
for
addr
in
reversed
(
user_stack
)]
+
\
(
need_delimiter
and
[
"-"
]
or
[])
+
\
[
b
.
ksym
(
addr
)
for
addr
in
reversed
(
kernel_stack
)]
line
=
[
k
.
name
.
decode
()]
# if we failed to get the stack is, such as due to no space (-ENOMEM) or
# hash collision (-EEXIST), we still print a placeholder for consistency
if
not
args
.
kernel_stacks_only
:
if
stack_id_err
(
k
.
user_stack_id
):
line
.
append
(
"[Missed User Stack]"
)
else
:
line
.
extend
([
b
.
sym
(
addr
,
k
.
tgid
)
for
addr
in
reversed
(
user_stack
)])
if
not
args
.
user_stacks_only
:
line
.
extend
([
"-"
]
if
(
need_delimiter
and
k
.
kernel_stack_id
>=
0
)
else
[])
if
stack_id_err
(
k
.
kernel_stack_id
):
line
.
append
(
"[Missed Kernel Stack]"
)
else
:
line
.
extend
([
b
.
ksym
(
addr
)
for
addr
in
reversed
(
kernel_stack
)])
print
(
"%s %d"
%
(
";"
.
join
(
line
),
v
.
value
))
else
:
# print default multi-line stack output
for
addr
in
kernel_stack
:
print
(
" %s"
%
b
.
ksym
(
addr
))
if
need_delimiter
:
print
(
" --"
)
for
addr
in
user_stack
:
print
(
" %s"
%
b
.
sym
(
addr
,
k
.
tgid
))
if
not
args
.
user_stacks_only
:
if
stack_id_err
(
k
.
kernel_stack_id
):
print
(
" [Missed Kernel Stack]"
)
else
:
for
addr
in
kernel_stack
:
print
(
" %s"
%
b
.
ksym
(
addr
))
if
not
args
.
kernel_stacks_only
:
if
need_delimiter
and
k
.
user_stack_id
>=
0
:
print
(
" --"
)
if
stack_id_err
(
k
.
user_stack_id
):
print
(
" [Missed User Stack]"
)
else
:
for
addr
in
user_stack
:
print
(
" %s"
%
b
.
sym
(
addr
,
k
.
tgid
))
print
(
" %-16s %s (%d)"
%
(
"-"
,
k
.
name
.
decode
(),
k
.
pid
))
print
(
" %d
\
n
"
%
v
.
value
)
if
missing_stacks
>
0
:
enomem_str
=
""
if
not
has_enomem
else
\
" Consider increasing --stack-storage-size."
print
(
"WARNING: %d stack traces could not be displayed.%s"
%
print
(
"WARNING: %d stack traces
lost and
could not be displayed.%s"
%
(
missing_stacks
,
enomem_str
),
file
=
stderr
)
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