test_bit: add test_and_set_bit()
[smatch.git] / stats.c
blobcda18fcaed56cc02a7a5d7f74236862d986f7de0
1 #include <stdio.h>
2 #include "allocate.h"
3 #include "linearize.h"
4 #include "storage.h"
6 __DECLARE_ALLOCATOR(struct ptr_list, ptrlist);
9 typedef void (*get_t)(struct allocator_stats*);
11 static void show_stats(get_t get, struct allocator_stats * tot)
13 struct allocator_stats x;
15 if (get)
16 get(&x);
17 else
18 x = *tot;
19 fprintf(stderr, "%16s: %8d, %10ld, %10ld, %6.2f%%, %8.2f\n",
20 x.name, x.allocations, x.useful_bytes, x.total_bytes,
21 100 * (double) x.useful_bytes / (x.total_bytes ? : 1),
22 (double) x.useful_bytes / (x.allocations ? : 1));
24 tot->allocations += x.allocations;
25 tot->useful_bytes += x.useful_bytes;
26 tot->total_bytes += x.total_bytes;
29 void show_allocation_stats(void)
31 struct allocator_stats tot = { .name = "total", };
33 fprintf(stderr, "%16s: %8s, %10s, %10s, %7s, %8s\n", "allocator", "allocs",
34 "bytes", "total", "%usage", "average");
35 show_stats(get_token_stats, &tot);
36 show_stats(get_ident_stats, &tot);
37 show_stats(get_symbol_stats, &tot);
38 show_stats(get_expression_stats, &tot);
39 show_stats(get_statement_stats, &tot);
40 show_stats(get_scope_stats, &tot);
41 show_stats(get_basic_block_stats, &tot);
42 show_stats(get_instruction_stats, &tot);
43 show_stats(get_pseudo_stats, &tot);
44 show_stats(get_pseudo_user_stats, &tot);
45 show_stats(get_ptrlist_stats, &tot);
46 show_stats(get_multijmp_stats, &tot);
47 show_stats(get_asm_rules_stats, &tot);
48 show_stats(get_asm_constraint_stats, &tot);
49 show_stats(get_context_stats, &tot);
50 show_stats(get_string_stats, &tot);
51 show_stats(get_bytes_stats, &tot);
52 //show_stats(get_storage_stats, &tot);
53 //show_stats(get_storage_hash_stats, &tot);
55 show_stats(NULL, &tot);
58 void report_stats(void)
60 if (fmem_report)
61 show_allocation_stats();