diff options
| author | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2017-04-12 10:10:20 +0200 |
|---|---|---|
| committer | Luc Van Oostenryck <luc.vanoostenryck@gmail.com> | 2017-05-15 18:32:11 +0200 |
| commit | 8decd80927fc0ff8432d6c8cc1c3d34d7726be86 (patch) | |
| tree | e09178b7cd7297a888810c3819d0f3a8ab45d2cc | |
| parent | 863ba0586620ac32fc0dcb63a488c62b729160ad (diff) | |
| download | sparse-dev-8decd80927fc0ff8432d6c8cc1c3d34d7726be86.tar.gz | |
add show_allocation_stats()
There exist some function to display the stats from each allocator
(show_<allocator>_alloc()) but these functions need to be
called one by one and deosn't allow to make some totals.
Chnage this by adding show_allocation_stats() which display
(in a more consise way) the stats from every allocator, together
with the totals.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
| -rw-r--r-- | Makefile | 1 | ||||
| -rw-r--r-- | allocate.h | 1 | ||||
| -rw-r--r-- | stats.c | 56 |
3 files changed, 58 insertions, 0 deletions
@@ -106,6 +106,7 @@ LIB_OBJS= target.o parse.o tokenize.o pre-process.o symbol.o lib.o scope.o \ expression.o show-parse.o evaluate.o expand.o inline.o linearize.o \ char.o sort.o allocate.o compat-$(OS).o ptrlist.o \ builtin.o \ + stats.o \ flow.o cse.o simplify.o memops.o liveness.o storage.o unssa.o dissect.o LIB_FILE= libsparse.a @@ -29,6 +29,7 @@ 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 *); +extern void show_allocation_stats(void); #define __DECLARE_ALLOCATOR(type, x) \ extern type *__alloc_##x(int); \ diff --git a/stats.c b/stats.c new file mode 100644 index 00000000..5f268573 --- /dev/null +++ b/stats.c @@ -0,0 +1,56 @@ +#include <stdio.h> +#include "allocate.h" +#include "linearize.h" +#include "storage.h" + +__DECLARE_ALLOCATOR(struct ptr_list, ptrlist); + + +typedef void (*get_t)(struct allocator_stats*); + +static void show_stats(get_t get, struct allocator_stats * tot) +{ + struct allocator_stats x; + + if (get) + get(&x); + else + x = *tot; + fprintf(stderr, "%16s: %8d, %10ld, %10ld, %6.2f%%, %8.2f\n", + x.name, x.allocations, x.useful_bytes, x.total_bytes, + 100 * (double) x.useful_bytes / (x.total_bytes ? : 1), + (double) x.useful_bytes / (x.allocations ? : 1)); + + tot->allocations += x.allocations; + tot->useful_bytes += x.useful_bytes; + tot->total_bytes += x.total_bytes; +} + +void show_allocation_stats(void) +{ + struct allocator_stats tot = { .name = "total", }; + + fprintf(stderr, "%16s: %8s, %10s, %10s, %7s, %8s\n", "allocator", "allocs", + "bytes", "total", "%usage", "average"); + show_stats(get_token_stats, &tot); + show_stats(get_ident_stats, &tot); + show_stats(get_symbol_stats, &tot); + show_stats(get_expression_stats, &tot); + show_stats(get_statement_stats, &tot); + show_stats(get_scope_stats, &tot); + show_stats(get_basic_block_stats, &tot); + show_stats(get_instruction_stats, &tot); + show_stats(get_pseudo_stats, &tot); + show_stats(get_pseudo_user_stats, &tot); + show_stats(get_ptrlist_stats, &tot); + show_stats(get_multijmp_stats, &tot); + show_stats(get_asm_rules_stats, &tot); + show_stats(get_asm_constraint_stats, &tot); + show_stats(get_context_stats, &tot); + show_stats(get_string_stats, &tot); + show_stats(get_bytes_stats, &tot); + //show_stats(get_storage_stats, &tot); + //show_stats(get_storage_hash_stats, &tot); + + show_stats(NULL, &tot); +} |
