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
ce657b11
Commit
ce657b11
authored
Apr 27, 2018
by
Teng Qin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix TCPSendStack example stack id error handling
parent
5cf87883
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
16 deletions
+31
-16
examples/cpp/TCPSendStack.cc
examples/cpp/TCPSendStack.cc
+31
-16
No files found.
examples/cpp/TCPSendStack.cc
View file @
ce657b11
...
...
@@ -27,17 +27,15 @@ struct stack_key_t {
int kernel_stack;
};
BPF_STACK_TRACE(stack_traces, 1
0240
);
BPF_STACK_TRACE(stack_traces, 1
6384
);
BPF_HASH(counts, struct stack_key_t, uint64_t);
int on_tcp_send(struct pt_regs *ctx) {
struct stack_key_t key = {};
key.pid = bpf_get_current_pid_tgid() >> 32;
bpf_get_current_comm(&key.name, sizeof(key.name));
key.kernel_stack = stack_traces.get_stackid(ctx, BPF_F_REUSE_STACKID);
key.user_stack = stack_traces.get_stackid(
ctx, BPF_F_REUSE_STACKID | BPF_F_USER_STACK
);
key.kernel_stack = stack_traces.get_stackid(ctx, 0);
key.user_stack = stack_traces.get_stackid(ctx, BPF_F_USER_STACK);
u64 zero = 0, *val;
val = counts.lookup_or_init(&key, &zero);
...
...
@@ -76,6 +74,12 @@ int main(int argc, char** argv) {
std
::
cout
<<
"Probing for "
<<
probe_time
<<
" seconds"
<<
std
::
endl
;
sleep
(
probe_time
);
auto
detach_res
=
bpf
.
detach_kprobe
(
"tcp_sendmsg"
);
if
(
detach_res
.
code
()
!=
0
)
{
std
::
cerr
<<
detach_res
.
msg
()
<<
std
::
endl
;
return
1
;
}
auto
table
=
bpf
.
get_hash_table
<
stack_key_t
,
uint64_t
>
(
"counts"
).
get_table_offline
();
std
::
sort
(
...
...
@@ -84,31 +88,42 @@ int main(int argc, char** argv) {
std
::
pair
<
stack_key_t
,
uint64_t
>
b
)
{
return
a
.
second
<
b
.
second
;
});
auto
stacks
=
bpf
.
get_stack_table
(
"stack_traces"
);
int
lost_stacks
=
0
;
for
(
auto
it
:
table
)
{
std
::
cout
<<
"PID: "
<<
it
.
first
.
pid
<<
" ("
<<
it
.
first
.
name
<<
") "
<<
"made "
<<
it
.
second
<<
" TCP sends on following stack: "
<<
std
::
endl
;
std
::
cout
<<
" Kernel Stack:"
<<
std
::
endl
;
if
(
it
.
first
.
kernel_stack
>=
0
)
{
std
::
cout
<<
" Kernel Stack:"
<<
std
::
endl
;
auto
syms
=
stacks
.
get_stack_symbol
(
it
.
first
.
kernel_stack
,
-
1
);
for
(
auto
sym
:
syms
)
std
::
cout
<<
" "
<<
sym
<<
std
::
endl
;
}
else
std
::
cout
<<
" "
<<
it
.
first
.
kernel_stack
<<
std
::
endl
;
std
::
cout
<<
" User Stack:"
<<
std
::
endl
;
}
else
{
// -EFAULT normally means the stack is not availiable and not an error
if
(
it
.
first
.
kernel_stack
!=
-
EFAULT
)
{
lost_stacks
++
;
std
::
cout
<<
" [Lost Kernel Stack"
<<
it
.
first
.
kernel_stack
<<
"]"
<<
std
::
endl
;
}
}
if
(
it
.
first
.
user_stack
>=
0
)
{
std
::
cout
<<
" User Stack:"
<<
std
::
endl
;
auto
syms
=
stacks
.
get_stack_symbol
(
it
.
first
.
user_stack
,
it
.
first
.
pid
);
for
(
auto
sym
:
syms
)
std
::
cout
<<
" "
<<
sym
<<
std
::
endl
;
}
else
std
::
cout
<<
" "
<<
it
.
first
.
user_stack
<<
std
::
endl
;
}
else
{
// -EFAULT normally means the stack is not availiable and not an error
if
(
it
.
first
.
user_stack
!=
-
EFAULT
)
{
lost_stacks
++
;
std
::
cout
<<
" [Lost User Stack "
<<
it
.
first
.
user_stack
<<
"]"
<<
std
::
endl
;
}
}
}
auto
detach_res
=
bpf
.
detach_kprobe
(
"tcp_sendmsg"
);
if
(
detach_res
.
code
()
!=
0
)
{
std
::
cerr
<<
detach_res
.
msg
()
<<
std
::
endl
;
return
1
;
}
if
(
lost_stacks
>
0
)
std
::
cout
<<
"Total "
<<
lost_stacks
<<
" stack-traces lost due to "
<<
"hash collision or stack table full"
<<
std
::
endl
;
return
0
;
}
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