2 #ifdef JEMALLOC_H_TYPES
4 typedef struct prof_bt_s prof_bt_t;
5 typedef struct prof_cnt_s prof_cnt_t;
6 typedef struct prof_thr_cnt_s prof_thr_cnt_t;
7 typedef struct prof_ctx_s prof_ctx_t;
8 typedef struct prof_tdata_s prof_tdata_t;
12 # define PROF_PREFIX_DEFAULT "jeprof"
14 # define PROF_PREFIX_DEFAULT ""
16 #define LG_PROF_SAMPLE_DEFAULT 19
17 #define LG_PROF_INTERVAL_DEFAULT -1
24 #define PROF_BT_MAX 128
27 #define PROF_TCMAX 1024
30 #define PROF_CKH_MINITEMS 64
33 #define PROF_DUMP_BUFSIZE 65536
36 #define PROF_PRINTF_BUFSIZE 128
42 #define PROF_NCTX_LOCKS 1024
48 #define PROF_TDATA_STATE_REINCARNATED ((prof_tdata_t *)(uintptr_t)1)
49 #define PROF_TDATA_STATE_PURGATORY ((prof_tdata_t *)(uintptr_t)2)
50 #define PROF_TDATA_STATE_MAX PROF_TDATA_STATE_PURGATORY
54 #ifdef JEMALLOC_H_STRUCTS
62 #ifdef JEMALLOC_PROF_LIBGCC
87 struct prof_thr_cnt_s {
89 ql_elm(prof_thr_cnt_t) cnts_link;
92 ql_elm(prof_thr_cnt_t) lru_link;
129 malloc_mutex_t *lock;
143 prof_cnt_t cnt_summed;
146 prof_cnt_t cnt_merged;
152 ql_head(prof_thr_cnt_t) cnts_ql;
155 ql_elm(prof_ctx_t) dump_link;
157 typedef
ql_head(prof_ctx_t) prof_ctx_list_t;
159 struct prof_tdata_s {
173 ql_head(prof_thr_cnt_t) lru_ql;
191 #ifdef JEMALLOC_H_EXTERNS
229 void bt_init(prof_bt_t *bt,
void **vec);
234 typedef int (prof_dump_open_t)(
bool,
const char *);
251 #ifdef JEMALLOC_H_INLINES
253 #define PROF_ALLOC_PREP(nignore, size, ret) do { \
254 prof_tdata_t *prof_tdata; \
257 assert(size == s2u(size)); \
259 prof_tdata = prof_tdata_get(true); \
260 if ((uintptr_t)prof_tdata <= (uintptr_t)PROF_TDATA_STATE_MAX) { \
261 if (prof_tdata != NULL) \
262 ret = (prof_thr_cnt_t *)(uintptr_t)1U; \
268 if (opt_prof_active == false) { \
270 ret = (prof_thr_cnt_t *)(uintptr_t)1U; \
271 } else if (opt_lg_prof_sample == 0) { \
274 bt_init(&bt, prof_tdata->vec); \
275 prof_backtrace(&bt, nignore); \
276 ret = prof_lookup(&bt); \
278 if (prof_tdata->threshold == 0) { \
281 prof_tdata->prng_state = \
282 (uint64_t)(uintptr_t)&size; \
283 prof_sample_threshold_update(prof_tdata); \
295 if (size >= prof_tdata->threshold - \
296 prof_tdata->accum) { \
297 bt_init(&bt, prof_tdata->vec); \
298 prof_backtrace(&bt, nignore); \
299 ret = prof_lookup(&bt); \
301 ret = (prof_thr_cnt_t *)(uintptr_t)1U; \
305 #ifndef JEMALLOC_ENABLE_INLINE
306 malloc_tsd_protos(JEMALLOC_ATTR(unused), prof_tdata, prof_tdata_t *)
315 size_t old_usize, prof_ctx_t *old_ctx);
319 #if (defined(JEMALLOC_ENABLE_INLINE) || defined(JEMALLOC_PROF_C_))
325 JEMALLOC_INLINE prof_tdata_t *
328 prof_tdata_t *prof_tdata;
333 if (create && prof_tdata == NULL)
379 prng64(r, 53, prof_tdata->prng_state,
381 u = (double)r * (1.0/9007199254740992.0L);
383 log(1.0 - (1.0 / (
double)((
uint64_t)1U << opt_lg_prof_sample))))
388 JEMALLOC_INLINE prof_ctx_t *
392 arena_chunk_t *
chunk;
397 chunk = (arena_chunk_t *)CHUNK_ADDR2BASE(ptr);
408 prof_ctx_set(
const void *ptr,
size_t usize, prof_ctx_t *ctx)
410 arena_chunk_t *chunk;
415 chunk = (arena_chunk_t *)CHUNK_ADDR2BASE(ptr);
426 prof_tdata_t *prof_tdata;
430 assert(opt_lg_prof_sample != 0);
437 if (size >= prof_tdata->threshold - prof_tdata->accum) {
438 prof_tdata->accum -= (prof_tdata->threshold - size);
441 while (prof_tdata->accum >= prof_tdata->threshold) {
442 prof_tdata->accum -= prof_tdata->threshold;
447 prof_tdata->accum += size;
453 prof_malloc(
const void *ptr,
size_t usize, prof_thr_cnt_t *cnt)
458 assert(usize ==
isalloc(ptr,
true));
460 if (opt_lg_prof_sample != 0) {
481 cnt->cnts.curbytes += usize;
482 if (opt_prof_accum) {
483 cnt->cnts.accumobjs++;
484 cnt->cnts.accumbytes += usize;
498 prof_realloc(
const void *ptr,
size_t usize, prof_thr_cnt_t *cnt,
499 size_t old_usize, prof_ctx_t *old_ctx)
501 prof_thr_cnt_t *told_cnt;
507 assert(usize ==
isalloc(ptr,
true));
508 if (opt_lg_prof_sample != 0) {
525 if (told_cnt == NULL) {
531 old_ctx->cnt_merged.curobjs--;
532 old_ctx->cnt_merged.curbytes -= old_usize;
534 told_cnt = (prof_thr_cnt_t *)(
uintptr_t)1U;
537 told_cnt = (prof_thr_cnt_t *)(
uintptr_t)1U;
544 }
else if (ptr != NULL)
550 told_cnt->cnts.curobjs--;
551 told_cnt->cnts.curbytes -= old_usize;
555 cnt->cnts.curbytes += usize;
556 if (opt_prof_accum) {
557 cnt->cnts.accumobjs++;
558 cnt->cnts.accumbytes += usize;
580 prof_thr_cnt_t *tcnt;
581 assert(size ==
isalloc(ptr,
true));
589 tcnt->cnts.curobjs--;
590 tcnt->cnts.curbytes -= size;
604 ctx->cnt_merged.curobjs--;
605 ctx->cnt_merged.curbytes -= size;
#define prof_tdata_cleanup
Definition: private_namespace.h:311
#define malloc_mutex_lock
Definition: private_namespace.h:237
#define prof_bt_count
Definition: private_namespace.h:292
#define prof_dump_open
Definition: private_namespace.h:295
#define prof_ctx_get
Definition: private_namespace.h:293
#define JEMALLOC_INLINE
Definition: jemalloc_internal.h:259
#define opt_prof_active
Definition: private_namespace.h:272
#define prof_malloc
Definition: private_namespace.h:301
#define opt_prof_leak
Definition: private_namespace.h:275
#define prof_tdata_get
Definition: private_namespace.h:312
#define ql_head(a_type)
Definition: ql.h:4
TC_SHARED_API::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::FieldOptions,::google::protobuf::internal::EnumTypeTraits< ::bgs::protocol::LogOption,::bgs::protocol::LogOption_IsValid >, 14, false > log
#define UINT64_C(val)
Definition: stdint.h:238
JEMALLOC_ALWAYS_INLINE size_t isalloc(const void *ptr, bool demote)
Definition: jemalloc_internal.h:869
arena_t NULL
Definition: jemalloc_internal.h:624
#define prof_sample_accum_update
Definition: private_namespace.h:308
#define prof_tdata_tsd_get
Definition: private_namespace.h:319
#define prof_boot0
Definition: private_namespace.h:289
signed __int64 int64_t
Definition: stdint.h:89
#define ql_elm(a_type)
Definition: ql.h:11
T max(const T &x, const T &y)
Definition: g3dmath.h:320
#define bool
Definition: CascPort.h:16
#define prof_tdata_init
Definition: private_namespace.h:313
#define arena_prof_ctx_get
Definition: private_namespace.h:49
#define opt_lg_prof_interval
Definition: private_namespace.h:266
_W64 unsigned int uintptr_t
Definition: stdint.h:119
#define huge_prof_ctx_set
Definition: private_namespace.h:210
#define opt_lg_prof_sample
Definition: private_namespace.h:267
#define opt_prof
Definition: private_namespace.h:270
#define opt_prof_gdump
Definition: private_namespace.h:274
#define prof_idump
Definition: private_namespace.h:298
unsigned __int64 uint64_t
Definition: stdint.h:90
#define prof_promote
Definition: private_namespace.h:306
#define prof_postfork_parent
Definition: private_namespace.h:304
#define prof_postfork_child
Definition: private_namespace.h:303
#define prof_backtrace
Definition: private_namespace.h:288
#define arena_prof_ctx_set
Definition: private_namespace.h:50
#define prof_sample_threshold_update
Definition: private_namespace.h:309
#define opt_prof_accum
Definition: private_namespace.h:271
#define malloc_mutex_unlock
Definition: private_namespace.h:241
#define prof_boot2
Definition: private_namespace.h:291
#define prof_ctx_set
Definition: private_namespace.h:294
internal::NamedArg< char > arg(StringRef name, const T &arg)
Definition: format.h:3248
#define prof_mdump
Definition: private_namespace.h:302
static const bool config_prof
Definition: jemalloc_internal.h:106
malloc_tsd_externs(arenas, arena_t *) malloc_tsd_funcs(JEMALLOC_ALWAYS_INLINE
#define prof_lookup
Definition: private_namespace.h:300
#define prof_gdump
Definition: private_namespace.h:297
#define huge_prof_ctx_get
Definition: private_namespace.h:209
#define bt_init
Definition: private_namespace.h:102
#define prof_free
Definition: private_namespace.h:296
#define const
Definition: zconf.h:217
#define prof_prefork
Definition: private_namespace.h:305
#define prof_interval
Definition: private_namespace.h:299
Definition: tomcrypt_prng.h:50
#define prof_boot1
Definition: private_namespace.h:290
#define opt_prof_final
Definition: private_namespace.h:273
#define prof_realloc
Definition: private_namespace.h:307
#define opt_prof_prefix
Definition: private_namespace.h:276
#define mb_write
Definition: private_namespace.h:254