MCPcopy Create free account
hub / github.com/beefytech/Beef / prof_malloc_sample_object

Function prof_malloc_sample_object

BeefRT/JEMalloc/src/prof.c:98–147  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

96}
97
98void
99prof_malloc_sample_object(tsd_t *tsd, const void *ptr, size_t size,
100 size_t usize, prof_tctx_t *tctx) {
101 cassert(config_prof);
102
103 if (opt_prof_sys_thread_name) {
104 prof_sys_thread_name_fetch(tsd);
105 }
106
107 edata_t *edata = emap_edata_lookup(tsd_tsdn(tsd), &arena_emap_global,
108 ptr);
109 prof_info_set(tsd, edata, tctx, size);
110
111 szind_t szind = sz_size2index(usize);
112
113 malloc_mutex_lock(tsd_tsdn(tsd), tctx->tdata->lock);
114 /*
115 * We need to do these map lookups while holding the lock, to avoid the
116 * possibility of races with prof_reset calls, which update the map and
117 * then acquire the lock. This actually still leaves a data race on the
118 * contents of the unbias map, but we have not yet gone through and
119 * atomic-ified the prof module, and compilers are not yet causing us
120 * issues. The key thing is to make sure that, if we read garbage data,
121 * the prof_reset call is about to mark our tctx as expired before any
122 * dumping of our corrupted output is attempted.
123 */
124 size_t shifted_unbiased_cnt = prof_shifted_unbiased_cnt[szind];
125 size_t unbiased_bytes = prof_unbiased_sz[szind];
126 tctx->cnts.curobjs++;
127 tctx->cnts.curobjs_shifted_unbiased += shifted_unbiased_cnt;
128 tctx->cnts.curbytes += usize;
129 tctx->cnts.curbytes_unbiased += unbiased_bytes;
130 if (opt_prof_accum) {
131 tctx->cnts.accumobjs++;
132 tctx->cnts.accumobjs_shifted_unbiased += shifted_unbiased_cnt;
133 tctx->cnts.accumbytes += usize;
134 tctx->cnts.accumbytes_unbiased += unbiased_bytes;
135 }
136 bool record_recent = prof_recent_alloc_prepare(tsd, tctx);
137 tctx->prepared = false;
138 malloc_mutex_unlock(tsd_tsdn(tsd), tctx->tdata->lock);
139 if (record_recent) {
140 assert(tctx == edata_prof_tctx_get(edata));
141 prof_recent_alloc(tsd, edata, size, usize);
142 }
143
144 if (opt_prof_stats) {
145 prof_stats_inc(tsd, szind, size);
146 }
147}
148
149void
150prof_free_sampled_object(tsd_t *tsd, size_t usize, prof_info_t *prof_info) {

Callers 2

prof_mallocFunction · 0.85
prof_reallocFunction · 0.85

Calls 11

emap_edata_lookupFunction · 0.85
tsd_tsdnFunction · 0.85
prof_info_setFunction · 0.85
sz_size2indexFunction · 0.85
malloc_mutex_lockFunction · 0.85
malloc_mutex_unlockFunction · 0.85
edata_prof_tctx_getFunction · 0.85
prof_recent_allocFunction · 0.85
prof_stats_incFunction · 0.85

Tested by

no test coverage detected