From 233e4681830bc2a9cd40deb4b5909b4e310d1a2a Mon Sep 17 00:00:00 2001 From: Ole Troan Date: Thu, 16 May 2019 15:01:34 +0200 Subject: stats: support multiple works for error counters The current code only allowed access to the main thread error counters. That is not so useful for a multi worker instance. No return a vector indexed by thread of counter_t values. Type: fix Change-Id: Ie322c8889c0c8175e1116e71de04a2cf453b9ed7 Signed-off-by: Ole Troan --- src/vpp-api/client/stat_client.c | 15 ++++++++++----- src/vpp-api/client/stat_client.h | 4 ++-- src/vpp-api/python/vpp_papi/vpp_stats.py | 19 +++++++++++++++---- 3 files changed, 27 insertions(+), 11 deletions(-) (limited to 'src/vpp-api') diff --git a/src/vpp-api/client/stat_client.c b/src/vpp-api/client/stat_client.c index a386eec30c3..8991806448a 100644 --- a/src/vpp-api/client/stat_client.c +++ b/src/vpp-api/client/stat_client.c @@ -231,7 +231,6 @@ copy_data (stat_segment_directory_entry_t * ep, stat_client_main_t * sm) int i; vlib_counter_t **combined_c; /* Combined counter */ counter_t **simple_c; /* Simple counter */ - counter_t *error_base; uint64_t *offset_vector; assert (sm->shared_header); @@ -275,10 +274,16 @@ copy_data (stat_segment_directory_entry_t * ep, stat_client_main_t * sm) break; case STAT_DIR_TYPE_ERROR_INDEX: - error_base = - stat_segment_pointer (sm->shared_header, - sm->shared_header->error_offset); - result.error_value = error_base[ep->index]; + /* Gather errors from all threads into a vector */ + offset_vector = stat_segment_pointer (sm->shared_header, + sm->shared_header->error_offset); + vec_validate (result.error_vector, vec_len (offset_vector) - 1); + for (i = 0; i < vec_len (offset_vector); i++) + { + counter_t *cb = + stat_segment_pointer (sm->shared_header, offset_vector[i]); + result.error_vector[i] = cb[ep->index]; + } break; case STAT_DIR_TYPE_NAME_VECTOR: diff --git a/src/vpp-api/client/stat_client.h b/src/vpp-api/client/stat_client.h index 1c76a938b30..901ec325522 100644 --- a/src/vpp-api/client/stat_client.h +++ b/src/vpp-api/client/stat_client.h @@ -18,7 +18,7 @@ #define included_stat_client_h #define STAT_VERSION_MAJOR 1 -#define STAT_VERSION_MINOR 1 +#define STAT_VERSION_MINOR 2 #include #include @@ -46,7 +46,7 @@ typedef struct union { double scalar_value; - uint64_t error_value; + counter_t *error_vector; counter_t **simple_counter_vec; vlib_counter_t **combined_counter_vec; uint8_t **name_vector; diff --git a/src/vpp-api/python/vpp_papi/vpp_stats.py b/src/vpp-api/python/vpp_papi/vpp_stats.py index c90aa349434..86a80ddc328 100644 --- a/src/vpp-api/python/vpp_papi/vpp_stats.py +++ b/src/vpp-api/python/vpp_papi/vpp_stats.py @@ -40,7 +40,7 @@ typedef struct union { double scalar_value; - uint64_t error_value; + counter_t *error_vector; counter_t **simple_counter_vec; vlib_counter_t **combined_counter_vec; uint8_t **name_vector; @@ -126,6 +126,12 @@ def combined_counter_vec_list(api, e): vec.append(if_per_thread) return vec +def error_vec_list(api, e): + vec = [] + for thread in range(api.stat_segment_vec_len(e)): + vec.append(e[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] @@ -138,7 +144,7 @@ def stat_entry_to_python(api, e): if e.type == 3: return combined_counter_vec_list(api, e.combined_counter_vec) if e.type == 4: - return e.error_value + return error_vec_list(api, e.error_vector) if e.type == 5: return name_vec_list(api, e.name_vector) raise NotImplementedError() @@ -248,6 +254,11 @@ class VPPStats(object): return None retries += 1 + def get_err_counter(self, name): + """Get an error counter. The errors from each worker thread + are summed""" + return sum(self.get_counter(name)) + def disconnect(self): self.api.stat_segment_disconnect_r(self.client) self.api.stat_client_free(self.client) @@ -265,8 +276,8 @@ class VPPStats(object): return None retries += 1 - return {k: error_counters[k] - for k in error_counters.keys() if error_counters[k]} + return {k: sum(error_counters[k]) + for k in error_counters.keys() if sum(error_counters[k])} def set_errors_str(self): '''Return all errors counters > 0 pretty printed''' -- cgit 1.2.3-korg