Add the prof_sys_thread_name feature in the prof_recent unit test.

This tests the combination of the prof_recent and thread_name features.
Verified that it catches the issue being fixed in this PR.

Also explicitly set thread name in test/unit/prof_recent.  This fixes the name
testing when no default thread name is set (e.g. FreeBSD).
This commit is contained in:
Qi Wang 2023-05-10 16:32:51 -07:00 committed by Qi Wang
parent 94ace05832
commit d4a2b8bab1
4 changed files with 29 additions and 11 deletions

View File

@ -5,5 +5,7 @@ typedef HANDLE thd_t;
typedef pthread_t thd_t; typedef pthread_t thd_t;
#endif #endif
void thd_create(thd_t *thd, void *(*proc)(void *), void *arg); void thd_create(thd_t *thd, void *(*proc)(void *), void *arg);
void thd_join(thd_t thd, void **ret); void thd_join(thd_t thd, void **ret);
bool thd_has_setname(void);
void thd_setname(const char *name);

View File

@ -32,3 +32,21 @@ thd_join(thd_t thd, void **ret) {
pthread_join(thd, ret); pthread_join(thd, ret);
} }
#endif #endif
void
thd_setname(const char *name) {
#ifdef JEMALLOC_HAVE_PTHREAD_SETNAME_NP
pthread_setname_np(pthread_self(), name);
#elif defined(JEMALLOC_HAVE_PTHREAD_SET_NAME_NP)
pthread_set_name_np(pthread_self(), name);
#endif
}
bool
thd_has_setname(void) {
#if defined(JEMALLOC_HAVE_PTHREAD_SETNAME_NP) || defined(JEMALLOC_HAVE_PTHREAD_SET_NAME_NP)
return true;
#else
return false;
#endif
}

View File

@ -5,6 +5,8 @@
/* As specified in the shell script */ /* As specified in the shell script */
#define OPT_ALLOC_MAX 3 #define OPT_ALLOC_MAX 3
const char *test_thread_name = "test_thread";
/* Invariant before and after every test (when config_prof is on) */ /* Invariant before and after every test (when config_prof is on) */
static void static void
confirm_prof_setup() { confirm_prof_setup() {
@ -439,16 +441,11 @@ confirm_record(const char *template, const confirm_record_t *records,
} }
ASSERT_CHAR(','); ASSERT_CHAR(',');
if (opt_prof_sys_thread_name) { if (thd_has_setname() && opt_prof_sys_thread_name) {
ASSERT_FORMATTED_STR("\"%s_thread_name\"", ASSERT_FORMATTED_STR("\"%s_thread_name\"",
*type); *type);
ASSERT_CHAR(':'); ASSERT_FORMATTED_STR(":\"%s\",",
ASSERT_CHAR('"'); test_thread_name);
while (*start != '"') {
++start;
}
ASSERT_CHAR('"');
ASSERT_CHAR(',');
} }
ASSERT_FORMATTED_STR("\"%s_time\"", *type); ASSERT_FORMATTED_STR("\"%s_time\"", *type);
@ -495,6 +492,7 @@ confirm_record(const char *template, const confirm_record_t *records,
TEST_BEGIN(test_prof_recent_alloc_dump) { TEST_BEGIN(test_prof_recent_alloc_dump) {
test_skip_if(!config_prof); test_skip_if(!config_prof);
thd_setname(test_thread_name);
confirm_prof_setup(); confirm_prof_setup();
ssize_t future; ssize_t future;

View File

@ -1,5 +1,5 @@
#!/bin/sh #!/bin/sh
if [ "x${enable_prof}" = "x1" ] ; then if [ "x${enable_prof}" = "x1" ] ; then
export MALLOC_CONF="prof:true,prof_active:true,lg_prof_sample:0,prof_recent_alloc_max:3" export MALLOC_CONF="prof:true,prof_active:true,lg_prof_sample:0,prof_recent_alloc_max:3,prof_sys_thread_name:true"
fi fi