From d460333efb22466713dd646b3947bbf0f868b02d Mon Sep 17 00:00:00 2001 From: Yinan Zhang Date: Fri, 19 Jun 2020 15:16:53 -0700 Subject: [PATCH] Improve naming for prof system thread name option --- Makefile.in | 2 +- include/jemalloc/internal/prof_externs.h | 6 +++--- src/ctl.c | 15 +++++++------- src/jemalloc.c | 5 ++--- src/prof.c | 18 ++++++++--------- test/unit/mallctl.c | 2 +- ...s_thread_name.c => prof_sys_thread_name.c} | 20 +++++++++---------- test/unit/prof_sys_thread_name.sh | 5 +++++ test/unit/prof_use_sys_thread_name.sh | 5 ----- 9 files changed, 38 insertions(+), 40 deletions(-) rename test/unit/{prof_use_sys_thread_name.c => prof_sys_thread_name.c} (74%) create mode 100644 test/unit/prof_sys_thread_name.sh delete mode 100644 test/unit/prof_use_sys_thread_name.sh diff --git a/Makefile.in b/Makefile.in index 35b4a05d..fd52ffc8 100644 --- a/Makefile.in +++ b/Makefile.in @@ -232,7 +232,7 @@ TESTS_UNIT := \ $(srcroot)test/unit/prof_reset.c \ $(srcroot)test/unit/prof_tctx.c \ $(srcroot)test/unit/prof_thread_name.c \ - $(srcroot)test/unit/prof_use_sys_thread_name.c \ + $(srcroot)test/unit/prof_sys_thread_name.c \ $(srcroot)test/unit/ql.c \ $(srcroot)test/unit/qr.c \ $(srcroot)test/unit/rb.c \ diff --git a/include/jemalloc/internal/prof_externs.h b/include/jemalloc/internal/prof_externs.h index b4339659..6021cf45 100644 --- a/include/jemalloc/internal/prof_externs.h +++ b/include/jemalloc/internal/prof_externs.h @@ -29,7 +29,7 @@ extern ssize_t opt_prof_recent_alloc_max; extern malloc_mutex_t prof_recent_alloc_mtx; /* Whether to use thread name provided by the system or by mallctl. */ -extern bool opt_prof_experimental_use_sys_thread_name; +extern bool opt_prof_sys_thread_name; /* Accessed via prof_active_[gs]et{_unlocked,}(). */ extern bool prof_active; @@ -90,8 +90,8 @@ uint64_t prof_sample_postponed_event_wait(tsd_t *tsd); void prof_sample_event_handler(tsd_t *tsd, uint64_t elapsed); /* Used by unit tests. */ -typedef int (prof_read_sys_thread_name_t)(char *buf, size_t limit); -extern prof_read_sys_thread_name_t *JET_MUTABLE prof_read_sys_thread_name; +typedef int (prof_sys_thread_name_read_t)(char *buf, size_t limit); +extern prof_sys_thread_name_read_t *JET_MUTABLE prof_sys_thread_name_read; size_t prof_tdata_count(void); size_t prof_bt_count(void); typedef int (prof_dump_open_t)(bool, const char *); diff --git a/src/ctl.c b/src/ctl.c index 24c959c4..5cba9af9 100644 --- a/src/ctl.c +++ b/src/ctl.c @@ -127,7 +127,7 @@ CTL_PROTO(opt_prof_final) CTL_PROTO(opt_prof_leak) CTL_PROTO(opt_prof_accum) CTL_PROTO(opt_prof_recent_alloc_max) -CTL_PROTO(opt_prof_experimental_use_sys_thread_name) +CTL_PROTO(opt_prof_sys_thread_name) CTL_PROTO(opt_prof_time_res) CTL_PROTO(opt_zero_realloc) CTL_PROTO(tcache_create) @@ -382,11 +382,10 @@ static const ctl_named_node_t opt_node[] = { {NAME("prof_final"), CTL(opt_prof_final)}, {NAME("prof_leak"), CTL(opt_prof_leak)}, {NAME("prof_accum"), CTL(opt_prof_accum)}, - {NAME("prof_recent_alloc_max"), CTL(opt_prof_recent_alloc_max)}, - {NAME("prof_experimental_use_sys_thread_name"), - CTL(opt_prof_experimental_use_sys_thread_name)}, - {NAME("zero_realloc"), CTL(opt_zero_realloc)}, - {NAME("prof_time_resolution"), CTL(opt_prof_time_res)} + {NAME("prof_recent_alloc_max"), CTL(opt_prof_recent_alloc_max)}, + {NAME("prof_sys_thread_name"), CTL(opt_prof_sys_thread_name)}, + {NAME("prof_time_resolution"), CTL(opt_prof_time_res)}, + {NAME("zero_realloc"), CTL(opt_zero_realloc)} }; static const ctl_named_node_t tcache_node[] = { @@ -1852,8 +1851,8 @@ CTL_RO_NL_CGEN(config_prof, opt_prof_final, opt_prof_final, bool) CTL_RO_NL_CGEN(config_prof, opt_prof_leak, opt_prof_leak, bool) CTL_RO_NL_CGEN(config_prof, opt_prof_recent_alloc_max, opt_prof_recent_alloc_max, ssize_t) -CTL_RO_NL_CGEN(config_prof, opt_prof_experimental_use_sys_thread_name, - opt_prof_experimental_use_sys_thread_name, bool) +CTL_RO_NL_CGEN(config_prof, opt_prof_sys_thread_name, opt_prof_sys_thread_name, + bool) CTL_RO_NL_CGEN(config_prof, opt_prof_time_res, prof_time_res_mode_names[opt_prof_time_res], const char *) CTL_RO_NL_GEN(opt_zero_realloc, diff --git a/src/jemalloc.c b/src/jemalloc.c index 573118e0..b468d821 100644 --- a/src/jemalloc.c +++ b/src/jemalloc.c @@ -1495,9 +1495,8 @@ malloc_conf_init_helper(sc_data_t *sc_data, unsigned bin_shard_sizes[SC_NBINS], CONF_HANDLE_BOOL(opt_prof_log, "prof_log") CONF_HANDLE_SSIZE_T(opt_prof_recent_alloc_max, "prof_recent_alloc_max", -1, SSIZE_MAX) - CONF_HANDLE_BOOL( - opt_prof_experimental_use_sys_thread_name, - "prof_experimental_use_sys_thread_name") + CONF_HANDLE_BOOL(opt_prof_sys_thread_name, + "prof_sys_thread_name") if (CONF_MATCH("prof_time_resolution")) { if (CONF_MATCH_VALUE("default")) { opt_prof_time_res = diff --git a/src/prof.c b/src/prof.c index 8ab68932..5e29f401 100644 --- a/src/prof.c +++ b/src/prof.c @@ -47,7 +47,7 @@ bool opt_prof_final = false; bool opt_prof_leak = false; bool opt_prof_accum = false; char opt_prof_prefix[PROF_DUMP_FILENAME_LEN]; -bool opt_prof_experimental_use_sys_thread_name = false; +bool opt_prof_sys_thread_name = false; /* Accessed via prof_sample_event_handler(). */ static counter_accum_t prof_idump_accumulated; @@ -197,21 +197,21 @@ prof_thread_name_set_impl(tsd_t *tsd, const char *thread_name) { } static int -prof_read_sys_thread_name_impl(char *buf, size_t limit) { +prof_sys_thread_name_read_impl(char *buf, size_t limit) { #ifdef JEMALLOC_HAVE_PTHREAD_SETNAME_NP return pthread_getname_np(pthread_self(), buf, limit); #else return ENOSYS; #endif } -prof_read_sys_thread_name_t *JET_MUTABLE prof_read_sys_thread_name = - prof_read_sys_thread_name_impl; +prof_sys_thread_name_read_t *JET_MUTABLE prof_sys_thread_name_read = + prof_sys_thread_name_read_impl; static void -prof_fetch_sys_thread_name(tsd_t *tsd) { +prof_sys_thread_name_fetch(tsd_t *tsd) { #define THREAD_NAME_MAX_LEN 16 char buf[THREAD_NAME_MAX_LEN]; - if (!prof_read_sys_thread_name(buf, THREAD_NAME_MAX_LEN)) { + if (!prof_sys_thread_name_read(buf, THREAD_NAME_MAX_LEN)) { prof_thread_name_set_impl(tsd, buf); } #undef THREAD_NAME_MAX_LEN @@ -220,8 +220,8 @@ prof_fetch_sys_thread_name(tsd_t *tsd) { void prof_malloc_sample_object(tsd_t *tsd, const void *ptr, size_t size, size_t usize, prof_tctx_t *tctx) { - if (opt_prof_experimental_use_sys_thread_name) { - prof_fetch_sys_thread_name(tsd); + if (opt_prof_sys_thread_name) { + prof_sys_thread_name_fetch(tsd); } edata_t *edata = emap_edata_lookup(tsd_tsdn(tsd), &arena_emap_global, @@ -870,7 +870,7 @@ prof_thread_name_get(tsd_t *tsd) { int prof_thread_name_set(tsd_t *tsd, const char *thread_name) { - if (opt_prof_experimental_use_sys_thread_name) { + if (opt_prof_sys_thread_name) { return ENOENT; } else { return prof_thread_name_set_impl(tsd, thread_name); diff --git a/test/unit/mallctl.c b/test/unit/mallctl.c index 10d809fb..3de56947 100644 --- a/test/unit/mallctl.c +++ b/test/unit/mallctl.c @@ -192,7 +192,7 @@ TEST_BEGIN(test_mallctl_opt) { TEST_MALLCTL_OPT(bool, prof_final, prof); TEST_MALLCTL_OPT(bool, prof_leak, prof); TEST_MALLCTL_OPT(ssize_t, prof_recent_alloc_max, prof); - TEST_MALLCTL_OPT(bool, prof_experimental_use_sys_thread_name, prof); + TEST_MALLCTL_OPT(bool, prof_sys_thread_name, prof); #undef TEST_MALLCTL_OPT } diff --git a/test/unit/prof_use_sys_thread_name.c b/test/unit/prof_sys_thread_name.c similarity index 74% rename from test/unit/prof_use_sys_thread_name.c rename to test/unit/prof_sys_thread_name.c index 60cb55bf..ec1e7745 100644 --- a/test/unit/prof_use_sys_thread_name.c +++ b/test/unit/prof_sys_thread_name.c @@ -3,31 +3,31 @@ static const char *test_thread_name = "test_name"; static int -test_prof_read_sys_thread_name_error(char *buf, size_t limit) { +test_prof_sys_thread_name_read_error(char *buf, size_t limit) { return ENOSYS; } static int -test_prof_read_sys_thread_name(char *buf, size_t limit) { +test_prof_sys_thread_name_read(char *buf, size_t limit) { assert(strlen(test_thread_name) < limit); strncpy(buf, test_thread_name, limit); return 0; } static int -test_prof_read_sys_thread_name_clear(char *buf, size_t limit) { +test_prof_sys_thread_name_read_clear(char *buf, size_t limit) { assert(limit > 0); buf[0] = '\0'; return 0; } -TEST_BEGIN(test_prof_experimental_use_sys_thread_name) { +TEST_BEGIN(test_prof_sys_thread_name) { test_skip_if(!config_prof); bool oldval; size_t sz = sizeof(oldval); - assert_d_eq(mallctl("opt.prof_experimental_use_sys_thread_name", - &oldval, &sz, NULL, 0), 0, "mallctl failed"); + assert_d_eq(mallctl("opt.prof_sys_thread_name", &oldval, &sz, NULL, 0), + 0, "mallctl failed"); assert_true(oldval, "option was not set correctly"); const char *thread_name; @@ -42,7 +42,7 @@ TEST_BEGIN(test_prof_experimental_use_sys_thread_name) { assert_ptr_eq(thread_name, test_thread_name, "Thread name should not be touched"); - prof_read_sys_thread_name = test_prof_read_sys_thread_name_error; + prof_sys_thread_name_read = test_prof_sys_thread_name_read_error; void *p = malloc(1); free(p); assert_d_eq(mallctl("thread.prof.name", &thread_name, &sz, NULL, 0), 0, @@ -50,7 +50,7 @@ TEST_BEGIN(test_prof_experimental_use_sys_thread_name) { assert_str_eq(thread_name, "", "Thread name should stay the same if the system call fails"); - prof_read_sys_thread_name = test_prof_read_sys_thread_name; + prof_sys_thread_name_read = test_prof_sys_thread_name_read; p = malloc(1); free(p); assert_d_eq(mallctl("thread.prof.name", &thread_name, &sz, NULL, 0), 0, @@ -58,7 +58,7 @@ TEST_BEGIN(test_prof_experimental_use_sys_thread_name) { assert_str_eq(thread_name, test_thread_name, "Thread name should be changed if the system call succeeds"); - prof_read_sys_thread_name = test_prof_read_sys_thread_name_clear; + prof_sys_thread_name_read = test_prof_sys_thread_name_read_clear; p = malloc(1); free(p); assert_d_eq(mallctl("thread.prof.name", &thread_name, &sz, NULL, 0), 0, @@ -71,5 +71,5 @@ TEST_END int main(void) { return test( - test_prof_experimental_use_sys_thread_name); + test_prof_sys_thread_name); } diff --git a/test/unit/prof_sys_thread_name.sh b/test/unit/prof_sys_thread_name.sh new file mode 100644 index 00000000..281cf9a0 --- /dev/null +++ b/test/unit/prof_sys_thread_name.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +if [ "x${enable_prof}" = "x1" ] ; then + export MALLOC_CONF="prof:true,lg_prof_sample:0,prof_sys_thread_name:true" +fi diff --git a/test/unit/prof_use_sys_thread_name.sh b/test/unit/prof_use_sys_thread_name.sh deleted file mode 100644 index 0e0e0d99..00000000 --- a/test/unit/prof_use_sys_thread_name.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -if [ "x${enable_prof}" = "x1" ] ; then - export MALLOC_CONF="prof:true,lg_prof_sample:0,prof_experimental_use_sys_thread_name:true" -fi