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
81031941
Commit
81031941
authored
Apr 25, 2018
by
Teng Qin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support of Cgroup Array in Python
parent
e5e9b1f5
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
2 deletions
+37
-2
src/python/bcc/table.py
src/python/bcc/table.py
+37
-2
No files found.
src/python/bcc/table.py
View file @
81031941
...
...
@@ -142,6 +142,8 @@ def Table(bpf, map_id, map_fd, keytype, leaftype, **kwargs):
t
=
LruHash
(
bpf
,
map_id
,
map_fd
,
keytype
,
leaftype
)
elif
ttype
==
BPF_MAP_TYPE_LRU_PERCPU_HASH
:
t
=
LruPerCpuHash
(
bpf
,
map_id
,
map_fd
,
keytype
,
leaftype
)
elif
ttype
==
BPF_MAP_TYPE_CGROUP_ARRAY
:
t
=
CgroupArray
(
bpf
,
map_id
,
map_fd
,
keytype
,
leaftype
)
if
t
==
None
:
raise
Exception
(
"Unknown table type %d"
%
ttype
)
return
t
...
...
@@ -199,8 +201,7 @@ class TableBase(MutableMapping):
return
leaf
def
__setitem__
(
self
,
key
,
leaf
):
res
=
lib
.
bpf_update_elem
(
self
.
map_fd
,
ct
.
byref
(
key
),
ct
.
byref
(
leaf
),
0
)
res
=
lib
.
bpf_update_elem
(
self
.
map_fd
,
ct
.
byref
(
key
),
ct
.
byref
(
leaf
),
0
)
if
res
<
0
:
errstr
=
os
.
strerror
(
ct
.
get_errno
())
raise
Exception
(
"Could not update table: %s"
%
errstr
)
...
...
@@ -477,6 +478,40 @@ class ProgArray(ArrayBase):
leaf
=
self
.
Leaf
(
leaf
.
fd
)
super
(
ProgArray
,
self
).
__setitem__
(
key
,
leaf
)
class
FileDesc
:
def
__init__
(
self
,
fd
):
if
(
fd
is
None
)
or
(
fd
<
0
):
raise
Exception
(
"Invalid file descriptor"
)
self
.
fd
=
fd
def
clean_up
(
self
):
if
(
self
.
fd
is
not
None
)
and
(
self
.
fd
>=
0
):
os
.
close
(
self
.
fd
)
self
.
fd
=
None
def
__del__
(
self
):
self
.
clean_up
()
def
__enter__
(
self
,
*
args
,
**
kwargs
):
return
self
def
__exit__
(
self
,
*
args
,
**
kwargs
):
self
.
clean_up
()
class
CgroupArray
(
ArrayBase
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
(
CgroupArray
,
self
).
__init__
(
*
args
,
**
kwargs
)
def
__setitem__
(
self
,
key
,
leaf
):
if
isinstance
(
leaf
,
int
):
super
(
CgroupArray
,
self
).
__setitem__
(
key
,
self
.
Leaf
(
leaf
))
elif
isinstance
(
leaf
,
str
):
# TODO: Add os.O_CLOEXEC once we move to Python version >3.3
with
FileDesc
(
os
.
open
(
leaf
,
os
.
O_RDONLY
))
as
f
:
super
(
CgroupArray
,
self
).
__setitem__
(
key
,
self
.
Leaf
(
f
.
fd
))
else
:
raise
Exception
(
"Cgroup array key must be either FD or cgroup path"
)
class
PerfEventArray
(
ArrayBase
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
...
...
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