diff options
author | Ole Troan <ot@cisco.com> | 2019-02-26 16:37:03 +0100 |
---|---|---|
committer | Neale Ranns <nranns@cisco.com> | 2019-02-28 13:25:22 +0000 |
commit | 703908aaf4f80ef6bc78166d46eba3a3b3aa15f7 (patch) | |
tree | 35bf3939113a8e0db85ec41671cdbbdb4f96d687 | |
parent | 8b409635b44fd599eea37c7f259be294141a38bb (diff) |
stats: Add interface name to sw_if_index as /if/names
Expose interface name to sw_if_index table as a directory node in the stats segment.
Change-Id: Ie50e4af01997d141880f02e3a8496bfeb91b9944
Signed-off-by: Ole Troan <ot@cisco.com>
-rw-r--r-- | extras/vom/vom/stat_client.cpp | 2 | ||||
-rw-r--r-- | extras/vom/vom/stat_reader.cpp | 1 | ||||
-rw-r--r-- | src/vpp-api/client/stat_client.c | 23 | ||||
-rw-r--r-- | src/vpp-api/client/stat_client.h | 2 | ||||
-rw-r--r-- | src/vpp/app/vpp_get_stats.c | 9 | ||||
-rw-r--r-- | src/vpp/stats/stat_segment.c | 60 | ||||
-rw-r--r-- | src/vpp/stats/stat_segment.h | 22 |
7 files changed, 108 insertions, 11 deletions
diff --git a/extras/vom/vom/stat_client.cpp b/extras/vom/vom/stat_client.cpp index b2d429929af..a413d6763f0 100644 --- a/extras/vom/vom/stat_client.cpp +++ b/extras/vom/vom/stat_client.cpp @@ -34,6 +34,8 @@ stat_client::stat_data_t::stat_data_t(const stat_segment_data_t& stat_seg_data) case STAT_DIR_TYPE_ERROR_INDEX: m_error_value = stat_seg_data.error_value; break; + case STAT_DIR_TYPE_NAME_VECTOR: + break; case STAT_DIR_TYPE_ILLEGAL: break; } diff --git a/extras/vom/vom/stat_reader.cpp b/extras/vom/vom/stat_reader.cpp index 1851f742247..0edbc704a08 100644 --- a/extras/vom/vom/stat_reader.cpp +++ b/extras/vom/vom/stat_reader.cpp @@ -78,6 +78,7 @@ stat_reader::read() switch (sde.type()) { case STAT_DIR_TYPE_ERROR_INDEX: case STAT_DIR_TYPE_SCALAR_INDEX: + case STAT_DIR_TYPE_NAME_VECTOR: case STAT_DIR_TYPE_ILLEGAL: break; diff --git a/src/vpp-api/client/stat_client.c b/src/vpp-api/client/stat_client.c index 2cf53d5d0af..25a37f76da8 100644 --- a/src/vpp-api/client/stat_client.c +++ b/src/vpp-api/client/stat_client.c @@ -252,8 +252,29 @@ copy_data (stat_segment_directory_entry_t * ep, stat_client_main_t * sm) result.error_value = error_base[ep->index]; break; + case STAT_DIR_TYPE_NAME_VECTOR: + if (ep->offset == 0) + return result; + uint8_t **name_vector = + stat_segment_pointer (sm->shared_header, ep->offset); + result.name_vector = vec_dup (name_vector); + offset_vector = + stat_segment_pointer (sm->shared_header, ep->offset_vector); + for (i = 0; i < vec_len (name_vector); i++) + { + if (offset_vector[i]) + { + u8 *name = + stat_segment_pointer (sm->shared_header, offset_vector[i]); + result.name_vector[i] = vec_dup (name); + } + else + result.name_vector[i] = 0; + } + break; + default: - fprintf (stderr, "Unknown type: %d", ep->type); + fprintf (stderr, "Unknown type: %d\n", ep->type); } return result; } diff --git a/src/vpp-api/client/stat_client.h b/src/vpp-api/client/stat_client.h index 89f6fe53ea4..23087abe749 100644 --- a/src/vpp-api/client/stat_client.h +++ b/src/vpp-api/client/stat_client.h @@ -28,6 +28,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; /* Default socket to exchange segment fd */ @@ -45,6 +46,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; diff --git a/src/vpp/app/vpp_get_stats.c b/src/vpp/app/vpp_get_stats.c index 1c1298e2afd..1d878029dda 100644 --- a/src/vpp/app/vpp_get_stats.c +++ b/src/vpp/app/vpp_get_stats.c @@ -220,6 +220,15 @@ reconnect: fformat (stdout, "%.2f %s\n", res[i].scalar_value, res[i].name); break; + case STAT_DIR_TYPE_NAME_VECTOR: + if (res[i].name_vector == 0) + continue; + for (k = 0; k < vec_len (res[i].name_vector); k++) + if (res[i].name_vector[k]) + fformat (stdout, "[%d]: %s %s\n", k, res[i].name_vector[k], + res[i].name); + break; + default: ; } diff --git a/src/vpp/stats/stat_segment.c b/src/vpp/stats/stat_segment.c index ca78a103522..aa32aede3a5 100644 --- a/src/vpp/stats/stat_segment.c +++ b/src/vpp/stats/stat_segment.c @@ -268,7 +268,7 @@ vlib_map_stat_segment_init (void) /* Scalar stats and node counters */ vec_validate (sm->directory_vector, STAT_COUNTERS - 1); #define _(E,t,n,p) \ - strcpy(sm->directory_vector[STAT_COUNTER_##E].name, "/sys" #p "/" #n); \ + strcpy(sm->directory_vector[STAT_COUNTER_##E].name, #p "/" #n); \ sm->directory_vector[STAT_COUNTER_##E].type = STAT_DIR_TYPE_##t; foreach_stat_segment_counter_name #undef _ @@ -686,8 +686,66 @@ statseg_config (vlib_main_t * vm, unformat_input_t * input) return 0; } +static clib_error_t * +statseg_sw_interface_add_del (vnet_main_t * vnm, u32 sw_if_index, u32 is_add) +{ + stat_segment_main_t *sm = &stat_segment_main; + stat_segment_shared_header_t *shared_header = sm->shared_header; + + void *oldheap = vlib_stats_push_heap (); + vlib_stat_segment_lock (); + + vec_validate (sm->interfaces, sw_if_index); + if (is_add) + { + vnet_sw_interface_t *si = vnet_get_sw_interface (vnm, sw_if_index); + vnet_sw_interface_t *si_sup = + vnet_get_sup_sw_interface (vnm, si->sw_if_index); + vnet_hw_interface_t *hi_sup; + + ASSERT (si_sup->type == VNET_SW_INTERFACE_TYPE_HARDWARE); + hi_sup = vnet_get_hw_interface (vnm, si_sup->hw_if_index); + + u8 *s = 0; + s = format (s, "%v", hi_sup->name); + if (si->type != VNET_SW_INTERFACE_TYPE_HARDWARE) + s = format (s, ".%d", si->sub.id); + s = format (s, "%c", 0); + sm->interfaces[sw_if_index] = s; + } + else + { + vec_free (sm->interfaces[sw_if_index]); + sm->interfaces[sw_if_index] = 0; + } + + stat_segment_directory_entry_t *ep; + ep = &sm->directory_vector[STAT_COUNTER_INTERFACE_NAMES]; + ep->offset = stat_segment_offset (shared_header, sm->interfaces); + + int i; + u64 *offset_vector = + ep->offset_vector ? stat_segment_pointer (shared_header, + ep->offset_vector) : 0; + + vec_validate (offset_vector, vec_len (sm->interfaces) - 1); + for (i = 0; i < vec_len (sm->interfaces); i++) + { + offset_vector[i] = + sm->interfaces[i] ? stat_segment_offset (shared_header, + sm->interfaces[i]) : 0; + } + ep->offset_vector = stat_segment_offset (shared_header, offset_vector); + + vlib_stat_segment_unlock (); + clib_mem_set_heap (oldheap); + + return 0; +} + VLIB_INIT_FUNCTION (statseg_init); VLIB_EARLY_CONFIG_FUNCTION (statseg_config, "statseg"); +VNET_SW_INTERFACE_ADD_DEL_FUNCTION (statseg_sw_interface_add_del); /* *INDENT-OFF* */ VLIB_REGISTER_NODE (stat_segment_collector, static) = diff --git a/src/vpp/stats/stat_segment.h b/src/vpp/stats/stat_segment.h index fb450f38f53..917b512aecb 100644 --- a/src/vpp/stats/stat_segment.h +++ b/src/vpp/stats/stat_segment.h @@ -32,19 +32,21 @@ typedef enum STAT_COUNTER_NODE_VECTORS, STAT_COUNTER_NODE_CALLS, STAT_COUNTER_NODE_SUSPENDS, + STAT_COUNTER_INTERFACE_NAMES, STAT_COUNTERS } stat_segment_counter_t; #define foreach_stat_segment_counter_name \ - _(VECTOR_RATE, SCALAR_INDEX, vector_rate,) \ - _(INPUT_RATE, SCALAR_INDEX, input_rate,) \ - _(LAST_UPDATE, SCALAR_INDEX, last_update,) \ - _(LAST_STATS_CLEAR, SCALAR_INDEX, last_stats_clear,) \ - _(HEARTBEAT, SCALAR_INDEX, heartbeat,) \ - _(NODE_CLOCKS, COUNTER_VECTOR_SIMPLE, clocks, /node) \ - _(NODE_VECTORS, COUNTER_VECTOR_SIMPLE, vectors, /node) \ - _(NODE_CALLS, COUNTER_VECTOR_SIMPLE, calls, /node) \ - _(NODE_SUSPENDS, COUNTER_VECTOR_SIMPLE, suspends, /node) + _(VECTOR_RATE, SCALAR_INDEX, vector_rate, /sys) \ + _(INPUT_RATE, SCALAR_INDEX, input_rate, /sys) \ + _(LAST_UPDATE, SCALAR_INDEX, last_update, /sys) \ + _(LAST_STATS_CLEAR, SCALAR_INDEX, last_stats_clear, /sys) \ + _(HEARTBEAT, SCALAR_INDEX, heartbeat, /sys) \ + _(NODE_CLOCKS, COUNTER_VECTOR_SIMPLE, clocks, /sys/node) \ + _(NODE_VECTORS, COUNTER_VECTOR_SIMPLE, vectors, /sys/node) \ + _(NODE_CALLS, COUNTER_VECTOR_SIMPLE, calls, /sys/node) \ + _(NODE_SUSPENDS, COUNTER_VECTOR_SIMPLE, suspends, /sys/node) \ + _(INTERFACE_NAMES, NAME_VECTOR, names, /if) typedef struct { @@ -101,6 +103,8 @@ typedef struct /* statistics segment */ uword *directory_vector_by_name; stat_segment_directory_entry_t *directory_vector; + u8 **interfaces; + clib_spinlock_t *stat_segment_lockp; clib_socket_t *socket; u8 *socket_name; |