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
38cc5d62
Commit
38cc5d62
authored
May 16, 2017
by
Teng Qin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use bpf_get_first_key in Python API
parent
e0f347a1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
17 deletions
+16
-17
src/python/bcc/libbcc.py
src/python/bcc/libbcc.py
+2
-0
src/python/bcc/table.py
src/python/bcc/table.py
+14
-17
No files found.
src/python/bcc/libbcc.py
View file @
38cc5d62
...
...
@@ -69,6 +69,8 @@ lib.bpf_table_leaf_sscanf.argtypes = [ct.c_void_p, ct.c_ulonglong,
# keep in sync with libbpf.h
lib
.
bpf_get_next_key
.
restype
=
ct
.
c_int
lib
.
bpf_get_next_key
.
argtypes
=
[
ct
.
c_int
,
ct
.
c_void_p
,
ct
.
c_void_p
]
lib
.
bpf_get_first_key
.
restype
=
ct
.
c_int
lib
.
bpf_get_first_key
.
argtypes
=
[
ct
.
c_int
,
ct
.
c_void_p
,
ct
.
c_uint
]
lib
.
bpf_lookup_elem
.
restype
=
ct
.
c_int
lib
.
bpf_lookup_elem
.
argtypes
=
[
ct
.
c_int
,
ct
.
c_void_p
,
ct
.
c_void_p
]
lib
.
bpf_update_elem
.
restype
=
ct
.
c_int
...
...
src/python/bcc/table.py
View file @
38cc5d62
...
...
@@ -245,25 +245,15 @@ class TableBase(MutableMapping):
self
[
k
]
=
self
.
Leaf
()
def
__iter__
(
self
):
return
TableBase
.
Iter
(
self
,
self
.
Key
)
return
TableBase
.
Iter
(
self
)
def
iter
(
self
):
return
self
.
__iter__
()
def
keys
(
self
):
return
self
.
__iter__
()
class
Iter
(
object
):
def
__init__
(
self
,
table
,
keytype
):
self
.
Key
=
keytype
def
__init__
(
self
,
table
):
self
.
table
=
table
k
=
self
.
Key
()
kp
=
ct
.
pointer
(
k
)
# if 0 is a valid key, try a few alternatives
if
k
in
table
:
ct
.
memset
(
kp
,
0xff
,
ct
.
sizeof
(
k
))
if
k
in
table
:
ct
.
memset
(
kp
,
0x55
,
ct
.
sizeof
(
k
))
if
k
in
table
:
raise
Exception
(
"Unable to allocate iterator"
)
self
.
key
=
k
self
.
key
=
None
def
__iter__
(
self
):
return
self
def
__next__
(
self
):
...
...
@@ -275,10 +265,17 @@ class TableBase(MutableMapping):
def
next
(
self
,
key
):
next_key
=
self
.
Key
()
next_key_p
=
ct
.
pointer
(
next_key
)
key_p
=
ct
.
pointer
(
key
)
res
=
lib
.
bpf_get_next_key
(
self
.
map_fd
,
ct
.
cast
(
key_p
,
ct
.
c_void_p
),
ct
.
cast
(
next_key_p
,
ct
.
c_void_p
))
if
key
is
None
:
res
=
lib
.
bpf_get_first_key
(
self
.
map_fd
,
ct
.
cast
(
next_key_p
,
ct
.
c_void_p
),
ct
.
sizeof
(
self
.
Key
))
else
:
key_p
=
ct
.
pointer
(
key
)
res
=
lib
.
bpf_get_next_key
(
self
.
map_fd
,
ct
.
cast
(
key_p
,
ct
.
c_void_p
),
ct
.
cast
(
next_key_p
,
ct
.
c_void_p
))
if
res
<
0
:
raise
StopIteration
()
return
next_key
...
...
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