summaryrefslogtreecommitdiffstats
path: root/src/vpp-api
diff options
context:
space:
mode:
authorDave Barach <dave@barachs.net>2019-08-14 09:35:41 -0400
committerAndrew Yourtchenko <ayourtch@gmail.com>2019-09-19 18:16:21 +0000
commit1ffabcb3df911f5f115a1c6dd51bdb5fdd3ac52c (patch)
tree46716a60634883ccd2f9017862515669478d743d /src/vpp-api
parent6b9847e8012b3b186897f3b2bdeaf478f8767301 (diff)
stats: refactor header files
Performant stat segment scraping involves caching the results of stat_segment_ls (...) and directly fishing counter data from the shared-memory segment. To do that, we need to publish several things previously hidden, declared in stat_client.c: o stat_client_main_t typedef o stat_segment_access_t typedef o stat_segment_access_start inline function o stat_segment_access_end inline function Type: refactor Signed-off-by: Dave Barach <dave@barachs.net> Change-Id: I3175e3d1f1fd8ea816336a584565179d1972115c (cherry picked from commit 531969ef614bdc15c45dae0f1b5e90afaf86eb7b)
Diffstat (limited to 'src/vpp-api')
-rw-r--r--src/vpp-api/client/stat_client.c38
-rw-r--r--src/vpp-api/client/stat_client.h53
2 files changed, 42 insertions, 49 deletions
diff --git a/src/vpp-api/client/stat_client.c b/src/vpp-api/client/stat_client.c
index 0eaec15ffb6..9a7a0e59daa 100644
--- a/src/vpp-api/client/stat_client.c
+++ b/src/vpp-api/client/stat_client.c
@@ -28,17 +28,9 @@
#include <assert.h>
#include <vppinfra/vec.h>
#include <vppinfra/lock.h>
-#include "stat_client.h"
#include <stdatomic.h>
#include <vpp/stats/stat_segment.h>
-
-struct stat_client_main_t
-{
- uint64_t current_epoch;
- stat_segment_shared_header_t *shared_header;
- stat_segment_directory_entry_t *directory_vector;
- ssize_t memory_size;
-};
+#include <vpp-api/client/stat_client.h>
stat_client_main_t stat_client_main;
@@ -169,34 +161,6 @@ 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)
- ;
- sm->directory_vector = stat_segment_pointer (sm->shared_header,
- sm->
- shared_header->directory_offset);
-}
-
-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)
{
diff --git a/src/vpp-api/client/stat_client.h b/src/vpp-api/client/stat_client.h
index 12faddb7bce..d8e90c0add0 100644
--- a/src/vpp-api/client/stat_client.h
+++ b/src/vpp-api/client/stat_client.h
@@ -23,22 +23,12 @@
#include <stdint.h>
#include <unistd.h>
#include <vlib/counter_types.h>
-
-typedef enum
-{
- STAT_DIR_TYPE_ILLEGAL = 0,
- STAT_DIR_TYPE_SCALAR_INDEX,
- 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;
+#include <stdbool.h>
+#include <vpp/stats/stat_segment_shared.h>
/* Default socket to exchange segment fd */
#define STAT_SEGMENT_SOCKET_FILE "/run/vpp/stats.sock"
-typedef struct stat_client_main_t stat_client_main_t;
-
typedef struct
{
char *name;
@@ -53,6 +43,16 @@ typedef struct
};
} stat_segment_data_t;
+typedef struct
+{
+ uint64_t current_epoch;
+ stat_segment_shared_header_t *shared_header;
+ stat_segment_directory_entry_t *directory_vector;
+ ssize_t memory_size;
+} stat_client_main_t;
+
+extern stat_client_main_t stat_client_main;
+
stat_client_main_t *stat_client_get (void);
void stat_client_free (stat_client_main_t * sm);
int stat_segment_connect_r (const char *socket_name, stat_client_main_t * sm);
@@ -81,6 +81,35 @@ char *stat_segment_index_to_name (uint32_t index);
uint64_t stat_segment_version (void);
uint64_t stat_segment_version_r (stat_client_main_t * sm);
+typedef struct
+{
+ uint64_t epoch;
+} stat_segment_access_t;
+
+static inline 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)
+ ;
+ sm->directory_vector = (stat_segment_directory_entry_t *)
+ stat_segment_pointer (sm->shared_header,
+ sm->shared_header->directory_offset);
+}
+
+static inline 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;
+}
+
+
#endif /* included_stat_client_h */
/*