summaryrefslogtreecommitdiffstats
path: root/src/vlib/buffer.c
diff options
context:
space:
mode:
authorBenoît Ganne <bganne@cisco.com>2021-03-09 15:37:49 +0100
committerDamjan Marion <dmarion@me.com>2021-08-27 10:05:31 +0000
commite09a2337b82d2dcb5b7379a9581477af291d1a75 (patch)
tree619da9a205808a35efbd9d2c21bdc010a447e2d9 /src/vlib/buffer.c
parenta13100f3aa21a39de991df9fff84cd91e4be3b80 (diff)
bufmon: add buffer monitoring plugin
This plugin allow to keep track of buffer usage in VPP graph nodes. The main use is to detect buffer leakages. Type: feature Change-Id: Iadcf4ab98207fab6e2fa375060879bc2a25b711e Signed-off-by: Benoît Ganne <bganne@cisco.com>
Diffstat (limited to 'src/vlib/buffer.c')
-rw-r--r--src/vlib/buffer.c34
1 files changed, 27 insertions, 7 deletions
diff --git a/src/vlib/buffer.c b/src/vlib/buffer.c
index adaafa36f5d..71f84d377af 100644
--- a/src/vlib/buffer.c
+++ b/src/vlib/buffer.c
@@ -615,20 +615,26 @@ format_vlib_buffer_pool (u8 * s, va_list * va)
return s;
}
-static clib_error_t *
-show_buffers (vlib_main_t * vm,
- unformat_input_t * input, vlib_cli_command_t * cmd)
+u8 *
+format_vlib_buffer_pool_all (u8 *s, va_list *va)
{
+ vlib_main_t *vm = va_arg (*va, vlib_main_t *);
vlib_buffer_main_t *bm = vm->buffer_main;
vlib_buffer_pool_t *bp;
- vlib_cli_output (vm, "%U", format_vlib_buffer_pool, vm, 0);
+ s = format (s, "%U", format_vlib_buffer_pool, vm, 0);
- /* *INDENT-OFF* */
vec_foreach (bp, bm->buffer_pools)
- vlib_cli_output (vm, "%U", format_vlib_buffer_pool, vm, bp);
- /* *INDENT-ON* */
+ s = format (s, "\n%U", format_vlib_buffer_pool, vm, bp);
+
+ return s;
+}
+static clib_error_t *
+show_buffers (vlib_main_t *vm, unformat_input_t *input,
+ vlib_cli_command_t *cmd)
+{
+ vlib_cli_output (vm, "%U", format_vlib_buffer_pool_all, vm);
return 0;
}
@@ -971,6 +977,20 @@ vlib_buffer_alloc_may_fail (vlib_main_t * vm, u32 n_buffers)
}
#endif
+__clib_export int
+vlib_buffer_set_alloc_free_callback (
+ vlib_main_t *vm, vlib_buffer_alloc_free_callback_t *alloc_callback_fn,
+ vlib_buffer_alloc_free_callback_t *free_callback_fn)
+{
+ vlib_buffer_main_t *bm = vm->buffer_main;
+ if ((alloc_callback_fn && bm->alloc_callback_fn) ||
+ (free_callback_fn && bm->free_callback_fn))
+ return 1;
+ bm->alloc_callback_fn = alloc_callback_fn;
+ bm->free_callback_fn = free_callback_fn;
+ return 0;
+}
+
/** @endcond */
/*
* fd.io coding-style-patch-verification: ON