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
15488d75
Commit
15488d75
authored
Apr 27, 2018
by
Teng Qin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add checks of table type in constructor
parent
bbc3fbfe
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
14 deletions
+31
-14
src/cc/api/BPFTable.cc
src/cc/api/BPFTable.cc
+27
-0
src/cc/api/BPFTable.h
src/cc/api/BPFTable.h
+4
-14
No files found.
src/cc/api/BPFTable.cc
View file @
15488d75
...
@@ -191,6 +191,9 @@ BPFStackTable::BPFStackTable(const TableDesc& desc,
...
@@ -191,6 +191,9 @@ BPFStackTable::BPFStackTable(const TableDesc& desc,
bool
use_debug_file
,
bool
use_debug_file
,
bool
check_debug_file_crc
)
bool
check_debug_file_crc
)
:
BPFTableBase
<
int
,
stacktrace_t
>
(
desc
)
{
:
BPFTableBase
<
int
,
stacktrace_t
>
(
desc
)
{
if
(
desc
.
type
!=
BPF_MAP_TYPE_STACK_TRACE
)
throw
std
::
invalid_argument
(
"Table '"
+
desc
.
name
+
"' is not a stack table"
);
symbol_option_
=
{
symbol_option_
=
{
.
use_debug_file
=
use_debug_file
,
.
use_debug_file
=
use_debug_file
,
.
check_debug_file_crc
=
check_debug_file_crc
,
.
check_debug_file_crc
=
check_debug_file_crc
,
...
@@ -254,6 +257,12 @@ std::vector<std::string> BPFStackTable::get_stack_symbol(int stack_id,
...
@@ -254,6 +257,12 @@ std::vector<std::string> BPFStackTable::get_stack_symbol(int stack_id,
return
res
;
return
res
;
}
}
BPFPerfBuffer
::
BPFPerfBuffer
(
const
TableDesc
&
desc
)
:
BPFTableBase
<
int
,
int
>
(
desc
),
epfd_
(
-
1
)
{
if
(
desc
.
type
!=
BPF_MAP_TYPE_PERF_EVENT_ARRAY
)
throw
std
::
invalid_argument
(
"Table '"
+
desc
.
name
+
"' is not a perf buffer"
);
}
StatusTuple
BPFPerfBuffer
::
open_on_cpu
(
perf_reader_raw_cb
cb
,
StatusTuple
BPFPerfBuffer
::
open_on_cpu
(
perf_reader_raw_cb
cb
,
perf_reader_lost_cb
lost_cb
,
int
cpu
,
perf_reader_lost_cb
lost_cb
,
int
cpu
,
void
*
cb_cookie
,
int
page_cnt
)
{
void
*
cb_cookie
,
int
page_cnt
)
{
...
@@ -363,6 +372,12 @@ BPFPerfBuffer::~BPFPerfBuffer() {
...
@@ -363,6 +372,12 @@ BPFPerfBuffer::~BPFPerfBuffer() {
<<
std
::
endl
;
<<
std
::
endl
;
}
}
BPFPerfEventArray
::
BPFPerfEventArray
(
const
TableDesc
&
desc
)
:
BPFTableBase
<
int
,
int
>
(
desc
)
{
if
(
desc
.
type
!=
BPF_MAP_TYPE_PERF_EVENT_ARRAY
)
throw
std
::
invalid_argument
(
"Table '"
+
desc
.
name
+
"' is not a perf event array"
);
}
StatusTuple
BPFPerfEventArray
::
open_all_cpu
(
uint32_t
type
,
uint64_t
config
)
{
StatusTuple
BPFPerfEventArray
::
open_all_cpu
(
uint32_t
type
,
uint64_t
config
)
{
if
(
cpu_fds_
.
size
()
!=
0
)
if
(
cpu_fds_
.
size
()
!=
0
)
return
StatusTuple
(
-
1
,
"Previously opened perf event not cleaned"
);
return
StatusTuple
(
-
1
,
"Previously opened perf event not cleaned"
);
...
@@ -436,6 +451,12 @@ BPFPerfEventArray::~BPFPerfEventArray() {
...
@@ -436,6 +451,12 @@ BPFPerfEventArray::~BPFPerfEventArray() {
}
}
}
}
BPFProgTable
::
BPFProgTable
(
const
TableDesc
&
desc
)
:
BPFTableBase
<
int
,
int
>
(
desc
)
{
if
(
desc
.
type
!=
BPF_MAP_TYPE_PROG_ARRAY
)
throw
std
::
invalid_argument
(
"Table '"
+
desc
.
name
+
"' is not a prog table"
);
}
StatusTuple
BPFProgTable
::
update_value
(
const
int
&
index
,
const
int
&
prog_fd
)
{
StatusTuple
BPFProgTable
::
update_value
(
const
int
&
index
,
const
int
&
prog_fd
)
{
if
(
!
this
->
update
(
const_cast
<
int
*>
(
&
index
),
const_cast
<
int
*>
(
&
prog_fd
)))
if
(
!
this
->
update
(
const_cast
<
int
*>
(
&
index
),
const_cast
<
int
*>
(
&
prog_fd
)))
return
StatusTuple
(
-
1
,
"Error updating value: %s"
,
std
::
strerror
(
errno
));
return
StatusTuple
(
-
1
,
"Error updating value: %s"
,
std
::
strerror
(
errno
));
...
@@ -448,6 +469,12 @@ StatusTuple BPFProgTable::remove_value(const int& index) {
...
@@ -448,6 +469,12 @@ StatusTuple BPFProgTable::remove_value(const int& index) {
return
StatusTuple
(
0
);
return
StatusTuple
(
0
);
}
}
BPFCgroupArray
::
BPFCgroupArray
(
const
TableDesc
&
desc
)
:
BPFTableBase
<
int
,
int
>
(
desc
)
{
if
(
desc
.
type
!=
BPF_MAP_TYPE_CGROUP_ARRAY
)
throw
std
::
invalid_argument
(
"Table '"
+
desc
.
name
+
"' is not a cgroup array"
);
}
StatusTuple
BPFCgroupArray
::
update_value
(
const
int
&
index
,
StatusTuple
BPFCgroupArray
::
update_value
(
const
int
&
index
,
const
int
&
cgroup2_fd
)
{
const
int
&
cgroup2_fd
)
{
if
(
!
this
->
update
(
const_cast
<
int
*>
(
&
index
),
const_cast
<
int
*>
(
&
cgroup2_fd
)))
if
(
!
this
->
update
(
const_cast
<
int
*>
(
&
index
),
const_cast
<
int
*>
(
&
cgroup2_fd
)))
...
...
src/cc/api/BPFTable.h
View file @
15488d75
...
@@ -299,8 +299,7 @@ class BPFStackTable : public BPFTableBase<int, stacktrace_t> {
...
@@ -299,8 +299,7 @@ class BPFStackTable : public BPFTableBase<int, stacktrace_t> {
class
BPFPerfBuffer
:
public
BPFTableBase
<
int
,
int
>
{
class
BPFPerfBuffer
:
public
BPFTableBase
<
int
,
int
>
{
public:
public:
BPFPerfBuffer
(
const
TableDesc
&
desc
)
BPFPerfBuffer
(
const
TableDesc
&
desc
);
:
BPFTableBase
<
int
,
int
>
(
desc
),
epfd_
(
-
1
)
{}
~
BPFPerfBuffer
();
~
BPFPerfBuffer
();
StatusTuple
open_all_cpu
(
perf_reader_raw_cb
cb
,
perf_reader_lost_cb
lost_cb
,
StatusTuple
open_all_cpu
(
perf_reader_raw_cb
cb
,
perf_reader_lost_cb
lost_cb
,
...
@@ -321,8 +320,7 @@ class BPFPerfBuffer : public BPFTableBase<int, int> {
...
@@ -321,8 +320,7 @@ class BPFPerfBuffer : public BPFTableBase<int, int> {
class
BPFPerfEventArray
:
public
BPFTableBase
<
int
,
int
>
{
class
BPFPerfEventArray
:
public
BPFTableBase
<
int
,
int
>
{
public:
public:
BPFPerfEventArray
(
const
TableDesc
&
desc
)
BPFPerfEventArray
(
const
TableDesc
&
desc
);
:
BPFTableBase
<
int
,
int
>
(
desc
)
{}
~
BPFPerfEventArray
();
~
BPFPerfEventArray
();
StatusTuple
open_all_cpu
(
uint32_t
type
,
uint64_t
config
);
StatusTuple
open_all_cpu
(
uint32_t
type
,
uint64_t
config
);
...
@@ -337,11 +335,7 @@ class BPFPerfEventArray : public BPFTableBase<int, int> {
...
@@ -337,11 +335,7 @@ class BPFPerfEventArray : public BPFTableBase<int, int> {
class
BPFProgTable
:
public
BPFTableBase
<
int
,
int
>
{
class
BPFProgTable
:
public
BPFTableBase
<
int
,
int
>
{
public:
public:
BPFProgTable
(
const
TableDesc
&
desc
)
BPFProgTable
(
const
TableDesc
&
desc
);
:
BPFTableBase
<
int
,
int
>
(
desc
)
{
if
(
desc
.
type
!=
BPF_MAP_TYPE_PROG_ARRAY
)
throw
std
::
invalid_argument
(
"Table '"
+
desc
.
name
+
"' is not a prog table"
);
}
StatusTuple
update_value
(
const
int
&
index
,
const
int
&
prog_fd
);
StatusTuple
update_value
(
const
int
&
index
,
const
int
&
prog_fd
);
StatusTuple
remove_value
(
const
int
&
index
);
StatusTuple
remove_value
(
const
int
&
index
);
...
@@ -349,11 +343,7 @@ public:
...
@@ -349,11 +343,7 @@ public:
class
BPFCgroupArray
:
public
BPFTableBase
<
int
,
int
>
{
class
BPFCgroupArray
:
public
BPFTableBase
<
int
,
int
>
{
public:
public:
BPFCgroupArray
(
const
TableDesc
&
desc
)
BPFCgroupArray
(
const
TableDesc
&
desc
);
:
BPFTableBase
<
int
,
int
>
(
desc
)
{
if
(
desc
.
type
!=
BPF_MAP_TYPE_CGROUP_ARRAY
)
throw
std
::
invalid_argument
(
"Table '"
+
desc
.
name
+
"' is not a cgroup array"
);
}
StatusTuple
update_value
(
const
int
&
index
,
const
int
&
cgroup2_fd
);
StatusTuple
update_value
(
const
int
&
index
,
const
int
&
cgroup2_fd
);
StatusTuple
update_value
(
const
int
&
index
,
const
std
::
string
&
cgroup2_path
);
StatusTuple
update_value
(
const
int
&
index
,
const
std
::
string
&
cgroup2_path
);
...
...
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