summaryrefslogtreecommitdiffstats
path: root/common/tlsf_malloc.c
diff options
context:
space:
mode:
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 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 */