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
ef6bb809
Commit
ef6bb809
authored
Mar 04, 2016
by
Brenden Blanco
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Better get_stackid rewriter logic and unittest version testing
Signed-off-by:
Brenden Blanco
<
bblanco@plumgrid.com
>
parent
ad0e8836
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
4 deletions
+24
-4
src/cc/frontends/clang/b_frontend_action.cc
src/cc/frontends/clang/b_frontend_action.cc
+8
-3
tests/python/test_stackid.py
tests/python/test_stackid.py
+16
-1
No files found.
src/cc/frontends/clang/b_frontend_action.cc
View file @
ef6bb809
...
@@ -315,6 +315,8 @@ bool BTypeVisitor::VisitCallExpr(CallExpr *Call) {
...
@@ -315,6 +315,8 @@ bool BTypeVisitor::VisitCallExpr(CallExpr *Call) {
string
prefix
,
suffix
;
string
prefix
,
suffix
;
string
map_update_policy
=
"BPF_ANY"
;
string
map_update_policy
=
"BPF_ANY"
;
string
txt
;
string
txt
;
auto
rewrite_start
=
Call
->
getLocStart
();
auto
rewrite_end
=
Call
->
getLocEnd
();
if
(
memb_name
==
"lookup_or_init"
)
{
if
(
memb_name
==
"lookup_or_init"
)
{
map_update_policy
=
"BPF_NOEXIST"
;
map_update_policy
=
"BPF_NOEXIST"
;
string
name
=
Ref
->
getDecl
()
->
getName
();
string
name
=
Ref
->
getDecl
()
->
getName
();
...
@@ -354,8 +356,11 @@ bool BTypeVisitor::VisitCallExpr(CallExpr *Call) {
...
@@ -354,8 +356,11 @@ bool BTypeVisitor::VisitCallExpr(CallExpr *Call) {
txt
+=
", bpf_get_smp_processor_id(), "
+
args_other
+
")"
;
txt
+=
", bpf_get_smp_processor_id(), "
+
args_other
+
")"
;
}
else
if
(
memb_name
==
"get_stackid"
)
{
}
else
if
(
memb_name
==
"get_stackid"
)
{
if
(
table_it
->
type
==
BPF_MAP_TYPE_STACK_TRACE
)
{
if
(
table_it
->
type
==
BPF_MAP_TYPE_STACK_TRACE
)
{
string
arg0
=
rewriter_
.
getRewrittenText
(
SourceRange
(
Call
->
getArg
(
0
)
->
getLocStart
(),
Call
->
getArg
(
0
)
->
getLocEnd
()));
txt
=
"bpf_get_stackid("
;
txt
=
"bpf_get_stackid("
;
txt
+=
"bpf_pseudo_fd(1, "
+
fd
+
"), "
+
args
+
")"
;
txt
+=
"bpf_pseudo_fd(1, "
+
fd
+
"), "
+
arg0
;
rewrite_end
=
Call
->
getArg
(
0
)
->
getLocEnd
();
}
else
{
}
else
{
unsigned
diag_id
=
C
.
getDiagnostics
().
getCustomDiagID
(
DiagnosticsEngine
::
Error
,
unsigned
diag_id
=
C
.
getDiagnostics
().
getCustomDiagID
(
DiagnosticsEngine
::
Error
,
"get_stackid only available on stacktrace maps"
);
"get_stackid only available on stacktrace maps"
);
...
@@ -387,12 +392,12 @@ bool BTypeVisitor::VisitCallExpr(CallExpr *Call) {
...
@@ -387,12 +392,12 @@ bool BTypeVisitor::VisitCallExpr(CallExpr *Call) {
txt
=
prefix
+
args
+
suffix
;
txt
=
prefix
+
args
+
suffix
;
}
}
if
(
!
rewriter_
.
isRewritable
(
Call
->
getLocStart
()
))
{
if
(
!
rewriter_
.
isRewritable
(
rewrite_start
)
||
!
rewriter_
.
isRewritable
(
rewrite_end
))
{
C
.
getDiagnostics
().
Report
(
Call
->
getLocStart
(),
diag
::
err_expected
)
C
.
getDiagnostics
().
Report
(
Call
->
getLocStart
(),
diag
::
err_expected
)
<<
"use of map function not in a macro"
;
<<
"use of map function not in a macro"
;
return
false
;
return
false
;
}
}
rewriter_
.
ReplaceText
(
SourceRange
(
Call
->
getLocStart
(),
Call
->
getLocEnd
()
),
txt
);
rewriter_
.
ReplaceText
(
SourceRange
(
rewrite_start
,
rewrite_end
),
txt
);
return
true
;
return
true
;
}
}
}
}
...
...
tests/python/test_stackid.py
View file @
ef6bb809
...
@@ -3,8 +3,23 @@
...
@@ -3,8 +3,23 @@
# Licensed under the Apache License, Version 2.0 (the "License")
# Licensed under the Apache License, Version 2.0 (the "License")
import
bcc
import
bcc
import
distutils.version
import
os
import
unittest
import
unittest
def
kernel_version_ge
(
major
,
minor
):
# True if running kernel is >= X.Y
version
=
distutils
.
version
.
LooseVersion
(
os
.
uname
()[
2
]).
version
if
version
[
0
]
>
major
:
return
True
if
version
[
0
]
<
major
:
return
False
if
minor
and
version
[
1
]
<
minor
:
return
False
return
True
@
unittest
.
skipUnless
(
kernel_version_ge
(
4
,
6
),
"requires kernel >= 4.6"
)
class
TestStackid
(
unittest
.
TestCase
):
class
TestStackid
(
unittest
.
TestCase
):
def
test_simple
(
self
):
def
test_simple
(
self
):
b
=
bcc
.
BPF
(
text
=
"""
b
=
bcc
.
BPF
(
text
=
"""
...
@@ -14,7 +29,7 @@ BPF_STACK_TRACE(stack_traces, 10240);
...
@@ -14,7 +29,7 @@ BPF_STACK_TRACE(stack_traces, 10240);
BPF_HASH(stack_entries, int, int);
BPF_HASH(stack_entries, int, int);
BPF_HASH(stub);
BPF_HASH(stub);
int kprobe__htab_map_delete_elem(struct pt_regs *ctx, struct bpf_map *map, u64 *k) {
int kprobe__htab_map_delete_elem(struct pt_regs *ctx, struct bpf_map *map, u64 *k) {
int id = stack_traces.get_stackid(ctx,
(BPF_F_REUSE_STACKID)
);
int id = stack_traces.get_stackid(ctx,
BPF_F_REUSE_STACKID
);
if (id < 0)
if (id < 0)
return 0;
return 0;
int key = 1;
int key = 1;
...
...
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