Improve naming for prof system thread name option
This commit is contained in:
parent
25e43c6022
commit
d460333efb
@ -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 \
|
||||
|
@ -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 *);
|
||||
|
13
src/ctl.c
13
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)
|
||||
@ -383,10 +383,9 @@ static const ctl_named_node_t opt_node[] = {
|
||||
{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_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,
|
||||
|
@ -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 =
|
||||
|
18
src/prof.c
18
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);
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
5
test/unit/prof_sys_thread_name.sh
Normal file
5
test/unit/prof_sys_thread_name.sh
Normal file
@ -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
|
@ -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
|
Loading…
Reference in New Issue
Block a user