aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/vpp/stats/stat_segment.c38
-rw-r--r--src/vpp/stats/stat_segment.h7
-rw-r--r--src/vpp/stats/stat_segment_provider.c6
3 files changed, 32 insertions, 19 deletions
diff --git a/src/vpp/stats/stat_segment.c b/src/vpp/stats/stat_segment.c
index 1ca9f5bab0d..cebd5e32afa 100644
--- a/src/vpp/stats/stat_segment.c
+++ b/src/vpp/stats/stat_segment.c
@@ -780,9 +780,10 @@ do_stat_segment_updates (vlib_main_t *vm, stat_segment_main_t *sm)
/* *INDENT-OFF* */
stat_segment_gauges_pool_t *g;
pool_foreach (g, sm->gauges)
- {
- g->fn(&sm->directory_vector[g->directory_index], g->caller_index);
- }
+ {
+ if (g->enabled)
+ g->fn (&sm->directory_vector[g->directory_index], g->caller_index);
+ }
/* *INDENT-ON* */
/* Heartbeat, so clients detect we're still here */
@@ -880,9 +881,9 @@ stat_segment_collector_process (vlib_main_t * vm, vlib_node_runtime_t * rt,
* Add a data provider (via callback) for a given stats entry.
* TODO: Add support for per-provider interval.
*/
-void
+uword
stat_segment_poll_add (u32 vector_index, stat_segment_update_fn update_fn,
- u32 caller_index, u32 interval)
+ u32 caller_index, u32 interval, u8 enabled)
{
stat_segment_main_t *sm = &stat_segment_main;
stat_segment_gauges_pool_t *gauge;
@@ -891,8 +892,23 @@ stat_segment_poll_add (u32 vector_index, stat_segment_update_fn update_fn,
gauge->fn = update_fn;
gauge->caller_index = caller_index;
gauge->directory_index = vector_index;
+ gauge->enabled = enabled;
+
+ return pool_elts (sm->gauges) - 1;
+}
+
+/*
+ * Enable (or disable) a callback for a stats entry
+ */
+void
+stat_segment_poll_state (uword index, u8 enabled)
+{
+ stat_segment_main_t *sm = &stat_segment_main;
+ stat_segment_gauges_pool_t *gauge = pool_elt_at_index (sm->gauges, index);
+
+ ASSERT (gauge);
- return;
+ gauge->enabled = enabled;
}
/*
@@ -900,20 +916,14 @@ stat_segment_poll_add (u32 vector_index, stat_segment_update_fn update_fn,
* Deprecated, replace with stat_segment_new_entry + stat_segment_pool_add
*/
clib_error_t *
-stat_segment_register_gauge (u8 * name, stat_segment_update_fn update_fn,
+stat_segment_register_gauge (u8 *name, stat_segment_update_fn update_fn,
u32 caller_index)
{
- stat_segment_main_t *sm = &stat_segment_main;
- stat_segment_gauges_pool_t *gauge;
-
u32 vector_index = stat_segment_new_entry (name, STAT_DIR_TYPE_SCALAR_INDEX);
if (vector_index == ~0) /* Already registered */
return clib_error_return (0, "%v is already registered", name);
- pool_get (sm->gauges, gauge);
- gauge->fn = update_fn;
- gauge->caller_index = caller_index;
- gauge->directory_index = vector_index;
+ stat_segment_poll_add (vector_index, update_fn, caller_index, -1, true);
return NULL;
}
diff --git a/src/vpp/stats/stat_segment.h b/src/vpp/stats/stat_segment.h
index 2858003bb73..42c30071c28 100644
--- a/src/vpp/stats/stat_segment.h
+++ b/src/vpp/stats/stat_segment.h
@@ -68,6 +68,7 @@ typedef struct {
u32 directory_index;
stat_segment_update_fn fn;
u32 caller_index;
+ u8 enabled;
} stat_segment_gauges_pool_t;
typedef struct
@@ -108,8 +109,10 @@ stat_segment_register_state_counter(u8 *name, u32 *index);
clib_error_t *
stat_segment_deregister_state_counter(u32 index);
void stat_segment_set_state_counter (u32 index, u64 value);
-void stat_segment_poll_add (u32 vector_index, stat_segment_update_fn update_fn,
- u32 caller_index, u32 interval);
+uword stat_segment_poll_add (u32 vector_index,
+ stat_segment_update_fn update_fn,
+ u32 caller_index, u32 interval, u8 enabled);
+void stat_segment_poll_state (uword index, u8 enabled);
counter_t **stat_validate_counter_vector3 (counter_t **counters, u32 max1,
u32 max2);
diff --git a/src/vpp/stats/stat_segment_provider.c b/src/vpp/stats/stat_segment_provider.c
index 30e03be45b9..f62a74fcab3 100644
--- a/src/vpp/stats/stat_segment_provider.c
+++ b/src/vpp/stats/stat_segment_provider.c
@@ -117,7 +117,7 @@ vlib_stats_register_mem_heap (clib_mem_heap_t *heap)
vec_free (s_free);
stat_segment_poll_add (mem_vector_index, stat_provider_mem_usage_update_fn,
- heap_index, 10);
+ heap_index, 10, true);
}
static void
@@ -180,7 +180,7 @@ stat_provider_register_vector_rate (u32 num_workers)
if (i == ~0)
ASSERT (0);
vec_free (s);
- stat_segment_poll_add (i, stat_provider_vector_rate_update_fn, ~0, 10);
+ stat_segment_poll_add (i, stat_provider_vector_rate_update_fn, ~0, 10, true);
s = format (0, "/sys/vector_rate_per_worker%c", 0);
i = stat_segment_new_entry (s, STAT_DIR_TYPE_COUNTER_VECTOR_SIMPLE);
@@ -188,7 +188,7 @@ stat_provider_register_vector_rate (u32 num_workers)
ASSERT (0);
vec_free (s);
stat_segment_poll_add (i, stat_provider_vector_rate_per_thread_update_fn, ~0,
- 10);
+ 10, true);
stat_segment_main_t *sm = &stat_segment_main;
vlib_stat_segment_lock ();