From 5884a076fb858320e7bcf86b961dd1555a81a75e Mon Sep 17 00:00:00 2001 From: Qi Wang Date: Thu, 12 Aug 2021 15:48:02 -0700 Subject: [PATCH] Rename prof.dump_prefix to prof.prefix This better aligns with our naming convention. The option has not been included in any upstream release yet. --- doc/jemalloc.xml.in | 22 ++++++-------- include/jemalloc/internal/prof_sys.h | 2 +- src/ctl.c | 8 +++--- src/prof_sys.c | 43 ++++++++++++++-------------- test/unit/prof_idump.c | 6 ++-- 5 files changed, 37 insertions(+), 44 deletions(-) diff --git a/doc/jemalloc.xml.in b/doc/jemalloc.xml.in index fa53715d..b8b96abe 100644 --- a/doc/jemalloc.xml.in +++ b/doc/jemalloc.xml.in @@ -1410,8 +1410,7 @@ malloc_conf = "xmalloc:true";]]> primarily useful for disabling the automatic final heap dump (which also disables leak reporting, if enabled). The default prefix is jeprof. This prefix value can be overriden by - prof.dump_prefix. + prof.prefix. @@ -1492,8 +1491,7 @@ malloc_conf = "xmalloc:true";]]> where <prefix> is controlled by the opt.prof_prefix and - prof.dump_prefix + prof.prefix options. By default, interval-triggered profile dumping is disabled (encoded as -1). @@ -1527,8 +1525,7 @@ malloc_conf = "xmalloc:true";]]> <prefix>.<pid>.<seq>.f.heap, where <prefix> is controlled by the opt.prof_prefix and - prof.dump_prefix + prof.prefix options. Note that atexit() may allocate memory during application initialization and then deadlock internally when jemalloc in turn calls atexit(), so @@ -2398,16 +2395,14 @@ struct extent_hooks_s { is specified, to a file according to the pattern <prefix>.<pid>.<seq>.m<mseq>.heap, where <prefix> is controlled by the - opt.prof_prefix and - prof.dump_prefix + opt.prof_prefix + and prof.prefix options. - + - prof.dump_prefix + prof.prefix (const char *) -w [] @@ -2433,8 +2428,7 @@ struct extent_hooks_s { <prefix>.<pid>.<seq>.u<useq>.heap, where <prefix> is controlled by the opt.prof_prefix and - prof.dump_prefix + prof.prefix options. diff --git a/include/jemalloc/internal/prof_sys.h b/include/jemalloc/internal/prof_sys.h index d784ef91..6e4e811a 100644 --- a/include/jemalloc/internal/prof_sys.h +++ b/include/jemalloc/internal/prof_sys.h @@ -10,7 +10,7 @@ void prof_unwind_init(); void prof_sys_thread_name_fetch(tsd_t *tsd); int prof_getpid(void); void prof_get_default_filename(tsdn_t *tsdn, char *filename, uint64_t ind); -bool prof_dump_prefix_set(tsdn_t *tsdn, const char *prefix); +bool prof_prefix_set(tsdn_t *tsdn, const char *prefix); void prof_fdump_impl(tsd_t *tsd); void prof_idump_impl(tsd_t *tsd); bool prof_mdump_impl(tsd_t *tsd, const char *filename); diff --git a/src/ctl.c b/src/ctl.c index 3ed00072..253341a1 100644 --- a/src/ctl.c +++ b/src/ctl.c @@ -187,7 +187,7 @@ CTL_PROTO(prof_thread_active_init) CTL_PROTO(prof_active) CTL_PROTO(prof_dump) CTL_PROTO(prof_gdump) -CTL_PROTO(prof_dump_prefix) +CTL_PROTO(prof_prefix) CTL_PROTO(prof_reset) CTL_PROTO(prof_interval) CTL_PROTO(lg_prof_sample) @@ -578,7 +578,7 @@ static const ctl_named_node_t prof_node[] = { {NAME("active"), CTL(prof_active)}, {NAME("dump"), CTL(prof_dump)}, {NAME("gdump"), CTL(prof_gdump)}, - {NAME("dump_prefix"), CTL(prof_dump_prefix)}, + {NAME("prefix"), CTL(prof_prefix)}, {NAME("reset"), CTL(prof_reset)}, {NAME("interval"), CTL(prof_interval)}, {NAME("lg_sample"), CTL(lg_prof_sample)}, @@ -3227,7 +3227,7 @@ label_return: } static int -prof_dump_prefix_ctl(tsd_t *tsd, const size_t *mib, size_t miblen, +prof_prefix_ctl(tsd_t *tsd, const size_t *mib, size_t miblen, void *oldp, size_t *oldlenp, void *newp, size_t newlen) { int ret; const char *prefix = NULL; @@ -3240,7 +3240,7 @@ prof_dump_prefix_ctl(tsd_t *tsd, const size_t *mib, size_t miblen, WRITEONLY(); WRITE(prefix, const char *); - ret = prof_dump_prefix_set(tsd_tsdn(tsd), prefix) ? EFAULT : 0; + ret = prof_prefix_set(tsd_tsdn(tsd), prefix) ? EFAULT : 0; label_return: malloc_mutex_unlock(tsd_tsdn(tsd), &ctl_mtx); return ret; diff --git a/src/prof_sys.c b/src/prof_sys.c index 87cd2b2f..6a5b2b16 100644 --- a/src/prof_sys.c +++ b/src/prof_sys.c @@ -34,7 +34,7 @@ static uint64_t prof_dump_iseq; static uint64_t prof_dump_mseq; static uint64_t prof_dump_useq; -static char *prof_dump_prefix = NULL; +static char *prof_prefix = NULL; /* The fallback allocator profiling functionality will use. */ base_t *prof_base; @@ -524,16 +524,16 @@ prof_strncpy(char *UNUSED dest, const char *UNUSED src, size_t UNUSED size) { } static const char * -prof_dump_prefix_get(tsdn_t* tsdn) { +prof_prefix_get(tsdn_t* tsdn) { malloc_mutex_assert_owner(tsdn, &prof_dump_filename_mtx); - return prof_dump_prefix == NULL ? opt_prof_prefix : prof_dump_prefix; + return prof_prefix == NULL ? opt_prof_prefix : prof_prefix; } static bool -prof_dump_prefix_is_empty(tsdn_t *tsdn) { +prof_prefix_is_empty(tsdn_t *tsdn) { malloc_mutex_lock(tsdn, &prof_dump_filename_mtx); - bool ret = (prof_dump_prefix_get(tsdn)[0] == '\0'); + bool ret = (prof_prefix_get(tsdn)[0] == '\0'); malloc_mutex_unlock(tsdn, &prof_dump_filename_mtx); return ret; } @@ -545,18 +545,18 @@ prof_dump_filename(tsd_t *tsd, char *filename, char v, uint64_t vseq) { cassert(config_prof); assert(tsd_reentrancy_level_get(tsd) == 0); - const char *prof_prefix = prof_dump_prefix_get(tsd_tsdn(tsd)); + const char *prof_prefix = prof_prefix_get(tsd_tsdn(tsd)); if (vseq != VSEQ_INVALID) { /* "...v.heap" */ malloc_snprintf(filename, DUMP_FILENAME_BUFSIZE, - "%s.%d.%"FMTu64".%c%"FMTu64".heap", - prof_prefix, prof_getpid(), prof_dump_seq, v, vseq); + "%s.%d.%"FMTu64".%c%"FMTu64".heap", prof_prefix, + prof_getpid(), prof_dump_seq, v, vseq); } else { /* "....heap" */ malloc_snprintf(filename, DUMP_FILENAME_BUFSIZE, - "%s.%d.%"FMTu64".%c.heap", - prof_prefix, prof_getpid(), prof_dump_seq, v); + "%s.%d.%"FMTu64".%c.heap", prof_prefix, + prof_getpid(), prof_dump_seq, v); } prof_dump_seq++; } @@ -565,8 +565,7 @@ void prof_get_default_filename(tsdn_t *tsdn, char *filename, uint64_t ind) { malloc_mutex_lock(tsdn, &prof_dump_filename_mtx); malloc_snprintf(filename, PROF_DUMP_FILENAME_LEN, - "%s.%d.%"FMTu64".json", prof_dump_prefix_get(tsdn), prof_getpid(), - ind); + "%s.%d.%"FMTu64".json", prof_prefix_get(tsdn), prof_getpid(), ind); malloc_mutex_unlock(tsdn, &prof_dump_filename_mtx); } @@ -574,7 +573,7 @@ void prof_fdump_impl(tsd_t *tsd) { char filename[DUMP_FILENAME_BUFSIZE]; - assert(!prof_dump_prefix_is_empty(tsd_tsdn(tsd))); + assert(!prof_prefix_is_empty(tsd_tsdn(tsd))); malloc_mutex_lock(tsd_tsdn(tsd), &prof_dump_filename_mtx); prof_dump_filename(tsd, filename, 'f', VSEQ_INVALID); malloc_mutex_unlock(tsd_tsdn(tsd), &prof_dump_filename_mtx); @@ -582,11 +581,11 @@ prof_fdump_impl(tsd_t *tsd) { } bool -prof_dump_prefix_set(tsdn_t *tsdn, const char *prefix) { +prof_prefix_set(tsdn_t *tsdn, const char *prefix) { cassert(config_prof); ctl_mtx_assert_held(tsdn); malloc_mutex_lock(tsdn, &prof_dump_filename_mtx); - if (prof_dump_prefix == NULL) { + if (prof_prefix == NULL) { malloc_mutex_unlock(tsdn, &prof_dump_filename_mtx); /* Everything is still guarded by ctl_mtx. */ char *buffer = base_alloc(tsdn, prof_base, @@ -595,12 +594,12 @@ prof_dump_prefix_set(tsdn_t *tsdn, const char *prefix) { return true; } malloc_mutex_lock(tsdn, &prof_dump_filename_mtx); - prof_dump_prefix = buffer; + prof_prefix = buffer; } - assert(prof_dump_prefix != NULL); + assert(prof_prefix != NULL); - prof_strncpy(prof_dump_prefix, prefix, PROF_DUMP_FILENAME_LEN - 1); - prof_dump_prefix[PROF_DUMP_FILENAME_LEN - 1] = '\0'; + prof_strncpy(prof_prefix, prefix, PROF_DUMP_FILENAME_LEN - 1); + prof_prefix[PROF_DUMP_FILENAME_LEN - 1] = '\0'; malloc_mutex_unlock(tsdn, &prof_dump_filename_mtx); return false; @@ -609,7 +608,7 @@ prof_dump_prefix_set(tsdn_t *tsdn, const char *prefix) { void prof_idump_impl(tsd_t *tsd) { malloc_mutex_lock(tsd_tsdn(tsd), &prof_dump_filename_mtx); - if (prof_dump_prefix_get(tsd_tsdn(tsd))[0] == '\0') { + if (prof_prefix_get(tsd_tsdn(tsd))[0] == '\0') { malloc_mutex_unlock(tsd_tsdn(tsd), &prof_dump_filename_mtx); return; } @@ -626,7 +625,7 @@ prof_mdump_impl(tsd_t *tsd, const char *filename) { if (filename == NULL) { /* No filename specified, so automatically generate one. */ malloc_mutex_lock(tsd_tsdn(tsd), &prof_dump_filename_mtx); - if (prof_dump_prefix_get(tsd_tsdn(tsd))[0] == '\0') { + if (prof_prefix_get(tsd_tsdn(tsd))[0] == '\0') { malloc_mutex_unlock(tsd_tsdn(tsd), &prof_dump_filename_mtx); return true; } @@ -642,7 +641,7 @@ void prof_gdump_impl(tsd_t *tsd) { tsdn_t *tsdn = tsd_tsdn(tsd); malloc_mutex_lock(tsdn, &prof_dump_filename_mtx); - if (prof_dump_prefix_get(tsdn)[0] == '\0') { + if (prof_prefix_get(tsdn)[0] == '\0') { malloc_mutex_unlock(tsdn, &prof_dump_filename_mtx); return; } diff --git a/test/unit/prof_idump.c b/test/unit/prof_idump.c index 607944c1..e9f5e56c 100644 --- a/test/unit/prof_idump.c +++ b/test/unit/prof_idump.c @@ -26,14 +26,14 @@ TEST_BEGIN(test_idump) { bool active; void *p; - const char *dump_prefix = TEST_PREFIX; + const char *prefix = TEST_PREFIX; test_skip_if(!config_prof); active = true; - expect_d_eq(mallctl("prof.dump_prefix", NULL, NULL, - (void *)&dump_prefix, sizeof(dump_prefix)), 0, + expect_d_eq(mallctl("prof.prefix", NULL, NULL, (void *)&prefix, + sizeof(prefix)), 0, "Unexpected mallctl failure while overwriting dump prefix"); expect_d_eq(mallctl("prof.active", NULL, NULL, (void *)&active,