sizes.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include "test/jemalloc_test.h"
  2. #include <stdio.h>
  3. /*
  4. * Print the sizes of various important core data structures. OK, I guess this
  5. * isn't really a "stress" test, but it does give useful information about
  6. * low-level performance characteristics, as the other things in this directory
  7. * do.
  8. */
  9. static void
  10. do_print(const char *name, size_t sz_bytes) {
  11. const char *sizes[] = {"bytes", "KB", "MB", "GB", "TB", "PB", "EB",
  12. "ZB"};
  13. size_t sizes_max = sizeof(sizes)/sizeof(sizes[0]);
  14. size_t ind = 0;
  15. double sz = sz_bytes;
  16. while (sz >= 1024 && ind < sizes_max - 1) {
  17. sz /= 1024;
  18. ind++;
  19. }
  20. if (ind == 0) {
  21. printf("%-20s: %zu bytes\n", name, sz_bytes);
  22. } else {
  23. printf("%-20s: %f %s\n", name, sz, sizes[ind]);
  24. }
  25. }
  26. int
  27. main() {
  28. #define P(type) \
  29. do_print(#type, sizeof(type))
  30. P(arena_t);
  31. P(arena_stats_t);
  32. P(base_t);
  33. P(decay_t);
  34. P(edata_t);
  35. P(ecache_t);
  36. P(eset_t);
  37. P(malloc_mutex_t);
  38. P(prof_tctx_t);
  39. P(prof_gctx_t);
  40. P(prof_tdata_t);
  41. P(rtree_t);
  42. P(rtree_leaf_elm_t);
  43. P(slab_data_t);
  44. P(tcache_t);
  45. P(tcache_slow_t);
  46. P(tsd_t);
  47. #undef P
  48. }