diff options
author | Ole Troan <ot@cisco.com> | 2019-04-15 08:53:46 +0200 |
---|---|---|
committer | Damjan Marion <dmarion@me.com> | 2019-04-16 15:55:42 +0000 |
commit | cbb8f589638c2634b44ee2de24c76696f983645a (patch) | |
tree | b725f28fb93f7e3f2db26719821c761146eec9f7 /src/vpp-api/client/stat_client.c | |
parent | 47feb1146ec3b0e1cf2ebd83cd5211e1df261194 (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/client/stat_client.c')
-rw-r--r-- | src/vpp-api/client/stat_client.c | 98 |
1 files changed, 56 insertions, 42 deletions
diff --git a/src/vpp-api/client/stat_client.c b/src/vpp-api/client/stat_client.c index 3959c92167f..a386eec30c3 100644 --- a/src/vpp-api/client/stat_client.c +++ b/src/vpp-api/client/stat_client.c @@ -97,13 +97,6 @@ get_stat_vector_r (stat_client_main_t * sm) sm->shared_header->directory_offset); } -static stat_segment_directory_entry_t * -get_stat_vector (void) -{ - stat_client_main_t *sm = &stat_client_main; - return get_stat_vector_r (sm); -} - int stat_segment_connect_r (const char *socket_name, stat_client_main_t * sm) { @@ -176,6 +169,31 @@ stat_segment_disconnect_r (stat_client_main_t * sm) return; } +typedef struct +{ + uint64_t epoch; +} stat_segment_access_t; + +static void +stat_segment_access_start (stat_segment_access_t * sa, + stat_client_main_t * sm) +{ + stat_segment_shared_header_t *shared_header = sm->shared_header; + sa->epoch = shared_header->epoch; + while (shared_header->in_progress != 0) + ; +} + +static bool +stat_segment_access_end (stat_segment_access_t * sa, stat_client_main_t * sm) +{ + stat_segment_shared_header_t *shared_header = sm->shared_header; + + if (shared_header->epoch != sa->epoch || shared_header->in_progress) + return false; + return true; +} + void stat_segment_disconnect (void) { @@ -186,9 +204,17 @@ stat_segment_disconnect (void) double stat_segment_heartbeat_r (stat_client_main_t * sm) { - stat_segment_directory_entry_t *vec = get_stat_vector_r (sm); - double *hb = stat_segment_pointer (sm->shared_header, vec[4].offset); - return *hb; + stat_segment_access_t sa; + stat_segment_directory_entry_t *ep; + + /* Has directory been update? */ + if (sm->shared_header->epoch != sm->current_epoch) + return 0; + stat_segment_access_start (&sa, sm); + ep = vec_elt_at_index (sm->directory_vector, STAT_COUNTER_HEARTBEAT); + if (!stat_segment_access_end (&sa, sm)) + return 0.0; + return ep->value; } double @@ -308,32 +334,6 @@ stat_segment_data_free (stat_segment_data_t * res) vec_free (res); } - -typedef struct -{ - uint64_t epoch; -} stat_segment_access_t; - -static void -stat_segment_access_start (stat_segment_access_t * sa, - stat_client_main_t * sm) -{ - stat_segment_shared_header_t *shared_header = sm->shared_header; - sa->epoch = shared_header->epoch; - while (shared_header->in_progress != 0) - ; -} - -static bool -stat_segment_access_end (stat_segment_access_t * sa, stat_client_main_t * sm) -{ - stat_segment_shared_header_t *shared_header = sm->shared_header; - - if (shared_header->epoch != sa->epoch || shared_header->in_progress) - return false; - return true; -} - uint32_t * stat_segment_ls_r (uint8_t ** patterns, stat_client_main_t * sm) { @@ -480,14 +480,28 @@ stat_segment_dump_entry (uint32_t index) } char * -stat_segment_index_to_name (uint32_t index) +stat_segment_index_to_name_r (uint32_t index, stat_client_main_t * sm) { - char *name; - stat_segment_directory_entry_t *counter_vec = get_stat_vector (); stat_segment_directory_entry_t *ep; - ep = vec_elt_at_index (counter_vec, index); - name = strdup (ep->name); - return name; + stat_segment_access_t sa; + stat_segment_directory_entry_t *vec; + + /* Has directory been update? */ + if (sm->shared_header->epoch != sm->current_epoch) + return 0; + stat_segment_access_start (&sa, sm); + vec = get_stat_vector_r (sm); + ep = vec_elt_at_index (vec, index); + if (!stat_segment_access_end (&sa, sm)) + return 0; + return strdup (ep->name); +} + +char * +stat_segment_index_to_name (uint32_t index) +{ + stat_client_main_t *sm = &stat_client_main; + return stat_segment_index_to_name_r (index, sm); } /* |