diff options
author | Ondrej Zajicek <santiago@crfreenet.org> | 2010-06-02 22:20:40 +0200 |
---|---|---|
committer | Ondrej Zajicek <santiago@crfreenet.org> | 2010-06-02 22:20:40 +0200 |
commit | acb60628f53ba1fc29d1a554683acdb03f961c6f (patch) | |
tree | be767e6d7995dee6708b7530b7dabe74d23b491e /lib/resource.c | |
parent | 4461b8979143bd13024663622c419646a1db0c85 (diff) |
Implements command that shows memory usage.
Diffstat (limited to 'lib/resource.c')
-rw-r--r-- | lib/resource.c | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/lib/resource.c b/lib/resource.c index 5ba23f18..24164ec2 100644 --- a/lib/resource.c +++ b/lib/resource.c @@ -37,13 +37,15 @@ struct pool { static void pool_dump(resource *); static void pool_free(resource *); static resource *pool_lookup(resource *, unsigned long); +static size_t pool_memsize(resource *P); static struct resclass pool_class = { "Pool", sizeof(pool), pool_free, pool_dump, - pool_lookup + pool_lookup, + pool_memsize }; pool root_pool; @@ -95,6 +97,19 @@ pool_dump(resource *P) indent -= 3; } +static size_t +pool_memsize(resource *P) +{ + pool *p = (pool *) P; + resource *r; + size_t sum = sizeof(pool) + ALLOC_OVERHEAD; + + WALK_LIST(r, p->inside) + sum += rmemsize(r); + + return sum; +} + static resource * pool_lookup(resource *P, unsigned long a) { @@ -177,6 +192,17 @@ rdump(void *res) debug("NULL\n"); } +size_t +rmemsize(void *res) +{ + resource *r = res; + if (!r) + return 0; + if (!r->class->memsize) + return r->class->size + ALLOC_OVERHEAD; + return r->class->memsize(r); +} + /** * ralloc - create a resource * @p: pool to create the resource in @@ -277,12 +303,20 @@ mbl_lookup(resource *r, unsigned long a) return NULL; } +static size_t +mbl_memsize(resource *r) +{ + struct mblock *m = (struct mblock *) r; + return ALLOC_OVERHEAD + sizeof(struct mblock) + m->size; +} + static struct resclass mb_class = { "Memory", 0, mbl_free, mbl_debug, - mbl_lookup + mbl_lookup, + mbl_memsize }; /** |