aboutsummaryrefslogtreecommitdiffstats
path: root/src/vpp-api/python/vpp_papi/vpp_stats.py
diff options
context:
space:
mode:
authorOle Troan <ot@cisco.com>2019-04-15 08:53:46 +0200
committerDamjan Marion <dmarion@me.com>2019-04-16 15:55:42 +0000
commitcbb8f589638c2634b44ee2de24c76696f983645a (patch)
treeb725f28fb93f7e3f2db26719821c761146eec9f7 /src/vpp-api/python/vpp_papi/vpp_stats.py
parent47feb1146ec3b0e1cf2ebd83cd5211e1df261194 (diff)
stats: Add name vectors to Python client
Change-Id: Ic62dfa0bf3e082a0b999026830c64a9c543da586 Signed-off-by: Ole Troan <ot@cisco.com>
Diffstat (limited to 'src/vpp-api/python/vpp_papi/vpp_stats.py')
-rw-r--r--src/vpp-api/python/vpp_papi/vpp_stats.py24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/vpp-api/python/vpp_papi/vpp_stats.py b/src/vpp-api/python/vpp_papi/vpp_stats.py
index 59c87dd6a81..c90aa349434 100644
--- a/src/vpp-api/python/vpp_papi/vpp_stats.py
+++ b/src/vpp-api/python/vpp_papi/vpp_stats.py
@@ -18,6 +18,7 @@ typedef enum {
STAT_DIR_TYPE_COUNTER_VECTOR_SIMPLE,
STAT_DIR_TYPE_COUNTER_VECTOR_COMBINED,
STAT_DIR_TYPE_ERROR_INDEX,
+ STAT_DIR_TYPE_NAME_VECTOR,
} stat_directory_type_t;
typedef struct
@@ -42,6 +43,7 @@ typedef struct
uint64_t error_value;
counter_t **simple_counter_vec;
vlib_counter_t **combined_counter_vec;
+ uint8_t **name_vector;
};
} stat_segment_data_t;
@@ -76,9 +78,10 @@ stat_segment_data_t *stat_segment_dump (uint32_t * counter_vec);
void stat_segment_data_free (stat_segment_data_t * res);
double stat_segment_heartbeat_r (stat_client_main_t * sm);
-double stat_segment_heartbeat (void);
int stat_segment_vec_len(void *vec);
uint8_t **stat_segment_string_vector(uint8_t **string_vector, char *string);
+char *stat_segment_index_to_name_r (uint32_t index, stat_client_main_t * sm);
+void free(void *ptr);
""")
@@ -123,6 +126,8 @@ def combined_counter_vec_list(api, e):
vec.append(if_per_thread)
return vec
+def name_vec_list(api, e):
+ return [ffi.string(e[i]).decode('utf-8') for i in range(api.stat_segment_vec_len(e)) if e[i] != ffi.NULL]
def stat_entry_to_python(api, e):
# Scalar index
@@ -134,7 +139,9 @@ def stat_entry_to_python(api, e):
return combined_counter_vec_list(api, e.combined_counter_vec)
if e.type == 4:
return e.error_value
- return None
+ if e.type == 5:
+ return name_vec_list(api, e.name_vector)
+ raise NotImplementedError()
class VPPStatsIOError(IOError):
@@ -171,7 +178,7 @@ class VPPStatsClientLoadError(RuntimeError):
class VPPStats(object):
VPPStatsIOError = VPPStatsIOError
- default_socketname = '/var/run/stats.sock'
+ default_socketname = '/var/run/vpp/stats.sock'
sharedlib_name = 'libvppapiclient.so'
def __init__(self, socketname=default_socketname, timeout=10):
@@ -200,6 +207,16 @@ class VPPStats(object):
patterns),
self.client)
+ def lsstr(self, patterns):
+ rv = self.api.stat_segment_ls_r(make_string_vector(self.api,
+ patterns),
+ self.client)
+
+ if rv == ffi.NULL:
+ raise VPPStatsIOError()
+ return [ffi.string(self.api.stat_segment_index_to_name_r(rv[i], self.client)).decode('utf-8')
+ for i in range(self.api.stat_segment_vec_len(rv))]
+
def dump(self, counters):
stats = {}
rv = self.api.stat_segment_dump_r(counters, self.client)
@@ -207,6 +224,7 @@ class VPPStats(object):
if rv == ffi.NULL:
raise VPPStatsIOError()
rv_len = self.api.stat_segment_vec_len(rv)
+
for i in range(rv_len):
n = ffi.string(rv[i].name).decode('utf-8')
e = stat_entry_to_python(self.api, rv[i])