Refactor profiling headers
This commit is contained in:
parent
6342da0970
commit
ea42174d07
22
include/jemalloc/internal/prof_data_externs.h
Normal file
22
include/jemalloc/internal/prof_data_externs.h
Normal file
@ -0,0 +1,22 @@
|
||||
#ifndef JEMALLOC_INTERNAL_PROF_DATA_EXTERNS_H
|
||||
#define JEMALLOC_INTERNAL_PROF_DATA_EXTERNS_H
|
||||
|
||||
#include "jemalloc/internal/mutex.h"
|
||||
|
||||
extern malloc_mutex_t *gctx_locks;
|
||||
extern malloc_mutex_t *tdata_locks;
|
||||
|
||||
void prof_bt_hash(const void *key, size_t r_hash[2]);
|
||||
bool prof_bt_keycomp(const void *k1, const void *k2);
|
||||
|
||||
bool prof_data_init(tsd_t *tsd);
|
||||
bool prof_dump(tsd_t *tsd, bool propagate_err, const char *filename,
|
||||
bool leakcheck);
|
||||
prof_tdata_t * prof_tdata_init_impl(tsd_t *tsd, uint64_t thr_uid,
|
||||
uint64_t thr_discrim, char *thread_name, bool active, bool reset_interval);
|
||||
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_tctx_try_destroy(tsd_t *tsd, prof_tctx_t *tctx);
|
||||
|
||||
#endif /* JEMALLOC_INTERNAL_PROF_DATA_EXTERNS_H */
|
@ -7,9 +7,6 @@ extern malloc_mutex_t bt2gctx_mtx;
|
||||
extern malloc_mutex_t tdatas_mtx;
|
||||
extern malloc_mutex_t prof_dump_mtx;
|
||||
|
||||
malloc_mutex_t *prof_gctx_mutex_choose(void);
|
||||
malloc_mutex_t *prof_tdata_mutex_choose(uint64_t thr_uid);
|
||||
|
||||
extern bool opt_prof;
|
||||
extern bool opt_prof_active;
|
||||
extern bool opt_prof_thread_active_init;
|
||||
@ -48,12 +45,14 @@ extern bool prof_booted;
|
||||
bool prof_idump_accum_impl(tsdn_t *tsdn, uint64_t accumbytes);
|
||||
void prof_idump_rollback_impl(tsdn_t *tsdn, size_t usize);
|
||||
|
||||
/* Functions only accessed in prof_inlines_b.h */
|
||||
prof_tdata_t *prof_tdata_init(tsd_t *tsd);
|
||||
prof_tdata_t *prof_tdata_reinit(tsd_t *tsd, prof_tdata_t *tdata);
|
||||
|
||||
void prof_alloc_rollback(tsd_t *tsd, prof_tctx_t *tctx, bool updated);
|
||||
void prof_malloc_sample_object(tsd_t *tsd, const void *ptr, size_t usize,
|
||||
prof_tctx_t *tctx);
|
||||
void prof_free_sampled_object(tsd_t *tsd, size_t usize, prof_info_t *prof_info);
|
||||
void bt_init(prof_bt_t *bt, void **vec);
|
||||
void prof_backtrace(tsd_t *tsd, prof_bt_t *bt);
|
||||
prof_tctx_t *prof_tctx_create(tsd_t *tsd);
|
||||
#ifdef JEMALLOC_JET
|
||||
size_t prof_tdata_count(void);
|
||||
@ -76,10 +75,6 @@ bool prof_mdump(tsd_t *tsd, const char *filename);
|
||||
void prof_gdump(tsdn_t *tsdn);
|
||||
bool prof_dump_prefix_set(tsdn_t *tsdn, const char *prefix);
|
||||
|
||||
void prof_bt_hash(const void *key, size_t r_hash[2]);
|
||||
bool prof_bt_keycomp(const void *k1, const void *k2);
|
||||
prof_tdata_t *prof_tdata_init(tsd_t *tsd);
|
||||
prof_tdata_t *prof_tdata_reinit(tsd_t *tsd, prof_tdata_t *tdata);
|
||||
void prof_reset(tsd_t *tsd, size_t lg_sample);
|
||||
void prof_tdata_cleanup(tsd_t *tsd);
|
||||
bool prof_active_get(tsdn_t *tsdn);
|
||||
@ -101,26 +96,7 @@ void prof_postfork_parent(tsdn_t *tsdn);
|
||||
void prof_postfork_child(tsdn_t *tsdn);
|
||||
void prof_sample_threshold_update(tsd_t *tsd);
|
||||
|
||||
void prof_try_log(tsd_t *tsd, size_t usize, prof_info_t *prof_info);
|
||||
bool prof_log_start(tsdn_t *tsdn, const char *filename);
|
||||
bool prof_log_stop(tsdn_t *tsdn);
|
||||
bool prof_log_init(tsd_t *tsdn);
|
||||
#ifdef JEMALLOC_JET
|
||||
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
|
||||
|
||||
/* Functions in prof_data.c only used in profiling code. */
|
||||
bool prof_data_init(tsd_t *tsd);
|
||||
bool prof_dump(tsd_t *tsd, bool propagate_err, const char *filename,
|
||||
bool leakcheck);
|
||||
prof_tdata_t * prof_tdata_init_impl(tsd_t *tsd, uint64_t thr_uid,
|
||||
uint64_t thr_discrim, char *thread_name, bool active, bool reset_interval);
|
||||
void prof_tdata_detach(tsd_t *tsd, prof_tdata_t *tdata);
|
||||
void prof_tctx_try_destroy(tsd_t *tsd, prof_tctx_t *tctx);
|
||||
|
||||
#endif /* JEMALLOC_INTERNAL_PROF_EXTERNS_H */
|
||||
|
17
include/jemalloc/internal/prof_log_externs.h
Normal file
17
include/jemalloc/internal/prof_log_externs.h
Normal file
@ -0,0 +1,17 @@
|
||||
#ifndef JEMALLOC_INTERNAL_PROF_LOG_EXTERNS_H
|
||||
#define JEMALLOC_INTERNAL_PROF_LOG_EXTERNS_H
|
||||
|
||||
#include "jemalloc/internal/mutex.h"
|
||||
|
||||
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
|
||||
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 */
|
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;
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "test/jemalloc_test.h"
|
||||
#include "jemalloc/internal/prof_log_externs.h"
|
||||
|
||||
#define N_PARAM 100
|
||||
#define N_THREADS 10
|
||||
|
Loading…
Reference in New Issue
Block a user