Expose prof testing internal functions

This commit is contained in:
Yinan Zhang
2020-06-17 09:57:54 -07:00
parent 40fa6674a9
commit b7858abfc0
8 changed files with 46 additions and 58 deletions

View File

@@ -205,12 +205,8 @@ prof_read_sys_thread_name_impl(char *buf, size_t limit) {
return ENOSYS;
#endif
}
#ifdef JEMALLOC_JET
prof_read_sys_thread_name_t *JET_MUTABLE prof_read_sys_thread_name =
prof_read_sys_thread_name_impl;
#else
#define prof_read_sys_thread_name prof_read_sys_thread_name_impl
#endif
static void
prof_fetch_sys_thread_name(tsd_t *tsd) {

View File

@@ -421,7 +421,7 @@ prof_tctx_create(tsd_t *tsd) {
return prof_lookup(tsd, &bt);
}
#ifdef JEMALLOC_JET
/* Used in unit tests. */
static prof_tdata_t *
prof_tdata_count_iter(prof_tdata_tree_t *tdatas, prof_tdata_t *tdata,
void *arg) {
@@ -432,6 +432,7 @@ prof_tdata_count_iter(prof_tdata_tree_t *tdatas, prof_tdata_t *tdata,
return NULL;
}
/* Used in unit tests. */
size_t
prof_tdata_count(void) {
size_t tdata_count = 0;
@@ -446,6 +447,7 @@ prof_tdata_count(void) {
return tdata_count;
}
/* Used in unit tests. */
size_t
prof_bt_count(void) {
size_t bt_count;
@@ -464,7 +466,6 @@ prof_bt_count(void) {
return bt_count;
}
#endif
static int
prof_dump_open_impl(bool propagate_err, const char *filename) {
@@ -1174,7 +1175,7 @@ prof_dump(tsd_t *tsd, bool propagate_err, const char *filename,
return false;
}
#ifdef JEMALLOC_JET
/* Used in unit tests. */
void
prof_cnt_all(uint64_t *curobjs, uint64_t *curbytes, uint64_t *accumobjs,
uint64_t *accumbytes) {
@@ -1219,7 +1220,6 @@ prof_cnt_all(uint64_t *curobjs, uint64_t *curbytes, uint64_t *accumobjs,
*accumbytes = prof_tdata_merge_iter_arg.cnt_all.accumbytes;
}
}
#endif
void
prof_bt_hash(const void *key, size_t r_hash[2]) {

View File

@@ -27,9 +27,8 @@ enum prof_logging_state_e {
*/
prof_logging_state_t prof_logging_state = prof_logging_state_stopped;
#ifdef JEMALLOC_JET
/* Used in unit tests. */
static bool prof_log_dummy = false;
#endif
/* Incremented for every log file that is output. */
static uint64_t log_seq = 0;
@@ -305,7 +304,7 @@ prof_thr_node_keycomp(const void *k1, const void *k2) {
return thr_node1->thr_uid == thr_node2->thr_uid;
}
#ifdef JEMALLOC_JET
/* Used in unit tests. */
size_t
prof_log_bt_count(void) {
size_t cnt = 0;
@@ -317,6 +316,7 @@ prof_log_bt_count(void) {
return cnt;
}
/* Used in unit tests. */
size_t
prof_log_alloc_count(void) {
size_t cnt = 0;
@@ -328,6 +328,7 @@ prof_log_alloc_count(void) {
return cnt;
}
/* Used in unit tests. */
size_t
prof_log_thr_count(void) {
size_t cnt = 0;
@@ -339,11 +340,13 @@ prof_log_thr_count(void) {
return cnt;
}
/* Used in unit tests. */
bool
prof_log_is_logging(void) {
return prof_logging_state == prof_logging_state_started;
}
/* Used in unit tests. */
bool
prof_log_rep_check(void) {
if (prof_logging_state == prof_logging_state_stopped
@@ -395,11 +398,11 @@ prof_log_rep_check(void) {
return false;
}
/* Used in unit tests. */
void
prof_log_dummy_set(bool new_value) {
prof_log_dummy = new_value;
}
#endif
bool
prof_log_start(tsdn_t *tsdn, const char *filename) {
@@ -451,11 +454,9 @@ prof_emitter_write_cb(void *opaque, const char *to_write) {
struct prof_emitter_cb_arg_s *arg =
(struct prof_emitter_cb_arg_s *)opaque;
size_t bytes = strlen(to_write);
#ifdef JEMALLOC_JET
if (prof_log_dummy) {
return;
}
#endif
arg->ret = malloc_write_fd(arg->fd, to_write, bytes);
}
@@ -612,15 +613,11 @@ prof_log_stop(tsdn_t *tsdn) {
/* Create a file. */
int fd;
#ifdef JEMALLOC_JET
if (prof_log_dummy) {
fd = 0;
} else {
fd = creat(log_filename, 0644);
}
#else
fd = creat(log_filename, 0644);
#endif
if (fd == -1) {
malloc_printf("<jemalloc>: creat() for log file \"%s\" "
@@ -668,11 +665,9 @@ prof_log_stop(tsdn_t *tsdn) {
prof_logging_state = prof_logging_state_stopped;
malloc_mutex_unlock(tsdn, &log_mtx);
#ifdef JEMALLOC_JET
if (prof_log_dummy) {
return false;
}
#endif
return close(fd) || arg.ret == -1;
}
#undef PROF_LOG_STOP_BUFSIZE

View File

@@ -12,10 +12,6 @@ ssize_t opt_prof_recent_alloc_max = PROF_RECENT_ALLOC_MAX_DEFAULT;
malloc_mutex_t prof_recent_alloc_mtx; /* Protects the fields below */
static atomic_zd_t prof_recent_alloc_max;
static ssize_t prof_recent_alloc_count = 0;
#ifndef JEMALLOC_JET
typedef ql_head(prof_recent_t) prof_recent_list_t;
static
#endif
prof_recent_list_t prof_recent_alloc_list;
malloc_mutex_t prof_recent_dump_mtx; /* Protects dumping. */
@@ -104,14 +100,16 @@ decrement_recent_count(tsd_t *tsd, prof_tctx_t *tctx) {
prof_tctx_try_destroy(tsd, tctx);
}
#ifndef JEMALLOC_JET
static inline
#endif
edata_t *
static inline edata_t *
prof_recent_alloc_edata_get_no_lock(const prof_recent_t *n) {
return (edata_t *)atomic_load_p(&n->alloc_edata, ATOMIC_ACQUIRE);
}
edata_t *
prof_recent_alloc_edata_get_no_lock_test(const prof_recent_t *n) {
return prof_recent_alloc_edata_get_no_lock(n);
}
static inline edata_t *
prof_recent_alloc_edata_get(tsd_t *tsd, const prof_recent_t *n) {
malloc_mutex_assert_owner(tsd_tsdn(tsd), &prof_recent_alloc_mtx);
@@ -129,14 +127,16 @@ edata_prof_recent_alloc_init(edata_t *edata) {
edata_prof_recent_alloc_set_dont_call_directly(edata, NULL);
}
#ifndef JEMALLOC_JET
static inline
#endif
prof_recent_t *
static inline prof_recent_t *
edata_prof_recent_alloc_get_no_lock(const edata_t *edata) {
return edata_prof_recent_alloc_get_dont_call_directly(edata);
}
prof_recent_t *
edata_prof_recent_alloc_get_no_lock_test(const edata_t *edata) {
return edata_prof_recent_alloc_get_no_lock(edata);
}
static inline prof_recent_t *
edata_prof_recent_alloc_get(tsd_t *tsd, const edata_t *edata) {
malloc_mutex_assert_owner(tsd_tsdn(tsd), &prof_recent_alloc_mtx);