summaryrefslogtreecommitdiffstats
path: root/common/tlsf_malloc.c
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2011-12-23 00:54:52 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2011-12-23 11:29:10 +0100
commit5d96cda9449cb6ac80b768856e5ab8255ba9502e (patch)
treedde8519c5355cb8f84c72b66f0d3f50b7efbea7c /common/tlsf_malloc.c
parent2467c61b3b1860339defc2b120e46c1aa8721aaf (diff)
downloadbarebox-5d96cda9449cb6ac80b768856e5ab8255ba9502e.tar.gz
tlsf: implement malloc_stats
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common/tlsf_malloc.c')
-rw-r--r--common/tlsf_malloc.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/common/tlsf_malloc.c b/common/tlsf_malloc.c
index a6f82ba..2fe443b 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 */