@@ -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");
@@ -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); \
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(+)