Add heap profiling tests.
Fix a regression in prof_dump_ctx() due to an uninitized variable. This
was caused by revision 4f37ef693e
, so no
releases are affected.
This commit is contained in:
116
test/unit/prof_accum.c
Normal file
116
test/unit/prof_accum.c
Normal file
@@ -0,0 +1,116 @@
|
||||
#include "test/jemalloc_test.h"
|
||||
|
||||
#define NTHREADS 4
|
||||
#define NALLOCS_PER_THREAD 50
|
||||
#define DUMP_INTERVAL 1
|
||||
#define BT_COUNT_CHECK_INTERVAL 5
|
||||
|
||||
#ifdef JEMALLOC_PROF
|
||||
const char *malloc_conf =
|
||||
"prof:true,prof_accum:true,prof_active:false,lg_prof_sample:0";
|
||||
#endif
|
||||
|
||||
static int
|
||||
prof_dump_open_intercept(bool propagate_err, const char *filename)
|
||||
{
|
||||
int fd;
|
||||
|
||||
fd = open("/dev/null", O_WRONLY);
|
||||
assert_d_ne(fd, -1, "Unexpected open() failure");
|
||||
|
||||
return (fd);
|
||||
}
|
||||
|
||||
#define alloc_n_proto(n) \
|
||||
static void *alloc_##n(unsigned bits);
|
||||
|
||||
#define alloc_n_gen(n) \
|
||||
static void * \
|
||||
alloc_##n(unsigned bits) \
|
||||
{ \
|
||||
\
|
||||
if (bits == 0) { \
|
||||
void *p = mallocx(1, 0); \
|
||||
assert_ptr_not_null(p, "Unexpected mallocx() failure"); \
|
||||
return (p); \
|
||||
} \
|
||||
\
|
||||
switch (bits & 0x1U) { \
|
||||
case 0: return (alloc_0(bits >> 1)); \
|
||||
case 1: return (alloc_1(bits >> 1)); \
|
||||
default: not_reached(); \
|
||||
} \
|
||||
}
|
||||
alloc_n_proto(0)
|
||||
alloc_n_proto(1)
|
||||
alloc_n_gen(0)
|
||||
alloc_n_gen(1)
|
||||
|
||||
static void *
|
||||
alloc_from_permuted_backtrace(unsigned thd_ind, unsigned iteration)
|
||||
{
|
||||
|
||||
return (alloc_0(thd_ind*NALLOCS_PER_THREAD + iteration));
|
||||
}
|
||||
|
||||
static void *
|
||||
thd_start(void *varg)
|
||||
{
|
||||
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,
|
||||
"Expected larger bactrace count increase");
|
||||
i_prev = i;
|
||||
bt_count_prev = bt_count;
|
||||
}
|
||||
}
|
||||
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
TEST_BEGIN(test_idump)
|
||||
{
|
||||
bool active;
|
||||
thd_t thds[NTHREADS];
|
||||
unsigned thd_args[NTHREADS];
|
||||
unsigned i;
|
||||
|
||||
test_skip_if(!config_prof);
|
||||
|
||||
active = true;
|
||||
assert_d_eq(mallctl("prof.active", NULL, NULL, &active, sizeof(active)),
|
||||
0, "Unexpected mallctl failure while activating profiling");
|
||||
|
||||
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]);
|
||||
}
|
||||
for (i = 0; i < NTHREADS; i++)
|
||||
thd_join(thds[i], NULL);
|
||||
}
|
||||
TEST_END
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
|
||||
return (test(
|
||||
test_idump));
|
||||
}
|
56
test/unit/prof_gdump.c
Normal file
56
test/unit/prof_gdump.c
Normal file
@@ -0,0 +1,56 @@
|
||||
#include "test/jemalloc_test.h"
|
||||
|
||||
#ifdef JEMALLOC_PROF
|
||||
const char *malloc_conf = "prof:true,prof_active:false,prof_gdump:true";
|
||||
#endif
|
||||
|
||||
static bool did_prof_dump_open;
|
||||
|
||||
static int
|
||||
prof_dump_open_intercept(bool propagate_err, const char *filename)
|
||||
{
|
||||
int fd;
|
||||
|
||||
did_prof_dump_open = true;
|
||||
|
||||
fd = open("/dev/null", O_WRONLY);
|
||||
assert_d_ne(fd, -1, "Unexpected open() failure");
|
||||
|
||||
return (fd);
|
||||
}
|
||||
|
||||
TEST_BEGIN(test_gdump)
|
||||
{
|
||||
bool active;
|
||||
void *p, *q;
|
||||
|
||||
test_skip_if(!config_prof);
|
||||
|
||||
active = true;
|
||||
assert_d_eq(mallctl("prof.active", NULL, NULL, &active, sizeof(active)),
|
||||
0, "Unexpected mallctl failure while activating profiling");
|
||||
|
||||
prof_dump_open = prof_dump_open_intercept;
|
||||
|
||||
did_prof_dump_open = false;
|
||||
p = mallocx(chunksize, 0);
|
||||
assert_ptr_not_null(p, "Unexpected mallocx() failure");
|
||||
assert_true(did_prof_dump_open, "Expected a profile dump");
|
||||
|
||||
did_prof_dump_open = false;
|
||||
q = mallocx(chunksize, 0);
|
||||
assert_ptr_not_null(q, "Unexpected mallocx() failure");
|
||||
assert_true(did_prof_dump_open, "Expected a profile dump");
|
||||
|
||||
dallocx(p, 0);
|
||||
dallocx(q, 0);
|
||||
}
|
||||
TEST_END
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
|
||||
return (test(
|
||||
test_gdump));
|
||||
}
|
51
test/unit/prof_idump.c
Normal file
51
test/unit/prof_idump.c
Normal file
@@ -0,0 +1,51 @@
|
||||
#include "test/jemalloc_test.h"
|
||||
|
||||
#ifdef JEMALLOC_PROF
|
||||
const char *malloc_conf =
|
||||
"prof:true,prof_accum:true,prof_active:false,lg_prof_sample:0,"
|
||||
"lg_prof_interval:0";
|
||||
#endif
|
||||
|
||||
static bool did_prof_dump_open;
|
||||
|
||||
static int
|
||||
prof_dump_open_intercept(bool propagate_err, const char *filename)
|
||||
{
|
||||
int fd;
|
||||
|
||||
did_prof_dump_open = true;
|
||||
|
||||
fd = open("/dev/null", O_WRONLY);
|
||||
assert_d_ne(fd, -1, "Unexpected open() failure");
|
||||
|
||||
return (fd);
|
||||
}
|
||||
|
||||
TEST_BEGIN(test_idump)
|
||||
{
|
||||
bool active;
|
||||
void *p;
|
||||
|
||||
test_skip_if(!config_prof);
|
||||
|
||||
active = true;
|
||||
assert_d_eq(mallctl("prof.active", NULL, NULL, &active, sizeof(active)),
|
||||
0, "Unexpected mallctl failure while activating profiling");
|
||||
|
||||
prof_dump_open = prof_dump_open_intercept;
|
||||
|
||||
did_prof_dump_open = false;
|
||||
p = mallocx(1, 0);
|
||||
assert_ptr_not_null(p, "Unexpected mallocx() failure");
|
||||
dallocx(p, 0);
|
||||
assert_true(did_prof_dump_open, "Expected a profile dump");
|
||||
}
|
||||
TEST_END
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
|
||||
return (test(
|
||||
test_idump));
|
||||
}
|
Reference in New Issue
Block a user