Commit 1217f018 authored by Brenden Blanco's avatar Brenden Blanco

Split bcc.table.BPFTable into multiple type-specific classes

BPFTable contained all of the logic for multiple table types, which is
incorrect since a bpf table has either hash or array behavior.
Additionally, some methods on the classes aren't valid for some table
types. Create HashTable, Array, ProgArray, and PerfEventArray classes to
contain this behavior.

In future, the new Array class and its children should behave more like
an array than a dict as it currently does.
Signed-off-by: default avatarBrenden Blanco <bblanco@plumgrid.com>
parent 134f6530
......@@ -26,7 +26,7 @@ import sys
basestring = (unicode if sys.version_info[0] < 3 else str)
from .libbcc import lib, _CB_TYPE
from .table import BPFTable
from .table import Table
open_kprobes = {}
open_uprobes = {}
......@@ -64,7 +64,9 @@ class BPF(object):
_libsearch_cache = {}
_lib_load_address_cache = {}
_lib_symbol_cache = {}
Table = BPFTable
# defined for compatibility reasons, to be removed
Table = Table
class Function(object):
def __init__(self, bpf, name, fd):
......@@ -234,7 +236,7 @@ class BPF(object):
if not leaf_desc:
raise Exception("Failed to load BPF Table %s leaf desc" % name)
leaftype = BPF._decode_table_type(json.loads(leaf_desc.decode()))
return BPF.Table(self, map_id, map_fd, keytype, leaftype)
return Table(self, map_id, map_fd, keytype, leaftype)
def __getitem__(self, key):
if key not in self.tables:
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment