*/
#include <vlib/vlib.h>
+#include <vlib/stat_weak_inlines.h>
void
vlib_clear_simple_counters (vlib_simple_counter_main_t * cm)
}
}
-void *vlib_stats_push_heap (void) __attribute__ ((weak));
-void *
-vlib_stats_push_heap (void)
-{
- return 0;
-};
-
-void vlib_stats_pop_heap (void *, void *, int) __attribute__ ((weak));
-void
-vlib_stats_pop_heap (void *notused, void *notused2, int type)
-{
-};
-
void
vlib_validate_simple_counter (vlib_simple_counter_main_t * cm, u32 index)
{
vlib_thread_main_t *tm = vlib_get_thread_main ();
int i;
- void *oldheap = vlib_stats_push_heap ();
+ void *oldheap = vlib_stats_push_heap (cm->counters);
vec_validate (cm->counters, tm->n_vlib_mains - 1);
for (i = 0; i < tm->n_vlib_mains; i++)
vec_validate_aligned (cm->counters[i], index, CLIB_CACHE_LINE_BYTES);
- vlib_stats_pop_heap (cm, oldheap,
- 3 /* STAT_DIR_TYPE_COUNTER_VECTOR_SIMPLE */ );
+ vlib_stats_pop_heap (cm, oldheap, 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_thread_main_t *tm = vlib_get_thread_main ();
int i;
- void *oldheap = vlib_stats_push_heap ();
+ void *oldheap = vlib_stats_push_heap (cm->counters);
vec_validate (cm->counters, tm->n_vlib_mains - 1);
for (i = 0; i < tm->n_vlib_mains; i++)
vec_validate_aligned (cm->counters[i], index, CLIB_CACHE_LINE_BYTES);
- vlib_stats_pop_heap (cm, oldheap,
- 4 /*STAT_DIR_TYPE_COUNTER_VECTOR_COMBINED */ );
+ vlib_stats_pop_heap (cm, oldheap, index,
+ 3 /*STAT_DIR_TYPE_COUNTER_VECTOR_COMBINED */ );
}
-u32
-vlib_combined_counter_n_counters (const vlib_combined_counter_main_t * cm)
+int
+ vlib_validate_combined_counter_will_expand
+ (vlib_combined_counter_main_t * cm, u32 index)
{
- ASSERT (cm->counters);
- return (vec_len (cm->counters[0]));
-}
+ vlib_thread_main_t *tm = vlib_get_thread_main ();
+ int i;
+ void *oldheap = vlib_stats_push_heap (cm->counters);
-u32
-vlib_simple_counter_n_counters (const vlib_simple_counter_main_t * cm)
-{
- ASSERT (cm->counters);
- return (vec_len (cm->counters[0]));
-}
+ /* Possibly once in recorded history */
+ if (PREDICT_FALSE (vec_len (cm->counters) == 0))
+ {
+ vlib_stats_pop_heap (cm, oldheap, index,
+ 3 /*STAT_DIR_TYPE_COUNTER_VECTOR_COMBINED */ );
+ return 1;
+ }
-void
-serialize_vlib_simple_counter_main (serialize_main_t * m, va_list * va)
-{
- clib_warning ("unimplemented");
+ for (i = 0; i < tm->n_vlib_mains; i++)
+ {
+ /* Trivially OK, and proves that index >= vec_len(...) */
+ if (index < vec_len (cm->counters[i]))
+ continue;
+ if (_vec_resize_will_expand
+ (cm->counters[i],
+ index - vec_len (cm->counters[i]) /* length_increment */ ,
+ sizeof (cm->counters[i]) /* data_bytes */ ,
+ 0 /* header_bytes */ ,
+ CLIB_CACHE_LINE_BYTES /* data_alignment */ ))
+ {
+ vlib_stats_pop_heap (cm, oldheap, index,
+ 3 /*STAT_DIR_TYPE_COUNTER_VECTOR_COMBINED */ );
+ return 1;
+ }
+ }
+ vlib_stats_pop_heap (cm, oldheap, index,
+ 3 /*STAT_DIR_TYPE_COUNTER_VECTOR_COMBINED */ );
+ return 0;
}
void
-unserialize_vlib_simple_counter_main (serialize_main_t * m, va_list * va)
+vlib_free_combined_counter (vlib_combined_counter_main_t * cm)
{
- clib_warning ("unimplemented");
+ 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
-serialize_vlib_combined_counter_main (serialize_main_t * m, va_list * va)
+u32
+vlib_combined_counter_n_counters (const vlib_combined_counter_main_t * cm)
{
- clib_warning ("unimplemented");
+ ASSERT (cm->counters);
+ return (vec_len (cm->counters[0]));
}
-void
-unserialize_vlib_combined_counter_main (serialize_main_t * m, va_list * va)
+u32
+vlib_simple_counter_n_counters (const vlib_simple_counter_main_t * cm)
{
- clib_warning ("unimplemented");
+ ASSERT (cm->counters);
+ return (vec_len (cm->counters[0]));
}
/*