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

@ -57,21 +57,6 @@ void prof_malloc_sample_object(tsd_t *tsd, const void *ptr, size_t size,
size_t usize, prof_tctx_t *tctx);
void prof_free_sampled_object(tsd_t *tsd, size_t usize, prof_info_t *prof_info);
prof_tctx_t *prof_tctx_create(tsd_t *tsd);
#ifdef JEMALLOC_JET
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;
size_t prof_tdata_count(void);
size_t prof_bt_count(void);
#endif
typedef int (prof_dump_open_t)(bool, const char *);
extern prof_dump_open_t *JET_MUTABLE prof_dump_open;
typedef bool (prof_dump_header_t)(tsdn_t *, bool, const prof_cnt_t *);
extern prof_dump_header_t *JET_MUTABLE prof_dump_header;
#ifdef JEMALLOC_JET
void prof_cnt_all(uint64_t *curobjs, uint64_t *curbytes, uint64_t *accumobjs,
uint64_t *accumbytes);
#endif
int prof_getpid(void);
void prof_get_default_filename(tsdn_t *tsdn, char *filename, uint64_t ind);
void prof_idump(tsdn_t *tsdn);
@ -104,6 +89,18 @@ uint64_t prof_sample_new_event_wait(tsd_t *tsd);
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;
size_t prof_tdata_count(void);
size_t prof_bt_count(void);
typedef int (prof_dump_open_t)(bool, const char *);
extern prof_dump_open_t *JET_MUTABLE prof_dump_open;
typedef bool (prof_dump_header_t)(tsdn_t *, bool, const prof_cnt_t *);
extern prof_dump_header_t *JET_MUTABLE prof_dump_header;
void prof_cnt_all(uint64_t *curobjs, uint64_t *curbytes, uint64_t *accumobjs,
uint64_t *accumbytes);
bool prof_log_start(tsdn_t *tsdn, const char *filename);
bool prof_log_stop(tsdn_t *tsdn);

View File

@ -7,13 +7,13 @@ extern malloc_mutex_t log_mtx;
void prof_try_log(tsd_t *tsd, size_t usize, prof_info_t *prof_info);
bool prof_log_init(tsd_t *tsdn);
#ifdef JEMALLOC_JET
/* Used in unit tests. */
size_t prof_log_bt_count(void);
size_t prof_log_alloc_count(void);
size_t prof_log_thr_count(void);
bool prof_log_is_logging(void);
bool prof_log_rep_check(void);
void prof_log_dummy_set(bool new_value);
#endif
#endif /* JEMALLOC_INTERNAL_PROF_LOG_EXTERNS_H */

View File

@ -8,11 +8,11 @@ void prof_recent_alloc(tsd_t *tsd, edata_t *edata, size_t size);
void prof_recent_alloc_reset(tsd_t *tsd, edata_t *edata);
bool prof_recent_init();
void edata_prof_recent_alloc_init(edata_t *edata);
#ifdef JEMALLOC_JET
/* Used in unit tests. */
typedef ql_head(prof_recent_t) prof_recent_list_t;
extern prof_recent_list_t prof_recent_alloc_list;
edata_t *prof_recent_alloc_edata_get_no_lock(const prof_recent_t *node);
prof_recent_t *edata_prof_recent_alloc_get_no_lock(const edata_t *edata);
#endif
edata_t *prof_recent_alloc_edata_get_no_lock_test(const prof_recent_t *node);
prof_recent_t *edata_prof_recent_alloc_get_no_lock_test(const edata_t *edata);
#endif /* JEMALLOC_INTERNAL_PROF_RECENT_EXTERNS_H */

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);

View File

@ -103,11 +103,11 @@ confirm_malloc(void *p) {
assert_ptr_not_null(p, "malloc failed unexpectedly");
edata_t *e = emap_edata_lookup(TSDN_NULL, &arena_emap_global, p);
assert_ptr_not_null(e, "NULL edata for living pointer");
prof_recent_t *n = edata_prof_recent_alloc_get_no_lock(e);
prof_recent_t *n = edata_prof_recent_alloc_get_no_lock_test(e);
assert_ptr_not_null(n, "Record in edata should not be NULL");
expect_ptr_not_null(n->alloc_tctx,
"alloc_tctx in record should not be NULL");
expect_ptr_eq(e, prof_recent_alloc_edata_get_no_lock(n),
expect_ptr_eq(e, prof_recent_alloc_edata_get_no_lock_test(n),
"edata pointer in record is not correct");
expect_ptr_null(n->dalloc_tctx, "dalloc_tctx in record should be NULL");
}
@ -122,10 +122,10 @@ static void
confirm_record_living(prof_recent_t *n) {
expect_ptr_not_null(n->alloc_tctx,
"alloc_tctx in record should not be NULL");
edata_t *edata = prof_recent_alloc_edata_get_no_lock(n);
edata_t *edata = prof_recent_alloc_edata_get_no_lock_test(n);
assert_ptr_not_null(edata,
"Recorded edata should not be NULL for living pointer");
expect_ptr_eq(n, edata_prof_recent_alloc_get_no_lock(edata),
expect_ptr_eq(n, edata_prof_recent_alloc_get_no_lock_test(edata),
"Record in edata is not correct");
expect_ptr_null(n->dalloc_tctx, "dalloc_tctx in record should be NULL");
}
@ -134,7 +134,7 @@ static void
confirm_record_released(prof_recent_t *n) {
expect_ptr_not_null(n->alloc_tctx,
"alloc_tctx in record should not be NULL");
expect_ptr_null(prof_recent_alloc_edata_get_no_lock(n),
expect_ptr_null(prof_recent_alloc_edata_get_no_lock_test(n),
"Recorded edata should be NULL for released pointer");
expect_ptr_not_null(n->dalloc_tctx,
"dalloc_tctx in record should not be NULL for released pointer");