aboutsummaryrefslogtreecommitdiffstats
path: root/src/vlib
diff options
context:
space:
mode:
authorOle Troan <ot@cisco.com>2019-02-26 13:10:56 +0100
committerDamjan Marion <dmarion@me.com>2019-02-26 20:17:30 +0000
commit849cbe225ea9c0358e3f2789c89d4b84d0f7b367 (patch)
tree6cd69a8271367ee08a3e03eb7297c87975aac5cf /src/vlib
parentca80dccb1e91bf83a133bd91d9ff1693840e95c6 (diff)
stats: buffer gauge callbacks use index instead of name.
Change-Id: I500b8e72d7e021b9564dad0ffc087cb0e1ceb96f Signed-off-by: Ole Troan <ot@cisco.com>
Diffstat (limited to 'src/vlib')
-rw-r--r--src/vlib/buffer.c46
1 files changed, 20 insertions, 26 deletions
diff --git a/src/vlib/buffer.c b/src/vlib/buffer.c
index 091799b3f12..7581d9cdd48 100644
--- a/src/vlib/buffer.c
+++ b/src/vlib/buffer.c
@@ -725,26 +725,22 @@ buffer_get_cached (vlib_buffer_pool_t * bp)
}
static vlib_buffer_pool_t *
-buffer_get_by_name (vlib_buffer_main_t * bm, char *name)
+buffer_get_by_index (vlib_buffer_main_t * bm, u32 index)
{
vlib_buffer_pool_t *bp;
- vec_foreach (bp, bm->buffer_pools)
- {
- if (!strcmp ((char *) bp->name, name))
- return bp;
- }
-
- return 0;
+ if (!bm->buffer_pools || vec_len (bm->buffer_pools) < index)
+ return 0;
+ bp = vec_elt_at_index (bm->buffer_pools, index);
+ if (!bp)
+ return 0;
+ return bp;
}
static void
-buffer_gauges_update_used_fn (stat_segment_directory_entry_t * e)
+buffer_gauges_update_used_fn (stat_segment_directory_entry_t * e, u32 index)
{
vlib_main_t *vm = vlib_get_main ();
- vlib_buffer_pool_t *bp;
-
- bp = buffer_get_by_name (vm->buffer_main,
- &e->name[sizeof ("/buffer/used/") - 1]);
+ vlib_buffer_pool_t *bp = buffer_get_by_index (vm->buffer_main, index);
if (!bp)
return;
@@ -752,13 +748,11 @@ buffer_gauges_update_used_fn (stat_segment_directory_entry_t * e)
}
static void
-buffer_gauges_update_available_fn (stat_segment_directory_entry_t * e)
+buffer_gauges_update_available_fn (stat_segment_directory_entry_t * e,
+ u32 index)
{
vlib_main_t *vm = vlib_get_main ();
- vlib_buffer_pool_t *bp;
-
- bp = buffer_get_by_name (vm->buffer_main,
- &e->name[sizeof ("/buffer/available/") - 1]);
+ vlib_buffer_pool_t *bp = buffer_get_by_index (vm->buffer_main, index);
if (!bp)
return;
@@ -766,13 +760,10 @@ buffer_gauges_update_available_fn (stat_segment_directory_entry_t * e)
}
static void
-buffer_gauges_update_cached_fn (stat_segment_directory_entry_t * e)
+buffer_gauges_update_cached_fn (stat_segment_directory_entry_t * e, u32 index)
{
vlib_main_t *vm = vlib_get_main ();
- vlib_buffer_pool_t *bp;
-
- bp = buffer_get_by_name (vm->buffer_main,
- &e->name[sizeof ("/buffer/cached/") - 1]);
+ vlib_buffer_pool_t *bp = buffer_get_by_index (vm->buffer_main, index);
if (!bp)
return;
@@ -818,13 +809,16 @@ vlib_buffer_main_init (struct vlib_main_t * vm)
vec_foreach (bp, bm->buffer_pools)
{
name = format (0, "/buffer/cached/%s%c", bp->name, 0);
- stat_segment_register_gauge (name, buffer_gauges_update_cached_fn);
+ stat_segment_register_gauge (name, buffer_gauges_update_cached_fn,
+ bp - bm->buffer_pools);
vec_free (name);
name = format (0, "/buffer/used/%s%c", bp->name, 0);
- stat_segment_register_gauge (name, buffer_gauges_update_used_fn);
+ stat_segment_register_gauge (name, buffer_gauges_update_used_fn,
+ bp - bm->buffer_pools);
vec_free (name);
name = format (0, "/buffer/available/%s%c", bp->name, 0);
- stat_segment_register_gauge (name, buffer_gauges_update_available_fn);
+ stat_segment_register_gauge (name, buffer_gauges_update_available_fn,
+ bp - bm->buffer_pools);
vec_free (name);
}