Refactor profiling headers
This commit is contained in:
32
src/prof.c
32
src/prof.c
@@ -5,6 +5,8 @@
|
||||
#include "jemalloc/internal/ctl.h"
|
||||
#include "jemalloc/internal/assert.h"
|
||||
#include "jemalloc/internal/mutex.h"
|
||||
#include "jemalloc/internal/prof_data_externs.h"
|
||||
#include "jemalloc/internal/prof_log_externs.h"
|
||||
#include "jemalloc/internal/thread_event.h"
|
||||
|
||||
/*
|
||||
@@ -73,24 +75,6 @@ uint64_t prof_interval = 0;
|
||||
|
||||
size_t lg_prof_sample;
|
||||
|
||||
/*
|
||||
* 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.
|
||||
* The primary motivation for this sharing though is that gctx's are ephemeral,
|
||||
* and destroying mutexes causes complications for systems that allocate when
|
||||
* creating/destroying mutexes.
|
||||
*/
|
||||
static malloc_mutex_t *gctx_locks;
|
||||
static atomic_u_t cum_gctxs; /* Atomic counter. */
|
||||
|
||||
/*
|
||||
* Table of mutexes that are shared among tdata's. No operations require
|
||||
* holding multiple tdata locks, so there is no problem with using them for more
|
||||
* than one tdata at the same time, even though a gctx lock may be acquired
|
||||
* while holding a tdata lock.
|
||||
*/
|
||||
static malloc_mutex_t *tdata_locks;
|
||||
|
||||
/* Non static to enable profiling. */
|
||||
malloc_mutex_t bt2gctx_mtx;
|
||||
|
||||
@@ -431,18 +415,6 @@ prof_backtrace(tsd_t *tsd, prof_bt_t *bt) {
|
||||
post_reentrancy(tsd);
|
||||
}
|
||||
|
||||
malloc_mutex_t *
|
||||
prof_gctx_mutex_choose(void) {
|
||||
unsigned ngctxs = atomic_fetch_add_u(&cum_gctxs, 1, ATOMIC_RELAXED);
|
||||
|
||||
return &gctx_locks[(ngctxs - 1) % PROF_NCTX_LOCKS];
|
||||
}
|
||||
|
||||
malloc_mutex_t *
|
||||
prof_tdata_mutex_choose(uint64_t thr_uid) {
|
||||
return &tdata_locks[thr_uid % PROF_NTDATA_LOCKS];
|
||||
}
|
||||
|
||||
/*
|
||||
* The bodies of this function and prof_leakcheck() are compiled out unless heap
|
||||
* profiling is enabled, so that it is possible to compile jemalloc with
|
||||
|
@@ -6,6 +6,7 @@
|
||||
#include "jemalloc/internal/ckh.h"
|
||||
#include "jemalloc/internal/hash.h"
|
||||
#include "jemalloc/internal/malloc_io.h"
|
||||
#include "jemalloc/internal/prof_data_externs.h"
|
||||
|
||||
/*
|
||||
* This file defines and manages the core profiling data structures.
|
||||
@@ -25,6 +26,24 @@
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
/*
|
||||
* 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.
|
||||
* The primary motivation for this sharing though is that gctx's are ephemeral,
|
||||
* and destroying mutexes causes complications for systems that allocate when
|
||||
* creating/destroying mutexes.
|
||||
*/
|
||||
malloc_mutex_t *gctx_locks;
|
||||
static atomic_u_t cum_gctxs; /* Atomic counter. */
|
||||
|
||||
/*
|
||||
* Table of mutexes that are shared among tdata's. No operations require
|
||||
* holding multiple tdata locks, so there is no problem with using them for more
|
||||
* than one tdata at the same time, even though a gctx lock may be acquired
|
||||
* while holding a tdata lock.
|
||||
*/
|
||||
malloc_mutex_t *tdata_locks;
|
||||
|
||||
/*
|
||||
* Global hash of (prof_bt_t *)-->(prof_gctx_t *). This is the master data
|
||||
* structure that knows about all backtraces currently captured.
|
||||
@@ -114,6 +133,18 @@ rb_gen(static UNUSED, tdata_tree_, prof_tdata_tree_t, prof_tdata_t, tdata_link,
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
static malloc_mutex_t *
|
||||
prof_gctx_mutex_choose(void) {
|
||||
unsigned ngctxs = atomic_fetch_add_u(&cum_gctxs, 1, ATOMIC_RELAXED);
|
||||
|
||||
return &gctx_locks[(ngctxs - 1) % PROF_NCTX_LOCKS];
|
||||
}
|
||||
|
||||
static malloc_mutex_t *
|
||||
prof_tdata_mutex_choose(uint64_t thr_uid) {
|
||||
return &tdata_locks[thr_uid % PROF_NTDATA_LOCKS];
|
||||
}
|
||||
|
||||
bool
|
||||
prof_data_init(tsd_t *tsd) {
|
||||
tdata_tree_new(&tdatas);
|
||||
|
@@ -4,10 +4,12 @@
|
||||
|
||||
#include "jemalloc/internal/assert.h"
|
||||
#include "jemalloc/internal/ckh.h"
|
||||
#include "jemalloc/internal/emitter.h"
|
||||
#include "jemalloc/internal/hash.h"
|
||||
#include "jemalloc/internal/malloc_io.h"
|
||||
#include "jemalloc/internal/mutex.h"
|
||||
#include "jemalloc/internal/emitter.h"
|
||||
#include "jemalloc/internal/prof_data_externs.h"
|
||||
#include "jemalloc/internal/prof_log_externs.h"
|
||||
|
||||
bool opt_prof_log = false;
|
||||
typedef enum prof_logging_state_e prof_logging_state_t;
|
||||
|
Reference in New Issue
Block a user