From c2e7a063923f43b66a58815ff85f9fcf1681cc76 Mon Sep 17 00:00:00 2001 From: Yinan Zhang Date: Fri, 26 Jun 2020 15:26:51 -0700 Subject: [PATCH] No need to intercept prof_dump_header() in tests --- include/jemalloc/internal/prof_data.h | 2 -- src/prof_data.c | 4 +--- test/unit/prof_reset.c | 31 ++++++--------------------- 3 files changed, 7 insertions(+), 30 deletions(-) diff --git a/include/jemalloc/internal/prof_data.h b/include/jemalloc/internal/prof_data.h index bf6e480e..e2e4aedb 100644 --- a/include/jemalloc/internal/prof_data.h +++ b/include/jemalloc/internal/prof_data.h @@ -28,8 +28,6 @@ void prof_tctx_try_destroy(tsd_t *tsd, prof_tctx_t *tctx); /* Used in unit tests. */ 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(prof_cnt_t *cnt_all); #endif /* JEMALLOC_INTERNAL_PROF_DATA_H */ diff --git a/src/prof_data.c b/src/prof_data.c index ee022ccd..6b441de1 100644 --- a/src/prof_data.c +++ b/src/prof_data.c @@ -792,8 +792,7 @@ prof_tdata_dump_iter(prof_tdata_tree_t *tdatas, prof_tdata_t *tdata, } static void -prof_dump_header_impl(void *opaque, const prof_cnt_t *cnt_all) { - prof_dump_iter_arg_t *arg = (prof_dump_iter_arg_t *)opaque; +prof_dump_header(prof_dump_iter_arg_t *arg, const prof_cnt_t *cnt_all) { prof_dump_printf(arg->prof_dump_write, arg->cbopaque, "heap_v2/%"FMTu64"\n t*: ", ((uint64_t)1U << lg_prof_sample)); prof_dump_print_cnts(arg->prof_dump_write, arg->cbopaque, cnt_all); @@ -803,7 +802,6 @@ prof_dump_header_impl(void *opaque, const prof_cnt_t *cnt_all) { tdata_tree_iter(&tdatas, NULL, prof_tdata_dump_iter, arg); malloc_mutex_unlock(arg->tsdn, &tdatas_mtx); } -prof_dump_header_t *JET_MUTABLE prof_dump_header = prof_dump_header_impl; static void prof_dump_gctx(prof_dump_iter_arg_t *arg, prof_gctx_t *gctx, diff --git a/test/unit/prof_reset.c b/test/unit/prof_reset.c index 8c82e6d5..a0fb0389 100644 --- a/test/unit/prof_reset.c +++ b/test/unit/prof_reset.c @@ -84,45 +84,26 @@ TEST_BEGIN(test_prof_reset_basic) { } TEST_END -bool prof_dump_header_intercepted = false; -prof_cnt_t cnt_all_copy = {0, 0, 0, 0}; -static void -prof_dump_header_intercept(void *opaque, const prof_cnt_t *cnt_all) { - prof_dump_header_intercepted = true; - memcpy(&cnt_all_copy, cnt_all, sizeof(prof_cnt_t)); -} - TEST_BEGIN(test_prof_reset_cleanup) { - void *p; - prof_dump_header_t *prof_dump_header_orig; - test_skip_if(!config_prof); set_prof_active(true); expect_zu_eq(prof_bt_count(), 0, "Expected 0 backtraces"); - p = mallocx(1, 0); + void *p = mallocx(1, 0); expect_ptr_not_null(p, "Unexpected mallocx() failure"); expect_zu_eq(prof_bt_count(), 1, "Expected 1 backtrace"); - prof_dump_header_orig = prof_dump_header; - prof_dump_header = prof_dump_header_intercept; - expect_false(prof_dump_header_intercepted, "Unexpected intercept"); - - expect_d_eq(mallctl("prof.dump", NULL, NULL, NULL, 0), - 0, "Unexpected error while dumping heap profile"); - expect_true(prof_dump_header_intercepted, "Expected intercept"); - expect_u64_eq(cnt_all_copy.curobjs, 1, "Expected 1 allocation"); + prof_cnt_t cnt_all; + prof_cnt_all(&cnt_all); + expect_u64_eq(cnt_all.curobjs, 1, "Expected 1 allocation"); expect_d_eq(mallctl("prof.reset", NULL, NULL, NULL, 0), 0, "Unexpected error while resetting heap profile data"); - expect_d_eq(mallctl("prof.dump", NULL, NULL, NULL, 0), - 0, "Unexpected error while dumping heap profile"); - expect_u64_eq(cnt_all_copy.curobjs, 0, "Expected 0 allocations"); + prof_cnt_all(&cnt_all); + expect_u64_eq(cnt_all.curobjs, 0, "Expected 0 allocations"); expect_zu_eq(prof_bt_count(), 1, "Expected 1 backtrace"); - prof_dump_header = prof_dump_header_orig; - dallocx(p, 0); expect_zu_eq(prof_bt_count(), 0, "Expected 0 backtraces");