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); size_t usize, prof_tctx_t *tctx);
void prof_free_sampled_object(tsd_t *tsd, size_t usize, prof_info_t *prof_info); 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); 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); int prof_getpid(void);
void prof_get_default_filename(tsdn_t *tsdn, char *filename, uint64_t ind); void prof_get_default_filename(tsdn_t *tsdn, char *filename, uint64_t ind);
void prof_idump(tsdn_t *tsdn); 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); uint64_t prof_sample_postponed_event_wait(tsd_t *tsd);
void prof_sample_event_handler(tsd_t *tsd, uint64_t elapsed); 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_start(tsdn_t *tsdn, const char *filename);
bool prof_log_stop(tsdn_t *tsdn); 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); void prof_try_log(tsd_t *tsd, size_t usize, prof_info_t *prof_info);
bool prof_log_init(tsd_t *tsdn); 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_bt_count(void);
size_t prof_log_alloc_count(void); size_t prof_log_alloc_count(void);
size_t prof_log_thr_count(void); size_t prof_log_thr_count(void);
bool prof_log_is_logging(void); bool prof_log_is_logging(void);
bool prof_log_rep_check(void); bool prof_log_rep_check(void);
void prof_log_dummy_set(bool new_value); void prof_log_dummy_set(bool new_value);
#endif
#endif /* JEMALLOC_INTERNAL_PROF_LOG_EXTERNS_H */ #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); void prof_recent_alloc_reset(tsd_t *tsd, edata_t *edata);
bool prof_recent_init(); bool prof_recent_init();
void edata_prof_recent_alloc_init(edata_t *edata); 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; typedef ql_head(prof_recent_t) prof_recent_list_t;
extern prof_recent_list_t prof_recent_alloc_list; extern prof_recent_list_t prof_recent_alloc_list;
edata_t *prof_recent_alloc_edata_get_no_lock(const prof_recent_t *node); 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(const edata_t *edata); prof_recent_t *edata_prof_recent_alloc_get_no_lock_test(const edata_t *edata);
#endif
#endif /* JEMALLOC_INTERNAL_PROF_RECENT_EXTERNS_H */ #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; return ENOSYS;
#endif #endif
} }
#ifdef JEMALLOC_JET
prof_read_sys_thread_name_t *JET_MUTABLE prof_read_sys_thread_name = prof_read_sys_thread_name_t *JET_MUTABLE prof_read_sys_thread_name =
prof_read_sys_thread_name_impl; prof_read_sys_thread_name_impl;
#else
#define prof_read_sys_thread_name prof_read_sys_thread_name_impl
#endif
static void static void
prof_fetch_sys_thread_name(tsd_t *tsd) { 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); return prof_lookup(tsd, &bt);
} }
#ifdef JEMALLOC_JET /* Used in unit tests. */
static prof_tdata_t * static prof_tdata_t *
prof_tdata_count_iter(prof_tdata_tree_t *tdatas, prof_tdata_t *tdata, prof_tdata_count_iter(prof_tdata_tree_t *tdatas, prof_tdata_t *tdata,
void *arg) { void *arg) {
@ -432,6 +432,7 @@ prof_tdata_count_iter(prof_tdata_tree_t *tdatas, prof_tdata_t *tdata,
return NULL; return NULL;
} }
/* Used in unit tests. */
size_t size_t
prof_tdata_count(void) { prof_tdata_count(void) {
size_t tdata_count = 0; size_t tdata_count = 0;
@ -446,6 +447,7 @@ prof_tdata_count(void) {
return tdata_count; return tdata_count;
} }
/* Used in unit tests. */
size_t size_t
prof_bt_count(void) { prof_bt_count(void) {
size_t bt_count; size_t bt_count;
@ -464,7 +466,6 @@ prof_bt_count(void) {
return bt_count; return bt_count;
} }
#endif
static int static int
prof_dump_open_impl(bool propagate_err, const char *filename) { 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; return false;
} }
#ifdef JEMALLOC_JET /* Used in unit tests. */
void void
prof_cnt_all(uint64_t *curobjs, uint64_t *curbytes, uint64_t *accumobjs, prof_cnt_all(uint64_t *curobjs, uint64_t *curbytes, uint64_t *accumobjs,
uint64_t *accumbytes) { 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; *accumbytes = prof_tdata_merge_iter_arg.cnt_all.accumbytes;
} }
} }
#endif
void void
prof_bt_hash(const void *key, size_t r_hash[2]) { 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; prof_logging_state_t prof_logging_state = prof_logging_state_stopped;
#ifdef JEMALLOC_JET /* Used in unit tests. */
static bool prof_log_dummy = false; static bool prof_log_dummy = false;
#endif
/* Incremented for every log file that is output. */ /* Incremented for every log file that is output. */
static uint64_t log_seq = 0; 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; return thr_node1->thr_uid == thr_node2->thr_uid;
} }
#ifdef JEMALLOC_JET /* Used in unit tests. */
size_t size_t
prof_log_bt_count(void) { prof_log_bt_count(void) {
size_t cnt = 0; size_t cnt = 0;
@ -317,6 +316,7 @@ prof_log_bt_count(void) {
return cnt; return cnt;
} }
/* Used in unit tests. */
size_t size_t
prof_log_alloc_count(void) { prof_log_alloc_count(void) {
size_t cnt = 0; size_t cnt = 0;
@ -328,6 +328,7 @@ prof_log_alloc_count(void) {
return cnt; return cnt;
} }
/* Used in unit tests. */
size_t size_t
prof_log_thr_count(void) { prof_log_thr_count(void) {
size_t cnt = 0; size_t cnt = 0;
@ -339,11 +340,13 @@ prof_log_thr_count(void) {
return cnt; return cnt;
} }
/* Used in unit tests. */
bool bool
prof_log_is_logging(void) { prof_log_is_logging(void) {
return prof_logging_state == prof_logging_state_started; return prof_logging_state == prof_logging_state_started;
} }
/* Used in unit tests. */
bool bool
prof_log_rep_check(void) { prof_log_rep_check(void) {
if (prof_logging_state == prof_logging_state_stopped if (prof_logging_state == prof_logging_state_stopped
@ -395,11 +398,11 @@ prof_log_rep_check(void) {
return false; return false;
} }
/* Used in unit tests. */
void void
prof_log_dummy_set(bool new_value) { prof_log_dummy_set(bool new_value) {
prof_log_dummy = new_value; prof_log_dummy = new_value;
} }
#endif
bool bool
prof_log_start(tsdn_t *tsdn, const char *filename) { 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 *arg =
(struct prof_emitter_cb_arg_s *)opaque; (struct prof_emitter_cb_arg_s *)opaque;
size_t bytes = strlen(to_write); size_t bytes = strlen(to_write);
#ifdef JEMALLOC_JET
if (prof_log_dummy) { if (prof_log_dummy) {
return; return;
} }
#endif
arg->ret = malloc_write_fd(arg->fd, to_write, bytes); arg->ret = malloc_write_fd(arg->fd, to_write, bytes);
} }
@ -612,15 +613,11 @@ prof_log_stop(tsdn_t *tsdn) {
/* Create a file. */ /* Create a file. */
int fd; int fd;
#ifdef JEMALLOC_JET
if (prof_log_dummy) { if (prof_log_dummy) {
fd = 0; fd = 0;
} else { } else {
fd = creat(log_filename, 0644); fd = creat(log_filename, 0644);
} }
#else
fd = creat(log_filename, 0644);
#endif
if (fd == -1) { if (fd == -1) {
malloc_printf("<jemalloc>: creat() for log file \"%s\" " 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; prof_logging_state = prof_logging_state_stopped;
malloc_mutex_unlock(tsdn, &log_mtx); malloc_mutex_unlock(tsdn, &log_mtx);
#ifdef JEMALLOC_JET
if (prof_log_dummy) { if (prof_log_dummy) {
return false; return false;
} }
#endif
return close(fd) || arg.ret == -1; return close(fd) || arg.ret == -1;
} }
#undef PROF_LOG_STOP_BUFSIZE #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 */ malloc_mutex_t prof_recent_alloc_mtx; /* Protects the fields below */
static atomic_zd_t prof_recent_alloc_max; static atomic_zd_t prof_recent_alloc_max;
static ssize_t prof_recent_alloc_count = 0; 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; prof_recent_list_t prof_recent_alloc_list;
malloc_mutex_t prof_recent_dump_mtx; /* Protects dumping. */ 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); prof_tctx_try_destroy(tsd, tctx);
} }
#ifndef JEMALLOC_JET static inline edata_t *
static inline
#endif
edata_t *
prof_recent_alloc_edata_get_no_lock(const prof_recent_t *n) { prof_recent_alloc_edata_get_no_lock(const prof_recent_t *n) {
return (edata_t *)atomic_load_p(&n->alloc_edata, ATOMIC_ACQUIRE); 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 * static inline edata_t *
prof_recent_alloc_edata_get(tsd_t *tsd, const prof_recent_t *n) { prof_recent_alloc_edata_get(tsd_t *tsd, const prof_recent_t *n) {
malloc_mutex_assert_owner(tsd_tsdn(tsd), &prof_recent_alloc_mtx); 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); edata_prof_recent_alloc_set_dont_call_directly(edata, NULL);
} }
#ifndef JEMALLOC_JET static inline prof_recent_t *
static inline
#endif
prof_recent_t *
edata_prof_recent_alloc_get_no_lock(const edata_t *edata) { edata_prof_recent_alloc_get_no_lock(const edata_t *edata) {
return edata_prof_recent_alloc_get_dont_call_directly(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 * static inline prof_recent_t *
edata_prof_recent_alloc_get(tsd_t *tsd, const edata_t *edata) { edata_prof_recent_alloc_get(tsd_t *tsd, const edata_t *edata) {
malloc_mutex_assert_owner(tsd_tsdn(tsd), &prof_recent_alloc_mtx); 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"); assert_ptr_not_null(p, "malloc failed unexpectedly");
edata_t *e = emap_edata_lookup(TSDN_NULL, &arena_emap_global, p); edata_t *e = emap_edata_lookup(TSDN_NULL, &arena_emap_global, p);
assert_ptr_not_null(e, "NULL edata for living pointer"); 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"); assert_ptr_not_null(n, "Record in edata should not be NULL");
expect_ptr_not_null(n->alloc_tctx, expect_ptr_not_null(n->alloc_tctx,
"alloc_tctx in record should not be NULL"); "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"); "edata pointer in record is not correct");
expect_ptr_null(n->dalloc_tctx, "dalloc_tctx in record should be NULL"); 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) { confirm_record_living(prof_recent_t *n) {
expect_ptr_not_null(n->alloc_tctx, expect_ptr_not_null(n->alloc_tctx,
"alloc_tctx in record should not be NULL"); "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, assert_ptr_not_null(edata,
"Recorded edata should not be NULL for living pointer"); "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"); "Record in edata is not correct");
expect_ptr_null(n->dalloc_tctx, "dalloc_tctx in record should be NULL"); 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) { confirm_record_released(prof_recent_t *n) {
expect_ptr_not_null(n->alloc_tctx, expect_ptr_not_null(n->alloc_tctx,
"alloc_tctx in record should not be NULL"); "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"); "Recorded edata should be NULL for released pointer");
expect_ptr_not_null(n->dalloc_tctx, expect_ptr_not_null(n->dalloc_tctx,
"dalloc_tctx in record should not be NULL for released pointer"); "dalloc_tctx in record should not be NULL for released pointer");