From d128efcb6aeddec8d3f1220eda0251dcaa25bab8 Mon Sep 17 00:00:00 2001 From: Yinan Zhang Date: Fri, 3 Apr 2020 10:26:03 -0700 Subject: [PATCH] Relocate a few prof utilities to the right modules --- include/jemalloc/internal/prof_data.h | 5 +++++ include/jemalloc/internal/prof_externs.h | 14 -------------- include/jemalloc/internal/prof_log.h | 3 +++ include/jemalloc/internal/prof_recent.h | 5 +++++ include/jemalloc/internal/prof_sys.h | 1 + src/ctl.c | 3 +++ src/prof.c | 16 ---------------- src/prof_data.c | 4 ++++ src/prof_sys.c | 9 +++++++++ 9 files changed, 30 insertions(+), 30 deletions(-) diff --git a/include/jemalloc/internal/prof_data.h b/include/jemalloc/internal/prof_data.h index 5c3f129f..de9f7bae 100644 --- a/include/jemalloc/internal/prof_data.h +++ b/include/jemalloc/internal/prof_data.h @@ -3,6 +3,10 @@ #include "jemalloc/internal/mutex.h" +extern malloc_mutex_t bt2gctx_mtx; +extern malloc_mutex_t tdatas_mtx; +extern malloc_mutex_t prof_dump_mtx; + extern malloc_mutex_t *gctx_locks; extern malloc_mutex_t *tdata_locks; @@ -19,6 +23,7 @@ prof_tdata_t * prof_tdata_init_impl(tsd_t *tsd, uint64_t thr_uid, void prof_tdata_detach(tsd_t *tsd, prof_tdata_t *tdata); void bt_init(prof_bt_t *bt, void **vec); void prof_backtrace(tsd_t *tsd, prof_bt_t *bt); +void prof_reset(tsd_t *tsd, size_t lg_sample); void prof_tctx_try_destroy(tsd_t *tsd, prof_tctx_t *tctx); /* Used in unit tests. */ diff --git a/include/jemalloc/internal/prof_externs.h b/include/jemalloc/internal/prof_externs.h index c7c3ccbe..a4a4aa61 100644 --- a/include/jemalloc/internal/prof_externs.h +++ b/include/jemalloc/internal/prof_externs.h @@ -3,10 +3,6 @@ #include "jemalloc/internal/mutex.h" -extern malloc_mutex_t bt2gctx_mtx; -extern malloc_mutex_t tdatas_mtx; -extern malloc_mutex_t prof_dump_mtx; - extern bool opt_prof; extern bool opt_prof_active; extern bool opt_prof_thread_active_init; @@ -26,7 +22,6 @@ extern char opt_prof_prefix[ /* For recording recent allocations */ extern ssize_t opt_prof_recent_alloc_max; -extern malloc_mutex_t prof_recent_alloc_mtx; /* Whether to use thread name provided by the system or by mallctl. */ extern bool opt_prof_sys_thread_name; @@ -57,12 +52,10 @@ 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); -int prof_getpid(void); void prof_idump(tsdn_t *tsdn); bool prof_mdump(tsd_t *tsd, const char *filename); void prof_gdump(tsdn_t *tsdn); -void prof_reset(tsd_t *tsd, size_t lg_sample); void prof_tdata_cleanup(tsd_t *tsd); bool prof_active_get(tsdn_t *tsdn); bool prof_active_set(tsdn_t *tsdn, bool active); @@ -87,11 +80,4 @@ 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); -bool prof_log_start(tsdn_t *tsdn, const char *filename); -bool prof_log_stop(tsdn_t *tsdn); - -ssize_t prof_recent_alloc_max_ctl_read(); -ssize_t prof_recent_alloc_max_ctl_write(tsd_t *tsd, ssize_t max); -void prof_recent_alloc_dump(tsd_t *tsd, write_cb_t *write_cb, void *cbopaque); - #endif /* JEMALLOC_INTERNAL_PROF_EXTERNS_H */ diff --git a/include/jemalloc/internal/prof_log.h b/include/jemalloc/internal/prof_log.h index e833ced7..ccb557dd 100644 --- a/include/jemalloc/internal/prof_log.h +++ b/include/jemalloc/internal/prof_log.h @@ -16,4 +16,7 @@ bool prof_log_is_logging(void); bool prof_log_rep_check(void); void prof_log_dummy_set(bool new_value); +bool prof_log_start(tsdn_t *tsdn, const char *filename); +bool prof_log_stop(tsdn_t *tsdn); + #endif /* JEMALLOC_INTERNAL_PROF_LOG_H */ diff --git a/include/jemalloc/internal/prof_recent.h b/include/jemalloc/internal/prof_recent.h index 4f376c7b..d793c6da 100644 --- a/include/jemalloc/internal/prof_recent.h +++ b/include/jemalloc/internal/prof_recent.h @@ -1,6 +1,7 @@ #ifndef JEMALLOC_INTERNAL_PROF_RECENT_H #define JEMALLOC_INTERNAL_PROF_RECENT_H +extern malloc_mutex_t prof_recent_alloc_mtx; extern malloc_mutex_t prof_recent_dump_mtx; bool prof_recent_alloc_prepare(tsd_t *tsd, prof_tctx_t *tctx); @@ -15,4 +16,8 @@ extern prof_recent_list_t prof_recent_alloc_list; 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); +ssize_t prof_recent_alloc_max_ctl_read(); +ssize_t prof_recent_alloc_max_ctl_write(tsd_t *tsd, ssize_t max); +void prof_recent_alloc_dump(tsd_t *tsd, write_cb_t *write_cb, void *cbopaque); + #endif /* JEMALLOC_INTERNAL_PROF_RECENT_H */ diff --git a/include/jemalloc/internal/prof_sys.h b/include/jemalloc/internal/prof_sys.h index 0d97cb99..3896f292 100644 --- a/include/jemalloc/internal/prof_sys.h +++ b/include/jemalloc/internal/prof_sys.h @@ -5,6 +5,7 @@ extern malloc_mutex_t prof_dump_filename_mtx; extern base_t *prof_base; void prof_sys_thread_name_fetch(tsd_t *tsd); +int prof_getpid(void); void prof_get_default_filename(tsdn_t *tsdn, char *filename, uint64_t ind); bool prof_dump_prefix_set(tsdn_t *tsdn, const char *prefix); void prof_fdump_impl(tsd_t *tsd); diff --git a/src/ctl.c b/src/ctl.c index fe0b9f99..8b9f42ec 100644 --- a/src/ctl.c +++ b/src/ctl.c @@ -9,6 +9,9 @@ #include "jemalloc/internal/mutex.h" #include "jemalloc/internal/nstime.h" #include "jemalloc/internal/peak_event.h" +#include "jemalloc/internal/prof_data.h" +#include "jemalloc/internal/prof_log.h" +#include "jemalloc/internal/prof_recent.h" #include "jemalloc/internal/prof_sys.h" #include "jemalloc/internal/sc.h" #include "jemalloc/internal/util.h" diff --git a/src/prof.c b/src/prof.c index 7732edea..50c08fa3 100644 --- a/src/prof.c +++ b/src/prof.c @@ -78,16 +78,9 @@ uint64_t prof_interval = 0; size_t lg_prof_sample; -/* Non static to enable profiling. */ -malloc_mutex_t bt2gctx_mtx; - -malloc_mutex_t tdatas_mtx; - static uint64_t next_thr_uid; static malloc_mutex_t next_thr_uid_mtx; -malloc_mutex_t prof_dump_mtx; - /* Do not dump any profiles until bootstrapping is complete. */ bool prof_booted = false; @@ -473,15 +466,6 @@ prof_sample_event_handler(tsd_t *tsd, uint64_t elapsed) { } } -int -prof_getpid(void) { -#ifdef _WIN32 - return GetCurrentProcessId(); -#else - return getpid(); -#endif -} - static void prof_fdump(void) { tsd_t *tsd; diff --git a/src/prof_data.c b/src/prof_data.c index 80772292..6e84e3cf 100644 --- a/src/prof_data.c +++ b/src/prof_data.c @@ -25,6 +25,10 @@ /******************************************************************************/ +malloc_mutex_t bt2gctx_mtx; +malloc_mutex_t tdatas_mtx; +malloc_mutex_t prof_dump_mtx; + /* * Table of mutexes that are shared among gctx's. These are leaf locks, so * there is no problem with using them for more than one gctx at the same time. diff --git a/src/prof_sys.c b/src/prof_sys.c index 364c315a..cdec9262 100644 --- a/src/prof_sys.c +++ b/src/prof_sys.c @@ -61,6 +61,15 @@ prof_sys_thread_name_fetch(tsd_t *tsd) { #undef THREAD_NAME_MAX_LEN } +int +prof_getpid(void) { +#ifdef _WIN32 + return GetCurrentProcessId(); +#else + return getpid(); +#endif +} + static void prof_dump_check_possible_error(bool err_cond, const char *format, ...) { assert(!prof_dump_error);