Restructure profiling

Develop new data structure and code logic for holding profiling
related information stored in the extent that may be needed after the
extent is released, which in particular is the case for the
reallocation code path (e.g. in `rallocx()` and `xallocx()`).  The
data structure is a generalization of `prof_tctx_t`: we previously
only copy out the `prof_tctx` before the extent is released, but we
may be in need of additional fields. Currently the only additional
field is the allocation time field, but there may be more fields in
the future.

The restructuring also resolved a bug: `prof_realloc()` mistakenly
passed the new `ptr` to `prof_free_sampled_object()`, but passing in
the `old_ptr` would crash because it's already been released.  Now
the essential profiling information is collectively copied out early
and safely passed to `prof_free_sampled_object()` after the extent is
released.
This commit is contained in:
Yinan Zhang
2019-11-19 16:24:57 -08:00
parent 8b2c2a596d
commit b55419f9b9
12 changed files with 82 additions and 92 deletions

View File

@@ -4,7 +4,7 @@ TEST_BEGIN(test_prof_realloc) {
tsdn_t *tsdn;
int flags;
void *p, *q;
prof_tctx_t *tctx_p, *tctx_q;
prof_info_t prof_info_p, prof_info_q;
uint64_t curobjs_0, curobjs_1, curobjs_2, curobjs_3;
test_skip_if(!config_prof);
@@ -15,8 +15,8 @@ TEST_BEGIN(test_prof_realloc) {
prof_cnt_all(&curobjs_0, NULL, NULL, NULL);
p = mallocx(1024, flags);
assert_ptr_not_null(p, "Unexpected mallocx() failure");
tctx_p = prof_tctx_get(tsdn, p, NULL);
assert_ptr_ne(tctx_p, (prof_tctx_t *)(uintptr_t)1U,
prof_info_get(tsdn, p, NULL, &prof_info_p);
assert_ptr_ne(prof_info_p.prof_tctx, (prof_tctx_t *)(uintptr_t)1U,
"Expected valid tctx");
prof_cnt_all(&curobjs_1, NULL, NULL, NULL);
assert_u64_eq(curobjs_0 + 1, curobjs_1,
@@ -25,8 +25,8 @@ TEST_BEGIN(test_prof_realloc) {
q = rallocx(p, 2048, flags);
assert_ptr_ne(p, q, "Expected move");
assert_ptr_not_null(p, "Unexpected rmallocx() failure");
tctx_q = prof_tctx_get(tsdn, q, NULL);
assert_ptr_ne(tctx_q, (prof_tctx_t *)(uintptr_t)1U,
prof_info_get(tsdn, q, NULL, &prof_info_q);
assert_ptr_ne(prof_info_q.prof_tctx, (prof_tctx_t *)(uintptr_t)1U,
"Expected valid tctx");
prof_cnt_all(&curobjs_2, NULL, NULL, NULL);
assert_u64_eq(curobjs_1, curobjs_2,