Code Review
/
vpp.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
PAPI: Add support for format/unformat functions.
[vpp.git]
/
src
/
vpp-api
/
python
/
vpp_papi
/
vpp_stats.py
diff --git
a/src/vpp-api/python/vpp_papi/vpp_stats.py
b/src/vpp-api/python/vpp_papi/vpp_stats.py
index
9bdb79f
..
76e1e54
100644
(file)
--- a/
src/vpp-api/python/vpp_papi/vpp_stats.py
+++ b/
src/vpp-api/python/vpp_papi/vpp_stats.py
@@
-62,7
+62,8
@@
def make_string_vector(api, strings):
if type(strings) is not list:
strings = [strings]
for s in strings:
if type(strings) is not list:
strings = [strings]
for s in strings:
- vec = api.stat_segment_string_vector(vec, ffi.new("char []", s))
+ vec = api.stat_segment_string_vector(vec, ffi.new("char []",
+ s.encode()))
return vec
return vec
@@
-114,7
+115,7
@@
def stat_entry_to_python(api, e):
class VPPStats:
def __init__(self, socketname='/var/run/stats.sock'):
self.api = ffi.dlopen('libvppapiclient.so')
class VPPStats:
def __init__(self, socketname='/var/run/stats.sock'):
self.api = ffi.dlopen('libvppapiclient.so')
- rv = self.api.stat_segment_connect(socketname)
+ rv = self.api.stat_segment_connect(socketname
.encode()
)
if rv != 0:
raise IOError()
if rv != 0:
raise IOError()
@@
-127,24
+128,45
@@
class VPPStats:
def dump(self, counters):
stats = {}
rv = self.api.stat_segment_dump(counters)
def dump(self, counters):
stats = {}
rv = self.api.stat_segment_dump(counters)
+ # Raise exception and retry
+ if rv == ffi.NULL:
+ raise IOError()
rv_len = self.api.stat_segment_vec_len(rv)
for i in range(rv_len):
rv_len = self.api.stat_segment_vec_len(rv)
for i in range(rv_len):
- n = ffi.string(rv[i].name)
+ n = ffi.string(rv[i].name)
.decode()
e = stat_entry_to_python(self.api, rv[i])
e = stat_entry_to_python(self.api, rv[i])
- stats[n] = e
+ if e is not None:
+ stats[n] = e
return stats
def get_counter(self, name):
return stats
def get_counter(self, name):
- dir = self.ls(name)
- return self.dump(dir).values()[0]
+ retries = 0
+ while True:
+ try:
+ dir = self.ls(name)
+ return self.dump(dir).values()[0]
+ except Exception as e:
+ if retries > 10:
+ return None
+ retries += 1
+ pass
def disconnect(self):
self.api.stat_segment_disconnect()
def set_errors(self):
'''Return all errors counters > 0'''
def disconnect(self):
self.api.stat_segment_disconnect()
def set_errors(self):
'''Return all errors counters > 0'''
- error_names = self.ls(['/err/'])
- error_counters = self.dump(error_names)
+ retries = 0
+ while True:
+ try:
+ error_names = self.ls(['/err/'])
+ error_counters = self.dump(error_names)
+ break
+ except Exception as e:
+ if retries > 10:
+ return None
+ retries += 1
+ pass
return {k: error_counters[k]
for k in error_counters.keys() if error_counters[k]}
return {k: error_counters[k]
for k in error_counters.keys() if error_counters[k]}