prof_log: cassert(config_prof) in public functions

This lets the compiler infer that the code is dead in builds where profiling is
enabled, saving on space there.
This commit is contained in:
David Goldblatt 2020-12-17 11:18:21 -08:00 committed by David Goldblatt
parent 526180b76d
commit 83cad746ae
2 changed files with 14 additions and 1 deletions

View File

@ -202,6 +202,7 @@ prof_log_thr_index(tsd_t *tsd, uint64_t thr_uid, const char *name) {
void void
prof_try_log(tsd_t *tsd, size_t usize, prof_info_t *prof_info) { prof_try_log(tsd_t *tsd, size_t usize, prof_info_t *prof_info) {
cassert(config_prof);
prof_tctx_t *tctx = prof_info->alloc_tctx; prof_tctx_t *tctx = prof_info->alloc_tctx;
malloc_mutex_assert_owner(tsd_tsdn(tsd), tctx->tdata->lock); malloc_mutex_assert_owner(tsd_tsdn(tsd), tctx->tdata->lock);
@ -307,6 +308,7 @@ prof_thr_node_keycomp(const void *k1, const void *k2) {
/* Used in unit tests. */ /* Used in unit tests. */
size_t size_t
prof_log_bt_count(void) { prof_log_bt_count(void) {
cassert(config_prof);
size_t cnt = 0; size_t cnt = 0;
prof_bt_node_t *node = log_bt_first; prof_bt_node_t *node = log_bt_first;
while (node != NULL) { while (node != NULL) {
@ -319,6 +321,7 @@ prof_log_bt_count(void) {
/* Used in unit tests. */ /* Used in unit tests. */
size_t size_t
prof_log_alloc_count(void) { prof_log_alloc_count(void) {
cassert(config_prof);
size_t cnt = 0; size_t cnt = 0;
prof_alloc_node_t *node = log_alloc_first; prof_alloc_node_t *node = log_alloc_first;
while (node != NULL) { while (node != NULL) {
@ -331,6 +334,7 @@ prof_log_alloc_count(void) {
/* Used in unit tests. */ /* Used in unit tests. */
size_t size_t
prof_log_thr_count(void) { prof_log_thr_count(void) {
cassert(config_prof);
size_t cnt = 0; size_t cnt = 0;
prof_thr_node_t *node = log_thr_first; prof_thr_node_t *node = log_thr_first;
while (node != NULL) { while (node != NULL) {
@ -343,12 +347,14 @@ prof_log_thr_count(void) {
/* Used in unit tests. */ /* Used in unit tests. */
bool bool
prof_log_is_logging(void) { prof_log_is_logging(void) {
cassert(config_prof);
return prof_logging_state == prof_logging_state_started; return prof_logging_state == prof_logging_state_started;
} }
/* Used in unit tests. */ /* Used in unit tests. */
bool bool
prof_log_rep_check(void) { prof_log_rep_check(void) {
cassert(config_prof);
if (prof_logging_state == prof_logging_state_stopped if (prof_logging_state == prof_logging_state_stopped
&& log_tables_initialized) { && log_tables_initialized) {
return true; return true;
@ -401,11 +407,14 @@ prof_log_rep_check(void) {
/* Used in unit tests. */ /* Used in unit tests. */
void void
prof_log_dummy_set(bool new_value) { prof_log_dummy_set(bool new_value) {
cassert(config_prof);
prof_log_dummy = new_value; prof_log_dummy = new_value;
} }
bool bool
prof_log_start(tsdn_t *tsdn, const char *filename) { prof_log_start(tsdn_t *tsdn, const char *filename) {
cassert(config_prof);
if (!opt_prof) { if (!opt_prof) {
return true; return true;
} }
@ -586,6 +595,7 @@ prof_log_emit_metadata(emitter_t *emitter) {
#define PROF_LOG_STOP_BUFSIZE PROF_DUMP_BUFSIZE #define PROF_LOG_STOP_BUFSIZE PROF_DUMP_BUFSIZE
bool bool
prof_log_stop(tsdn_t *tsdn) { prof_log_stop(tsdn_t *tsdn) {
cassert(config_prof);
if (!opt_prof || !prof_booted) { if (!opt_prof || !prof_booted) {
return true; return true;
} }
@ -672,6 +682,7 @@ prof_log_stop(tsdn_t *tsdn) {
#undef PROF_LOG_STOP_BUFSIZE #undef PROF_LOG_STOP_BUFSIZE
bool prof_log_init(tsd_t *tsd) { bool prof_log_init(tsd_t *tsd) {
cassert(config_prof);
if (malloc_mutex_init(&log_mtx, "prof_log", if (malloc_mutex_init(&log_mtx, "prof_log",
WITNESS_RANK_PROF_LOG, malloc_mutex_rank_exclusive)) { WITNESS_RANK_PROF_LOG, malloc_mutex_rank_exclusive)) {
return true; return true;

View File

@ -141,7 +141,9 @@ TEST_END
int int
main(void) { main(void) {
prof_log_dummy_set(true); if (config_prof) {
prof_log_dummy_set(true);
}
return test_no_reentrancy( return test_no_reentrancy(
test_prof_log_many_logs, test_prof_log_many_logs,
test_prof_log_many_traces, test_prof_log_many_traces,