summaryrefslogtreecommitdiffstats
path: root/src/vlib/counter.c
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2022-03-14 13:04:38 +0100
committerFlorin Coras <florin.coras@gmail.com>2022-03-14 20:30:06 +0000
commit58fd481d73dce9c276facb42b9a9c3488c25417d (patch)
treef299759229f606fdf83722c6682665e06e286fad /src/vlib/counter.c
parent92991e5c690e8ad55f9cf0fdb81c26c1d1143b7d (diff)
stats: refactor vlib counters
Change-Id: I09d2da73eff42c52ba1373acc99ff28f283a6725 Type: improvement Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src/vlib/counter.c')
-rw-r--r--src/vlib/counter.c93
1 files changed, 44 insertions, 49 deletions
diff --git a/src/vlib/counter.c b/src/vlib/counter.c
index ceaf0132e64..4f375dee938 100644
--- a/src/vlib/counter.c
+++ b/src/vlib/counter.c
@@ -79,63 +79,59 @@ void
vlib_validate_simple_counter (vlib_simple_counter_main_t * cm, u32 index)
{
vlib_thread_main_t *tm = vlib_get_thread_main ();
- int i, resized = 0;
- void *oldheap = vlib_stats_set_heap ();
+ char *name = cm->stat_segment_name ? cm->stat_segment_name : cm->name;
- vec_validate (cm->counters, tm->n_vlib_mains - 1);
- for (i = 0; i < tm->n_vlib_mains; i++)
- if (index >= vec_len (cm->counters[i]))
- {
- if (vec_resize_will_expand (cm->counters[i],
- index - vec_len (cm->counters[i]) +
- 1 /* length_increment */))
- resized++;
+ if (name == 0)
+ {
+ if (cm->counters == 0)
+ cm->stats_entry_index = ~0;
+ vec_validate (cm->counters, tm->n_vlib_mains - 1);
+ for (int i = 0; i < tm->n_vlib_mains; i++)
vec_validate_aligned (cm->counters[i], index, CLIB_CACHE_LINE_BYTES);
- }
+ return;
+ }
- clib_mem_set_heap (oldheap);
- /* Avoid the epoch increase when there was no counter vector resize. */
- if (resized)
- vlib_stats_update_counter (cm, index, STAT_DIR_TYPE_COUNTER_VECTOR_SIMPLE);
+ if (cm->counters == 0)
+ cm->stats_entry_index = vlib_stats_add_counter_vector ("%s", name);
+
+ vlib_stats_validate (cm->stats_entry_index, tm->n_vlib_mains - 1, index);
+ cm->counters = vlib_stats_get_entry_data_pointer (cm->stats_entry_index);
}
void
vlib_free_simple_counter (vlib_simple_counter_main_t * cm)
{
- int i;
-
- vlib_stats_delete_cm (cm);
-
- void *oldheap = vlib_stats_set_heap ();
- for (i = 0; i < vec_len (cm->counters); i++)
- vec_free (cm->counters[i]);
- vec_free (cm->counters);
- clib_mem_set_heap (oldheap);
+ if (cm->stats_entry_index == ~0)
+ {
+ for (int i = 0; i < vec_len (cm->counters); i++)
+ vec_free (cm->counters[i]);
+ vec_free (cm->counters);
+ }
+ else
+ vlib_stats_remove_entry (cm->stats_entry_index);
}
void
vlib_validate_combined_counter (vlib_combined_counter_main_t * cm, u32 index)
{
vlib_thread_main_t *tm = vlib_get_thread_main ();
- int i, resized = 0;
- void *oldheap = vlib_stats_set_heap ();
+ char *name = cm->stat_segment_name ? cm->stat_segment_name : cm->name;
- vec_validate (cm->counters, tm->n_vlib_mains - 1);
- for (i = 0; i < tm->n_vlib_mains; i++)
- if (index >= vec_len (cm->counters[i]))
- {
- if (vec_resize_will_expand (cm->counters[i],
- index - vec_len (cm->counters[i]) +
- 1 /* length_increment */))
- resized++;
+ if (name == 0)
+ {
+ if (cm->counters == 0)
+ cm->stats_entry_index = ~0;
+ vec_validate (cm->counters, tm->n_vlib_mains - 1);
+ for (int i = 0; i < tm->n_vlib_mains; i++)
vec_validate_aligned (cm->counters[i], index, CLIB_CACHE_LINE_BYTES);
- }
+ return;
+ }
- clib_mem_set_heap (oldheap);
- /* Avoid the epoch increase when there was no counter vector resize. */
- if (resized)
- vlib_stats_update_counter (cm, index,
- STAT_DIR_TYPE_COUNTER_VECTOR_COMBINED);
+ if (cm->counters == 0)
+ cm->stats_entry_index = vlib_stats_add_counter_pair_vector ("%s", name);
+
+ vlib_stats_validate (cm->stats_entry_index, tm->n_vlib_mains - 1, index);
+ cm->counters = vlib_stats_get_entry_data_pointer (cm->stats_entry_index);
}
int
@@ -173,15 +169,14 @@ int
void
vlib_free_combined_counter (vlib_combined_counter_main_t * cm)
{
- int i;
-
- vlib_stats_delete_cm (cm);
-
- void *oldheap = vlib_stats_set_heap ();
- for (i = 0; i < vec_len (cm->counters); i++)
- vec_free (cm->counters[i]);
- vec_free (cm->counters);
- clib_mem_set_heap (oldheap);
+ if (cm->stats_entry_index == ~0)
+ {
+ for (int i = 0; i < vec_len (cm->counters); i++)
+ vec_free (cm->counters[i]);
+ vec_free (cm->counters);
+ }
+ else
+ vlib_stats_remove_entry (cm->stats_entry_index);
}
u32