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);
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];
static void
do_stat_segment_updates (stat_segment_main_t * sm)
{
+ stat_segment_shared_header_t *shared_header = sm->shared_header;
vlib_main_t *vm = vlib_mains[0];
f64 vector_rate;
u64 input_packets, last_input_packets;
f64 dt, now;
vlib_main_t *this_vlib_main;
int i, start;
+ counter_t **counters;
+ static int num_worker_threads_set;
/*
- * Compute the average vector rate across all workers
+ * Set once at the beginning of time.
+ * Can't do this from the init routine, which happens before
+ * start_workers sets up vlib_mains...
+ */
+ if (PREDICT_FALSE (num_worker_threads_set == 0))
+ {
+ sm->directory_vector[STAT_COUNTER_NUM_WORKER_THREADS].value =
+ vec_len (vlib_mains) > 1 ? vec_len (vlib_mains) - 1 : 1;
+
+ stat_validate_counter_vector (&sm->directory_vector
+ [STAT_COUNTER_VECTOR_RATE_PER_WORKER],
+ vec_len (vlib_mains));
+ num_worker_threads_set = 1;
+ }
+
+ /*
+ * Compute per-worker vector rates, and the average vector rate
+ * across all workers
*/
vector_rate = 0.0;
+ counters =
+ stat_segment_pointer (shared_header,
+ sm->directory_vector
+ [STAT_COUNTER_VECTOR_RATE_PER_WORKER].offset);
+
start = vec_len (vlib_mains) > 1 ? 1 : 0;
for (i = start; i < vec_len (vlib_mains); i++)
{
+
+ f64 this_vector_rate;
+
this_vlib_main = vlib_mains[i];
- vector_rate += vlib_last_vector_length_per_node (this_vlib_main);
+
+ this_vector_rate = vlib_last_vector_length_per_node (this_vlib_main);
+ vector_rate += this_vector_rate;
+
+ /* Set the per-worker rate */
+ counters[i - start][0] = this_vector_rate;
}
+
+ /* And set the system average rate */
vector_rate /= (f64) (i - start);
- sm->directory_vector[STAT_COUNTER_VECTOR_RATE].value =
- vector_rate / ((f64) (vec_len (vlib_mains) - start));
+ sm->directory_vector[STAT_COUNTER_VECTOR_RATE].value = vector_rate;
/*
* Compute the aggregate input rate
statseg_init (vlib_main_t * vm)
{
stat_segment_main_t *sm = &stat_segment_main;
- clib_error_t *error;
-
- /* dependent on unix_input_init */
- if ((error = vlib_call_init_function (vm, unix_input_init)))
- return error;
if (sm->socket_name)
stats_segment_socket_init ();
return 0;
}
+/* *INDENT-OFF* */
+VLIB_INIT_FUNCTION (statseg_init) =
+{
+ .runs_after = VLIB_INITS("unix_input_init"),
+};
+/* *INDENT-ON* */
+
+
clib_error_t *
stat_segment_register_gauge (u8 * name, stat_segment_update_fn update_fn,
u32 caller_index)
/* set default socket file name when statseg config stanza is empty. */
sm->socket_name = format (0, "%s", STAT_SEGMENT_SOCKET_FILE);
+ /*
+ * NULL-terminate socket name string
+ * clib_socket_init()->socket_config() use C str*
+ */
+ vec_add1 (sm->socket_name, 0);
while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
{
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);