From 6a974ff25e7a0ea6ad65c3e1285fd3bd0a25c1de Mon Sep 17 00:00:00 2001 From: Ole Troan Date: Tue, 21 Apr 2020 17:54:41 +0200 Subject: stats: add apis to delete simple/combined counters vlib_free_simple_counter() vlib_free_combined_counter() Frees the name and two dimensional vector from the stats segment. Type: fix Signed-off-by: Ole Troan Change-Id: If1becf7d09520ba41a3d59e2df94958ecfcf6948 (cherry picked from commit a568a19b2956ed8b94b11c2ef041412473dc8442) --- src/vlib/counter.c | 28 ++++++++++++++++++++++++++++ src/vlib/counter.h | 3 +++ src/vlib/stat_weak_inlines.h | 5 +++++ 3 files changed, 36 insertions(+) (limited to 'src/vlib') diff --git a/src/vlib/counter.c b/src/vlib/counter.c index faf106942b7..558bbe0e990 100644 --- a/src/vlib/counter.c +++ b/src/vlib/counter.c @@ -90,6 +90,20 @@ vlib_validate_simple_counter (vlib_simple_counter_main_t * cm, u32 index) 2 /* STAT_DIR_TYPE_COUNTER_VECTOR_SIMPLE */ ); } +void +vlib_free_simple_counter (vlib_simple_counter_main_t * cm) +{ + int i; + + vlib_stats_delete_cm (cm); + + void *oldheap = vlib_stats_push_heap (cm->counters); + for (i = 0; i < vec_len (cm->counters); i++) + vec_free (cm->counters[i]); + vec_free (cm->counters); + clib_mem_set_heap (oldheap); +} + void vlib_validate_combined_counter (vlib_combined_counter_main_t * cm, u32 index) { @@ -105,6 +119,20 @@ vlib_validate_combined_counter (vlib_combined_counter_main_t * cm, u32 index) 3 /*STAT_DIR_TYPE_COUNTER_VECTOR_COMBINED */ ); } +void +vlib_free_combined_counter (vlib_combined_counter_main_t * cm) +{ + int i; + + vlib_stats_delete_cm (cm); + + void *oldheap = vlib_stats_push_heap (cm->counters); + for (i = 0; i < vec_len (cm->counters); i++) + vec_free (cm->counters[i]); + vec_free (cm->counters); + clib_mem_set_heap (oldheap); +} + u32 vlib_combined_counter_n_counters (const vlib_combined_counter_main_t * cm) { diff --git a/src/vlib/counter.h b/src/vlib/counter.h index 092bd00c879..e9978ba25f5 100644 --- a/src/vlib/counter.h +++ b/src/vlib/counter.h @@ -304,6 +304,8 @@ vlib_zero_combined_counter (vlib_combined_counter_main_t * cm, u32 index) void vlib_validate_simple_counter (vlib_simple_counter_main_t * cm, u32 index); +void vlib_free_simple_counter (vlib_simple_counter_main_t * cm); + /** validate a combined counter @param cm - (vlib_combined_counter_main_t *) pointer to the counter collection @@ -312,6 +314,7 @@ void vlib_validate_simple_counter (vlib_simple_counter_main_t * cm, void vlib_validate_combined_counter (vlib_combined_counter_main_t * cm, u32 index); +void vlib_free_combined_counter (vlib_combined_counter_main_t * cm); /** Obtain the number of simple or combined counters allocated. A macro which reduces to to vec_len(cm->maxi), the answer in either diff --git a/src/vlib/stat_weak_inlines.h b/src/vlib/stat_weak_inlines.h index d288a04c477..a1311e864b3 100644 --- a/src/vlib/stat_weak_inlines.h +++ b/src/vlib/stat_weak_inlines.h @@ -57,5 +57,10 @@ void vlib_stat_segment_unlock (void) { } +void vlib_stats_delete_cm (void *) __attribute__ ((weak)); +void +vlib_stats_delete_cm (void *notused) +{ +} #endif -- cgit 1.2.3-korg