aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/vpp-api/client/stat_client.c98
-rw-r--r--src/vpp-api/client/stat_client.h1
-rw-r--r--src/vpp-api/python/vpp_papi/vpp_stats.py24
-rw-r--r--src/vpp/stats/stat_segment.c5
4 files changed, 81 insertions, 47 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);
}
/*
diff --git a/src/vpp-api/client/stat_client.h b/src/vpp-api/client/stat_client.h
index 23087abe749..fb2adfe8f1f 100644
--- a/src/vpp-api/client/stat_client.h
+++ b/src/vpp-api/client/stat_client.h
@@ -73,6 +73,7 @@ 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);
+char *stat_segment_index_to_name_r (uint32_t index, stat_client_main_t * sm);
char *stat_segment_index_to_name (uint32_t index);
#endif /* included_stat_client_h */
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])
diff --git a/src/vpp/stats/stat_segment.c b/src/vpp/stats/stat_segment.c
index 05b8cdcb34d..2cf82b97f18 100644
--- a/src/vpp/stats/stat_segment.c
+++ b/src/vpp/stats/stat_segment.c
@@ -427,7 +427,7 @@ update_node_counters (stat_segment_main_t * sm)
stat_validate_counter_vector (&sm->directory_vector
[STAT_COUNTER_NODE_SUSPENDS], l);
- vec_validate (sm->nodes, l);
+ vec_validate (sm->nodes, l - 1);
stat_segment_directory_entry_t *ep;
ep = &sm->directory_vector[STAT_COUNTER_NODE_NAMES];
ep->offset = stat_segment_offset (shared_header, sm->nodes);
@@ -437,8 +437,9 @@ update_node_counters (stat_segment_main_t * sm)
ep->offset_vector ? stat_segment_pointer (shared_header,
ep->offset_vector) : 0;
/* Update names dictionary */
- vec_validate (offset_vector, l);
+ vec_validate (offset_vector, l - 1);
vlib_node_t **nodes = node_dups[0];
+
for (i = 0; i < vec_len (nodes); i++)
{
vlib_node_t *n = nodes[i];