linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: linux-sparse@vger.kernel.org
Cc: Christopher Li <sparse@chrisli.org>,
	Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH 1/5] add get_<allocator>_stats()
Date: Wed, 12 Apr 2017 10:36:59 +0200	[thread overview]
Message-ID: <20170412083703.11552-2-luc.vanoostenryck@gmail.com> (raw)
In-Reply-To: <20170412083703.11552-1-luc.vanoostenryck@gmail.com>

There exists a function to display the stats from each allocator
but:
1) what it displays is a bit long and fixed
2) it doesn't allow to make totals and stuff.

Change this by adding a function that only collect the stats
from each allocator.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 allocate.c |  8 ++++++++
 allocate.h | 12 ++++++++++++
 2 files changed, 20 insertions(+)

diff --git a/allocate.c b/allocate.c
index f597caf16..daa4ac247 100644
--- a/allocate.c
+++ b/allocate.c
@@ -127,6 +127,14 @@ void show_allocations(struct allocator_struct *x)
 		(double) x->useful_bytes / x->allocations);
 }
 
+void get_allocator_stats(struct allocator_struct *x, struct allocator_stats *s)
+{
+	s->name = x->name;
+	s->allocations = x->allocations;
+	s->useful_bytes = x->useful_bytes;
+	s->total_bytes = x->total_bytes;
+}
+
 ALLOCATOR(ident, "identifiers");
 ALLOCATOR(token, "tokens");
 ALLOCATOR(context, "contexts");
diff --git a/allocate.h b/allocate.h
index 9e51ed7da..6e6c3a614 100644
--- a/allocate.h
+++ b/allocate.h
@@ -17,16 +17,24 @@ struct allocator_struct {
 	unsigned int allocations, total_bytes, useful_bytes;
 };
 
+struct allocator_stats {
+	const char *name;
+	unsigned int allocations;
+	unsigned long total_bytes, useful_bytes;
+};
+
 extern void protect_allocations(struct allocator_struct *desc);
 extern void drop_all_allocations(struct allocator_struct *desc);
 extern void *allocate(struct allocator_struct *desc, unsigned int size);
 extern void free_one_entry(struct allocator_struct *desc, void *entry);
 extern void show_allocations(struct allocator_struct *);
+extern void get_allocator_stats(struct allocator_struct *, struct allocator_stats *);
 
 #define __DECLARE_ALLOCATOR(type, x)		\
 	extern type *__alloc_##x(int);		\
 	extern void __free_##x(type *);		\
 	extern void show_##x##_alloc(void);	\
+	extern void get_##x##_stats(struct allocator_stats *);		\
 	extern void clear_##x##_alloc(void);	\
 	extern void protect_##x##_alloc(void);
 #define DECLARE_ALLOCATOR(x) __DECLARE_ALLOCATOR(struct x, x)
@@ -48,6 +56,10 @@ extern void show_allocations(struct allocator_struct *);
 	{							\
 		show_allocations(&x##_allocator);		\
 	}							\
+	void get_##x##_stats(struct allocator_stats *s)		\
+	{							\
+		get_allocator_stats(&x##_allocator, s);		\
+	}							\
 	void clear_##x##_alloc(void)				\
 	{							\
 		drop_all_allocations(&x##_allocator);		\
-- 
2.12.0


  reply	other threads:[~2017-04-12  8:37 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-12  8:36 [PATCH 0/5] report allocation stats Luc Van Oostenryck
2017-04-12  8:36 ` Luc Van Oostenryck [this message]
2017-04-12  8:37 ` [PATCH 2/5] add show_allocation_stats() Luc Van Oostenryck
2017-04-12  8:37 ` [PATCH 3/5] add helper handle_simple_switch() Luc Van Oostenryck
2017-06-01  6:15   ` Christopher Li
2017-06-01 14:30     ` Luc Van Oostenryck
2017-04-12  8:37 ` [PATCH 4/5] teach sparse how to handle '-fmem-report' Luc Van Oostenryck
2017-04-12  8:37 ` [PATCH 5/5] use -fmem-report to report allocation stats Luc Van Oostenryck

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=20170412083703.11552-2-luc.vanoostenryck@gmail.com \
    --to=luc.vanoostenryck@gmail.com \
    --cc=linux-sparse@vger.kernel.org \
    --cc=sparse@chrisli.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;
as well as URLs for NNTP newsgroup(s).