From acb60628f53ba1fc29d1a554683acdb03f961c6f Mon Sep 17 00:00:00 2001 From: Ondrej Zajicek Date: Wed, 2 Jun 2010 22:20:40 +0200 Subject: Implements command that shows memory usage. --- nest/cmds.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'nest/cmds.c') diff --git a/nest/cmds.c b/nest/cmds.c index 16fbba61..8ac32096 100644 --- a/nest/cmds.c +++ b/nest/cmds.c @@ -11,6 +11,7 @@ #include "conf/conf.h" #include "nest/cmds.h" #include "lib/string.h" +#include "lib/resource.h" void cmd_show_status(void) @@ -47,3 +48,32 @@ cmd_show_symbols(struct symbol *sym) cli_msg(0, ""); } } + +static void +print_size(char *dsc, size_t val) +{ + char *px = " kMG"; + int i = 0; + while ((val >= 10000) && (i < 3)) + { + val = (val + 512) / 1024; + i++; + } + + cli_msg(-1018, "%-17s %4u %cB", dsc, (unsigned) val, px[i]); +} + +extern pool *rt_table_pool; +extern pool *rta_pool; +extern pool *proto_pool; + +void +cmd_show_memory(void) +{ + cli_msg(-1018, "BIRD memory usage"); + print_size("Routing tables:", rmemsize(rt_table_pool)); + print_size("Route attributes:", rmemsize(rta_pool)); + print_size("Protocols:", rmemsize(proto_pool)); + print_size("Total:", rmemsize(&root_pool)); + cli_msg(0, ""); +} -- cgit v1.2.3