diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2011-12-23 00:54:52 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2011-12-23 11:29:10 +0100 |
commit | 5d96cda9449cb6ac80b768856e5ab8255ba9502e (patch) | |
tree | dde8519c5355cb8f84c72b66f0d3f50b7efbea7c | |
parent | 2467c61b3b1860339defc2b120e46c1aa8721aaf (diff) | |
download | barebox-5d96cda9449cb6ac80b768856e5ab8255ba9502e.tar.gz barebox-5d96cda9449cb6ac80b768856e5ab8255ba9502e.tar.xz |
tlsf: implement malloc_stats
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r-- | common/tlsf_malloc.c | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/common/tlsf_malloc.c b/common/tlsf_malloc.c index a6f82ba58d..2fe443bf2b 100644 --- a/common/tlsf_malloc.c +++ b/common/tlsf_malloc.c @@ -71,8 +71,29 @@ void *memalign(size_t alignment, size_t bytes) } EXPORT_SYMBOL(memalign); -#ifdef CONFIG_CMD_MEMINFO +struct malloc_stats { + size_t free; + size_t used; +}; + +static void malloc_walker(void* ptr, size_t size, int used, void *user) +{ + struct malloc_stats *s = user; + + if (used) + s->used += size; + else + s->free += size; +} + void malloc_stats(void) { + struct malloc_stats s; + + s.used = 0; + s.free = 0; + + tlsf_walk_heap(tlsf_mem_pool, malloc_walker, &s); + + printf("used: %10d\nfree: %10d\n", s.used, s.free); } -#endif /* CONFIG_CMD_MEMINFO */ |