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. --- lib/mempool.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'lib/mempool.c') diff --git a/lib/mempool.c b/lib/mempool.c index 0cb06b5..65072f9 100644 --- a/lib/mempool.c +++ b/lib/mempool.c @@ -43,13 +43,15 @@ struct linpool { static void lp_free(resource *); static void lp_dump(resource *); static resource *lp_lookup(resource *, unsigned long); +static size_t lp_memsize(resource *r); static struct resclass lp_class = { "LinPool", sizeof(struct linpool), lp_free, lp_dump, - lp_lookup + lp_lookup, + lp_memsize }; /** @@ -235,6 +237,24 @@ lp_dump(resource *r) m->total_large); } +static size_t +lp_memsize(resource *r) +{ + linpool *m = (linpool *) r; + struct lp_chunk *c; + int cnt = 0; + + for(c=m->first; c; c=c->next) + cnt++; + for(c=m->first_large; c; c=c->next) + cnt++; + + return ALLOC_OVERHEAD + sizeof(struct linpool) + + cnt * (ALLOC_OVERHEAD + sizeof(sizeof(struct lp_chunk))) + + m->total + m->total_large; +} + + static resource * lp_lookup(resource *r, unsigned long a) { -- cgit v1.2.3