2014-10-02 08:51:52 +08:00
|
|
|
#include "test/jemalloc_test.h"
|
|
|
|
|
2017-01-20 13:41:41 +08:00
|
|
|
#define NTHREADS 4
|
|
|
|
#define NALLOCS_PER_THREAD 50
|
|
|
|
#define DUMP_INTERVAL 1
|
|
|
|
#define BT_COUNT_CHECK_INTERVAL 5
|
2014-01-18 07:40:52 +08:00
|
|
|
|
|
|
|
static int
|
2017-01-16 08:56:30 +08:00
|
|
|
prof_dump_open_intercept(bool propagate_err, const char *filename) {
|
2014-01-18 07:40:52 +08:00
|
|
|
int fd;
|
|
|
|
|
|
|
|
fd = open("/dev/null", O_WRONLY);
|
|
|
|
assert_d_ne(fd, -1, "Unexpected open() failure");
|
|
|
|
|
2017-01-20 10:15:45 +08:00
|
|
|
return fd;
|
2014-01-18 07:40:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void *
|
2017-01-16 08:56:30 +08:00
|
|
|
alloc_from_permuted_backtrace(unsigned thd_ind, unsigned iteration) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return btalloc(1, thd_ind*NALLOCS_PER_THREAD + iteration);
|
2014-01-18 07:40:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void *
|
2017-01-16 08:56:30 +08:00
|
|
|
thd_start(void *varg) {
|
2014-01-18 07:40:52 +08:00
|
|
|
unsigned thd_ind = *(unsigned *)varg;
|
|
|
|
size_t bt_count_prev, bt_count;
|
|
|
|
unsigned i_prev, i;
|
|
|
|
|
|
|
|
i_prev = 0;
|
|
|
|
bt_count_prev = 0;
|
|
|
|
for (i = 0; i < NALLOCS_PER_THREAD; i++) {
|
|
|
|
void *p = alloc_from_permuted_backtrace(thd_ind, i);
|
|
|
|
dallocx(p, 0);
|
|
|
|
if (i % DUMP_INTERVAL == 0) {
|
|
|
|
assert_d_eq(mallctl("prof.dump", NULL, NULL, NULL, 0),
|
|
|
|
0, "Unexpected error while dumping heap profile");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i % BT_COUNT_CHECK_INTERVAL == 0 ||
|
|
|
|
i+1 == NALLOCS_PER_THREAD) {
|
|
|
|
bt_count = prof_bt_count();
|
|
|
|
assert_zu_le(bt_count_prev+(i-i_prev), bt_count,
|
2014-01-22 06:59:40 +08:00
|
|
|
"Expected larger backtrace count increase");
|
2014-01-18 07:40:52 +08:00
|
|
|
i_prev = i;
|
|
|
|
bt_count_prev = bt_count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-20 10:15:45 +08:00
|
|
|
return NULL;
|
2014-01-18 07:40:52 +08:00
|
|
|
}
|
|
|
|
|
2017-01-16 08:56:30 +08:00
|
|
|
TEST_BEGIN(test_idump) {
|
2014-01-18 07:40:52 +08:00
|
|
|
bool active;
|
|
|
|
thd_t thds[NTHREADS];
|
|
|
|
unsigned thd_args[NTHREADS];
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
test_skip_if(!config_prof);
|
|
|
|
|
|
|
|
active = true;
|
2016-10-28 12:31:25 +08:00
|
|
|
assert_d_eq(mallctl("prof.active", NULL, NULL, (void *)&active,
|
|
|
|
sizeof(active)), 0,
|
|
|
|
"Unexpected mallctl failure while activating profiling");
|
2014-01-18 07:40:52 +08:00
|
|
|
|
|
|
|
prof_dump_open = prof_dump_open_intercept;
|
|
|
|
|
|
|
|
for (i = 0; i < NTHREADS; i++) {
|
|
|
|
thd_args[i] = i;
|
|
|
|
thd_create(&thds[i], thd_start, (void *)&thd_args[i]);
|
|
|
|
}
|
2017-01-16 08:56:30 +08:00
|
|
|
for (i = 0; i < NTHREADS; i++) {
|
2014-01-18 07:40:52 +08:00
|
|
|
thd_join(thds[i], NULL);
|
2017-01-16 08:56:30 +08:00
|
|
|
}
|
2014-01-18 07:40:52 +08:00
|
|
|
}
|
|
|
|
TEST_END
|
|
|
|
|
|
|
|
int
|
2017-01-16 08:56:30 +08:00
|
|
|
main(void) {
|
2017-01-20 10:15:45 +08:00
|
|
|
return test(
|
|
|
|
test_idump);
|
2014-01-18 07:40:52 +08:00
|
|
|
}
|