MCPcopy Create free account
hub / github.com/FDio/vpp / StatsVector

Class StatsVector

src/vpp-api/python/vpp_papi/vpp_stats.py:83–116  ·  view source on GitHub ↗

A class representing a VPP vector

Source from the content-addressed store, hash-verified

81
82
83class StatsVector:
84 """A class representing a VPP vector"""
85
86 def __init__(self, stats, ptr, fmt):
87 self.vec_start = ptr - stats.base
88 self.vec_len = get_vec_len(stats, ptr - stats.base)
89 self.struct = Struct(fmt)
90 self.fmtlen = len(fmt)
91 self.elementsize = self.struct.size
92 self.statseg = stats.statseg
93 self.stats = stats
94
95 if self.vec_start + self.vec_len * self.elementsize >= stats.size:
96 raise IOError("Vector overruns stats segment")
97
98 def __iter__(self):
99 with self.stats.lock:
100 return self.struct.iter_unpack(
101 self.statseg[
102 self.vec_start : self.vec_start + self.elementsize * self.vec_len
103 ]
104 )
105
106 def __getitem__(self, index):
107 if index > self.vec_len:
108 raise IOError("Index beyond end of vector")
109 with self.stats.lock:
110 if self.fmtlen == 1:
111 return self.struct.unpack_from(
112 self.statseg, self.vec_start + (index * self.elementsize)
113 )[0]
114 return self.struct.unpack_from(
115 self.statseg, self.vec_start + (index * self.elementsize)
116 )
117
118
119class VPPStats:

Callers 5

refreshMethod · 0.85
simpleMethod · 0.85
combinedMethod · 0.85
nameMethod · 0.85
histogram_log2Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected