Add a small program to print data structure sizes.

This commit is contained in:
David Goldblatt 2020-05-27 11:56:36 -07:00 committed by David Goldblatt
parent 3e19ebd2ea
commit 17a64fe91c
2 changed files with 52 additions and 1 deletions

View File

@ -291,7 +291,8 @@ endif
TESTS_STRESS := $(srcroot)test/stress/microbench.c \ TESTS_STRESS := $(srcroot)test/stress/microbench.c \
$(srcroot)test/stress/fill_flush.c \ $(srcroot)test/stress/fill_flush.c \
$(srcroot)test/stress/large_microbench.c \ $(srcroot)test/stress/large_microbench.c \
$(srcroot)test/stress/hookbench.c $(srcroot)test/stress/hookbench.c \
$(srcroot)test/stress/sizes.c
TESTS := $(TESTS_UNIT) $(TESTS_INTEGRATION) $(TESTS_INTEGRATION_CPP) $(TESTS_STRESS) TESTS := $(TESTS_UNIT) $(TESTS_INTEGRATION) $(TESTS_INTEGRATION_CPP) $(TESTS_STRESS)

50
test/stress/sizes.c Normal file
View File

@ -0,0 +1,50 @@
#include "test/jemalloc_test.h"
#include <stdio.h>
/*
* Print the sizes of various important core data structures. OK, I guess this
* isn't really a "stress" test, but it does give useful information about
* low-level performance characteristics, as the other things in this directory
* do.
*/
static void
do_print(const char *name, size_t sz_bytes) {
const char *sizes[] = {"bytes", "KB", "MB", "GB", "TB", "PB", "EB",
"ZB"};
size_t sizes_max = sizeof(sizes)/sizeof(sizes[0]);
size_t ind = 0;
double sz = sz_bytes;
while (sz >= 1024 && ind < sizes_max) {
sz /= 1024;
ind++;
}
if (ind == 0) {
printf("%-20s: %zu bytes\n", name, sz_bytes);
} else {
printf("%-20s: %f %s\n", name, sz, sizes[ind]);
}
}
int
main() {
#define P(type) \
do_print(#type, sizeof(type))
P(arena_t);
P(arena_stats_t);
P(base_t);
P(decay_t);
P(edata_t);
P(ecache_t);
P(eset_t);
P(malloc_mutex_t);
P(prof_tctx_t);
P(prof_gctx_t);
P(prof_tdata_t);
P(tcache_t);
P(tcache_slow_t);
P(tsd_t);
#undef P
}