mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 2/3] tlsf: implement malloc_stats
Date: Mon,  2 Jan 2012 14:50:06 +0100	[thread overview]
Message-ID: <1325512207-16501-4-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1325512207-16501-1-git-send-email-s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 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 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 */
-- 
1.7.7.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2012-01-02 13:50 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-02 13:50 tlsf patches Sascha Hauer
2012-01-02 13:50 ` [PATCH 1/3] tlsf: enable assertions Sascha Hauer
2012-01-02 13:50 ` [PATCH] uart drivers: use xzalloc instead of xmalloc Sascha Hauer
2012-01-02 13:50 ` Sascha Hauer [this message]
2012-01-02 13:50 ` [PATCH 3/3] tlsf: remove unused stuff from tlsfbits.h Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1325512207-16501-4-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox