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