stats.c 1.7 KB

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