Generalize prof_cnt_all() for testing
This commit is contained in:
parent
80d18c18c9
commit
f58ebdff7a
@ -30,7 +30,6 @@ size_t prof_tdata_count(void);
|
||||
size_t prof_bt_count(void);
|
||||
typedef void (prof_dump_header_t)(void *, const prof_cnt_t *);
|
||||
extern prof_dump_header_t *JET_MUTABLE prof_dump_header;
|
||||
void prof_cnt_all(uint64_t *curobjs, uint64_t *curbytes, uint64_t *accumobjs,
|
||||
uint64_t *accumbytes);
|
||||
void prof_cnt_all(prof_cnt_t *cnt_all);
|
||||
|
||||
#endif /* JEMALLOC_INTERNAL_PROF_DATA_H */
|
||||
|
@ -939,46 +939,16 @@ prof_dump_impl(tsd_t *tsd, write_cb_t *prof_dump_write, void *cbopaque,
|
||||
|
||||
/* Used in unit tests. */
|
||||
void
|
||||
prof_cnt_all(uint64_t *curobjs, uint64_t *curbytes, uint64_t *accumobjs,
|
||||
uint64_t *accumbytes) {
|
||||
tsd_t *tsd;
|
||||
prof_tdata_t *tdata;
|
||||
prof_cnt_t cnt_all;
|
||||
size_t leak_ngctx;
|
||||
prof_gctx_tree_t gctxs;
|
||||
|
||||
tsd = tsd_fetch();
|
||||
tdata = prof_tdata_get(tsd, false);
|
||||
prof_cnt_all(prof_cnt_t *cnt_all) {
|
||||
tsd_t *tsd = tsd_fetch();
|
||||
prof_tdata_t *tdata = prof_tdata_get(tsd, false);
|
||||
if (tdata == NULL) {
|
||||
if (curobjs != NULL) {
|
||||
*curobjs = 0;
|
||||
}
|
||||
if (curbytes != NULL) {
|
||||
*curbytes = 0;
|
||||
}
|
||||
if (accumobjs != NULL) {
|
||||
*accumobjs = 0;
|
||||
}
|
||||
if (accumbytes != NULL) {
|
||||
*accumbytes = 0;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
prof_dump_prep(tsd, tdata, &cnt_all, &leak_ngctx, &gctxs);
|
||||
prof_gctx_finish(tsd, &gctxs);
|
||||
|
||||
if (curobjs != NULL) {
|
||||
*curobjs = cnt_all.curobjs;
|
||||
}
|
||||
if (curbytes != NULL) {
|
||||
*curbytes = cnt_all.curbytes;
|
||||
}
|
||||
if (accumobjs != NULL) {
|
||||
*accumobjs = cnt_all.accumobjs;
|
||||
}
|
||||
if (accumbytes != NULL) {
|
||||
*accumbytes = cnt_all.accumbytes;
|
||||
memset(cnt_all, 0, sizeof(prof_cnt_t));
|
||||
} else {
|
||||
size_t leak_ngctx;
|
||||
prof_gctx_tree_t gctxs;
|
||||
prof_dump_prep(tsd, tdata, cnt_all, &leak_ngctx, &gctxs);
|
||||
prof_gctx_finish(tsd, &gctxs);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,21 +7,21 @@ TEST_BEGIN(test_prof_realloc) {
|
||||
int flags;
|
||||
void *p, *q;
|
||||
prof_info_t prof_info_p, prof_info_q;
|
||||
uint64_t curobjs_0, curobjs_1, curobjs_2, curobjs_3;
|
||||
prof_cnt_t cnt_0, cnt_1, cnt_2, cnt_3;
|
||||
|
||||
test_skip_if(!config_prof);
|
||||
|
||||
tsd = tsd_fetch();
|
||||
flags = MALLOCX_TCACHE_NONE;
|
||||
|
||||
prof_cnt_all(&curobjs_0, NULL, NULL, NULL);
|
||||
prof_cnt_all(&cnt_0);
|
||||
p = mallocx(1024, flags);
|
||||
expect_ptr_not_null(p, "Unexpected mallocx() failure");
|
||||
prof_info_get(tsd, p, NULL, &prof_info_p);
|
||||
expect_ptr_ne(prof_info_p.alloc_tctx, (prof_tctx_t *)(uintptr_t)1U,
|
||||
"Expected valid tctx");
|
||||
prof_cnt_all(&curobjs_1, NULL, NULL, NULL);
|
||||
expect_u64_eq(curobjs_0 + 1, curobjs_1,
|
||||
prof_cnt_all(&cnt_1);
|
||||
expect_u64_eq(cnt_0.curobjs + 1, cnt_1.curobjs,
|
||||
"Allocation should have increased sample size");
|
||||
|
||||
q = rallocx(p, 2048, flags);
|
||||
@ -30,13 +30,13 @@ TEST_BEGIN(test_prof_realloc) {
|
||||
prof_info_get(tsd, q, NULL, &prof_info_q);
|
||||
expect_ptr_ne(prof_info_q.alloc_tctx, (prof_tctx_t *)(uintptr_t)1U,
|
||||
"Expected valid tctx");
|
||||
prof_cnt_all(&curobjs_2, NULL, NULL, NULL);
|
||||
expect_u64_eq(curobjs_1, curobjs_2,
|
||||
prof_cnt_all(&cnt_2);
|
||||
expect_u64_eq(cnt_1.curobjs, cnt_2.curobjs,
|
||||
"Reallocation should not have changed sample size");
|
||||
|
||||
dallocx(q, flags);
|
||||
prof_cnt_all(&curobjs_3, NULL, NULL, NULL);
|
||||
expect_u64_eq(curobjs_0, curobjs_3,
|
||||
prof_cnt_all(&cnt_3);
|
||||
expect_u64_eq(cnt_0.curobjs, cnt_3.curobjs,
|
||||
"Sample size should have returned to base level");
|
||||
}
|
||||
TEST_END
|
||||
|
Loading…
Reference in New Issue
Block a user