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
63b6e44e
Commit
63b6e44e
authored
Apr 06, 2018
by
Teng Qin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve clear table API in C++
parent
5d23500a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
15 deletions
+60
-15
src/cc/api/BPFTable.cc
src/cc/api/BPFTable.cc
+47
-8
src/cc/api/BPFTable.h
src/cc/api/BPFTable.h
+3
-7
tests/cc/test_bpf_table.cc
tests/cc/test_bpf_table.cc
+10
-0
No files found.
src/cc/api/BPFTable.cc
View file @
63b6e44e
...
...
@@ -142,6 +142,45 @@ StatusTuple BPFTable::remove_value(const std::string& key_str) {
return
StatusTuple
(
0
);
}
StatusTuple
BPFTable
::
clear_table_non_atomic
()
{
if
(
desc
.
type
==
BPF_MAP_TYPE_HASH
||
desc
.
type
==
BPF_MAP_TYPE_PERCPU_HASH
||
desc
.
type
==
BPF_MAP_TYPE_LRU_HASH
||
desc
.
type
==
BPF_MAP_TYPE_PERCPU_HASH
||
desc
.
type
==
BPF_MAP_TYPE_HASH_OF_MAPS
)
{
// For hash maps, use the first() interface (which uses get_next_key) to
// iterate through the map and clear elements
auto
key
=
std
::
unique_ptr
<
void
,
decltype
(
::
free
)
*>
(
::
malloc
(
desc
.
key_size
),
::
free
);
while
(
this
->
first
(
key
.
get
()))
if
(
!
this
->
remove
(
key
.
get
()))
{
return
StatusTuple
(
-
1
,
"Failed to delete element when clearing table %s"
,
desc
.
name
.
c_str
());
}
}
else
if
(
desc
.
type
==
BPF_MAP_TYPE_ARRAY
||
desc
.
type
==
BPF_MAP_TYPE_PERCPU_ARRAY
)
{
return
StatusTuple
(
-
1
,
"Array map %s do not support clearing elements"
,
desc
.
name
.
c_str
());
}
else
if
(
desc
.
type
==
BPF_MAP_TYPE_PROG_ARRAY
||
desc
.
type
==
BPF_MAP_TYPE_PERF_EVENT_ARRAY
||
desc
.
type
==
BPF_MAP_TYPE_STACK_TRACE
||
desc
.
type
==
BPF_MAP_TYPE_ARRAY_OF_MAPS
)
{
// For Stack-trace and FD arrays, just iterate over all indices
for
(
size_t
i
=
0
;
i
<
desc
.
max_entries
;
i
++
)
{
this
->
remove
(
&
i
);
}
}
else
{
return
StatusTuple
(
-
1
,
"Clearing for map type of %s not supported yet"
,
desc
.
name
.
c_str
());
}
return
StatusTuple
(
0
);
}
size_t
BPFTable
::
get_possible_cpu_count
()
{
return
get_possible_cpus
().
size
();
}
...
...
@@ -149,7 +188,7 @@ size_t BPFTable::get_possible_cpu_count() {
BPFStackTable
::
BPFStackTable
(
const
TableDesc
&
desc
,
bool
use_debug_file
,
bool
check_debug_file_crc
)
:
BPFTableBase
<
int
,
stacktrace_t
>
(
desc
)
{
:
BPFTableBase
<
int
,
stacktrace_t
>
(
desc
)
{
symbol_option_
=
{
.
use_debug_file
=
use_debug_file
,
.
check_debug_file_crc
=
check_debug_file_crc
,
...
...
@@ -157,11 +196,11 @@ BPFStackTable::BPFStackTable(const TableDesc& desc,
};
}
BPFStackTable
::
BPFStackTable
(
BPFStackTable
&&
that
)
:
BPFTableBase
<
int
,
stacktrace_t
>
(
that
.
desc
),
symbol_option_
(
std
::
move
(
that
.
symbol_option_
)),
pid_sym_
(
std
::
move
(
that
.
pid_sym_
))
{
that
.
pid_sym_
.
clear
();
BPFStackTable
::
BPFStackTable
(
BPFStackTable
&&
that
)
:
BPFTableBase
<
int
,
stacktrace_t
>
(
that
.
desc
),
symbol_option_
(
std
::
move
(
that
.
symbol_option_
)),
pid_sym_
(
std
::
move
(
that
.
pid_sym_
))
{
that
.
pid_sym_
.
clear
();
}
BPFStackTable
::~
BPFStackTable
()
{
...
...
@@ -214,8 +253,8 @@ std::vector<std::string> BPFStackTable::get_stack_symbol(int stack_id,
}
StatusTuple
BPFPerfBuffer
::
open_on_cpu
(
perf_reader_raw_cb
cb
,
perf_reader_lost_cb
lost_cb
,
int
cpu
,
void
*
cb_cookie
,
int
page_cnt
)
{
perf_reader_lost_cb
lost_cb
,
int
cpu
,
void
*
cb_cookie
,
int
page_cnt
)
{
if
(
cpu_readers_
.
find
(
cpu
)
!=
cpu_readers_
.
end
())
return
StatusTuple
(
-
1
,
"Perf buffer already open on CPU %d"
,
cpu
);
...
...
src/cc/api/BPFTable.h
View file @
63b6e44e
...
...
@@ -105,6 +105,8 @@ class BPFTable : public BPFTableBase<void, void> {
StatusTuple
remove_value
(
const
std
::
string
&
key_str
);
StatusTuple
clear_table_non_atomic
();
static
size_t
get_possible_cpu_count
();
};
...
...
@@ -237,14 +239,8 @@ class BPFHashTable : public BPFTableBase<KeyType, ValueType> {
StatusTuple
clear_table_non_atomic
()
{
KeyType
cur
;
if
(
!
this
->
first
(
&
cur
))
return
StatusTuple
(
0
);
while
(
true
)
{
while
(
this
->
first
(
&
cur
))
TRY2
(
remove_value
(
cur
));
if
(
!
this
->
next
(
&
cur
,
&
cur
))
break
;
}
return
StatusTuple
(
0
);
}
...
...
tests/cc/test_bpf_table.cc
View file @
63b6e44e
...
...
@@ -54,6 +54,16 @@ TEST_CASE("test bpf table", "[bpf_table]") {
res
=
t
.
get_value
(
"0x11"
,
value
);
REQUIRE
(
res
.
code
()
!=
0
);
// clear table
res
=
t
.
update_value
(
"0x15"
,
"0x888"
);
REQUIRE
(
res
.
code
()
==
0
);
auto
elements
=
bpf
->
get_hash_table
<
int
,
int
>
(
"myhash"
).
get_table_offline
();
REQUIRE
(
elements
.
size
()
==
2
);
res
=
t
.
clear_table_non_atomic
();
REQUIRE
(
res
.
code
()
==
0
);
elements
=
bpf
->
get_hash_table
<
int
,
int
>
(
"myhash"
).
get_table_offline
();
REQUIRE
(
elements
.
size
()
==
0
);
// delete bpf_module, call to key/leaf printf/scanf must fail
delete
bpf
;
...
...
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