Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 1 | #define JEMALLOC_PROF_C_ |
Jason Evans | 376b152 | 2010-02-11 14:45:59 -0800 | [diff] [blame] | 2 | #include "jemalloc/internal/jemalloc_internal.h" |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 3 | /******************************************************************************/ |
| 4 | |
| 5 | #ifdef JEMALLOC_PROF_LIBUNWIND |
| 6 | #define UNW_LOCAL_ONLY |
| 7 | #include <libunwind.h> |
| 8 | #endif |
| 9 | |
Jason Evans | 77f350b | 2011-03-15 22:23:12 -0700 | [diff] [blame] | 10 | #ifdef JEMALLOC_PROF_LIBGCC |
| 11 | #include <unwind.h> |
| 12 | #endif |
| 13 | |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 14 | /******************************************************************************/ |
| 15 | /* Data. */ |
| 16 | |
Jason Evans | cd9a134 | 2012-03-21 18:33:03 -0700 | [diff] [blame] | 17 | malloc_tsd_data(, prof_tdata, prof_tdata_t *, NULL) |
| 18 | |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 19 | bool opt_prof = false; |
Jason Evans | f18c982 | 2010-03-31 18:43:24 -0700 | [diff] [blame] | 20 | bool opt_prof_active = true; |
Jason Evans | b9477e7 | 2010-03-01 20:15:26 -0800 | [diff] [blame] | 21 | size_t opt_lg_prof_sample = LG_PROF_SAMPLE_DEFAULT; |
Jason Evans | a02fc08 | 2010-03-31 17:35:51 -0700 | [diff] [blame] | 22 | ssize_t opt_lg_prof_interval = LG_PROF_INTERVAL_DEFAULT; |
Jason Evans | e733970 | 2010-10-23 18:37:06 -0700 | [diff] [blame] | 23 | bool opt_prof_gdump = false; |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 24 | bool opt_prof_leak = false; |
Jason Evans | a881cd2 | 2010-10-02 15:18:50 -0700 | [diff] [blame] | 25 | bool opt_prof_accum = true; |
Jason Evans | e733970 | 2010-10-23 18:37:06 -0700 | [diff] [blame] | 26 | char opt_prof_prefix[PATH_MAX + 1]; |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 27 | |
Jason Evans | d34f9e7 | 2010-02-11 13:19:21 -0800 | [diff] [blame] | 28 | uint64_t prof_interval; |
Jason Evans | 0b270a9 | 2010-03-31 16:45:04 -0700 | [diff] [blame] | 29 | bool prof_promote; |
Jason Evans | d34f9e7 | 2010-02-11 13:19:21 -0800 | [diff] [blame] | 30 | |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 31 | /* |
Jason Evans | 6da5418 | 2012-03-23 18:05:51 -0700 | [diff] [blame] | 32 | * Table of mutexes that are shared among ctx's. These are leaf locks, so |
| 33 | * there is no problem with using them for more than one ctx at the same time. |
| 34 | * The primary motivation for this sharing though is that ctx's are ephemeral, |
| 35 | * and destroying mutexes causes complications for systems that allocate when |
| 36 | * creating/destroying mutexes. |
| 37 | */ |
| 38 | static malloc_mutex_t *ctx_locks; |
| 39 | static unsigned cum_ctxs; /* Atomic counter. */ |
| 40 | |
| 41 | /* |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 42 | * Global hash of (prof_bt_t *)-->(prof_ctx_t *). This is the master data |
Jason Evans | a881cd2 | 2010-10-02 15:18:50 -0700 | [diff] [blame] | 43 | * structure that knows about all backtraces currently captured. |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 44 | */ |
| 45 | static ckh_t bt2ctx; |
| 46 | static malloc_mutex_t bt2ctx_mtx; |
| 47 | |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 48 | static malloc_mutex_t prof_dump_seq_mtx; |
| 49 | static uint64_t prof_dump_seq; |
| 50 | static uint64_t prof_dump_iseq; |
| 51 | static uint64_t prof_dump_mseq; |
| 52 | static uint64_t prof_dump_useq; |
| 53 | |
| 54 | /* |
| 55 | * This buffer is rather large for stack allocation, so use a single buffer for |
| 56 | * all profile dumps. The buffer is implicitly protected by bt2ctx_mtx, since |
| 57 | * it must be locked anyway during dumping. |
| 58 | */ |
Jason Evans | cd9a134 | 2012-03-21 18:33:03 -0700 | [diff] [blame] | 59 | static char prof_dump_buf[PROF_DUMP_BUFSIZE]; |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 60 | static unsigned prof_dump_buf_end; |
| 61 | static int prof_dump_fd; |
| 62 | |
| 63 | /* Do not dump any profiles until bootstrapping is complete. */ |
| 64 | static bool prof_booted = false; |
| 65 | |
| 66 | static malloc_mutex_t enq_mtx; |
| 67 | static bool enq; |
Jason Evans | d34f9e7 | 2010-02-11 13:19:21 -0800 | [diff] [blame] | 68 | static bool enq_idump; |
Jason Evans | e733970 | 2010-10-23 18:37:06 -0700 | [diff] [blame] | 69 | static bool enq_gdump; |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 70 | |
| 71 | /******************************************************************************/ |
| 72 | /* Function prototypes for non-inline static functions. */ |
| 73 | |
| 74 | static prof_bt_t *bt_dup(prof_bt_t *bt); |
Jason Evans | a881cd2 | 2010-10-02 15:18:50 -0700 | [diff] [blame] | 75 | static void bt_destroy(prof_bt_t *bt); |
Jason Evans | b27805b | 2010-02-10 18:15:53 -0800 | [diff] [blame] | 76 | #ifdef JEMALLOC_PROF_LIBGCC |
| 77 | static _Unwind_Reason_Code prof_unwind_init_callback( |
| 78 | struct _Unwind_Context *context, void *arg); |
| 79 | static _Unwind_Reason_Code prof_unwind_callback( |
| 80 | struct _Unwind_Context *context, void *arg); |
| 81 | #endif |
Jason Evans | 22ca855 | 2010-03-02 11:57:30 -0800 | [diff] [blame] | 82 | static bool prof_flush(bool propagate_err); |
Jason Evans | d81e4bd | 2012-03-06 14:57:45 -0800 | [diff] [blame] | 83 | static bool prof_write(bool propagate_err, const char *s); |
| 84 | static bool prof_printf(bool propagate_err, const char *format, ...) |
| 85 | JEMALLOC_ATTR(format(printf, 2, 3)); |
Jason Evans | a881cd2 | 2010-10-02 15:18:50 -0700 | [diff] [blame] | 86 | static void prof_ctx_sum(prof_ctx_t *ctx, prof_cnt_t *cnt_all, |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 87 | size_t *leak_nctx); |
Jason Evans | a881cd2 | 2010-10-02 15:18:50 -0700 | [diff] [blame] | 88 | static void prof_ctx_destroy(prof_ctx_t *ctx); |
| 89 | static void prof_ctx_merge(prof_ctx_t *ctx, prof_thr_cnt_t *cnt); |
Jason Evans | d81e4bd | 2012-03-06 14:57:45 -0800 | [diff] [blame] | 90 | static bool prof_dump_ctx(bool propagate_err, prof_ctx_t *ctx, |
| 91 | prof_bt_t *bt); |
Jason Evans | 22ca855 | 2010-03-02 11:57:30 -0800 | [diff] [blame] | 92 | static bool prof_dump_maps(bool propagate_err); |
Jason Evans | d81e4bd | 2012-03-06 14:57:45 -0800 | [diff] [blame] | 93 | static bool prof_dump(bool propagate_err, const char *filename, |
| 94 | bool leakcheck); |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 95 | static void prof_dump_filename(char *filename, char v, int64_t vseq); |
| 96 | static void prof_fdump(void); |
| 97 | static void prof_bt_hash(const void *key, unsigned minbits, size_t *hash1, |
| 98 | size_t *hash2); |
| 99 | static bool prof_bt_keycomp(const void *k1, const void *k2); |
Jason Evans | 6da5418 | 2012-03-23 18:05:51 -0700 | [diff] [blame] | 100 | static malloc_mutex_t *prof_ctx_mutex_choose(void); |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 101 | |
| 102 | /******************************************************************************/ |
| 103 | |
Jason Evans | 4d6a134 | 2010-10-20 19:05:59 -0700 | [diff] [blame] | 104 | void |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 105 | bt_init(prof_bt_t *bt, void **vec) |
| 106 | { |
| 107 | |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 108 | cassert(config_prof); |
| 109 | |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 110 | bt->vec = vec; |
| 111 | bt->len = 0; |
| 112 | } |
| 113 | |
Jason Evans | a881cd2 | 2010-10-02 15:18:50 -0700 | [diff] [blame] | 114 | static void |
| 115 | bt_destroy(prof_bt_t *bt) |
| 116 | { |
| 117 | |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 118 | cassert(config_prof); |
| 119 | |
Jason Evans | a881cd2 | 2010-10-02 15:18:50 -0700 | [diff] [blame] | 120 | idalloc(bt); |
| 121 | } |
| 122 | |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 123 | static prof_bt_t * |
| 124 | bt_dup(prof_bt_t *bt) |
| 125 | { |
| 126 | prof_bt_t *ret; |
| 127 | |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 128 | cassert(config_prof); |
| 129 | |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 130 | /* |
| 131 | * Create a single allocation that has space for vec immediately |
| 132 | * following the prof_bt_t structure. The backtraces that get |
| 133 | * stored in the backtrace caches are copied from stack-allocated |
| 134 | * temporary variables, so size is known at creation time. Making this |
| 135 | * a contiguous object improves cache locality. |
| 136 | */ |
| 137 | ret = (prof_bt_t *)imalloc(QUANTUM_CEILING(sizeof(prof_bt_t)) + |
| 138 | (bt->len * sizeof(void *))); |
| 139 | if (ret == NULL) |
| 140 | return (NULL); |
| 141 | ret->vec = (void **)((uintptr_t)ret + |
| 142 | QUANTUM_CEILING(sizeof(prof_bt_t))); |
| 143 | memcpy(ret->vec, bt->vec, bt->len * sizeof(void *)); |
| 144 | ret->len = bt->len; |
| 145 | |
| 146 | return (ret); |
| 147 | } |
| 148 | |
| 149 | static inline void |
| 150 | prof_enter(void) |
| 151 | { |
| 152 | |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 153 | cassert(config_prof); |
| 154 | |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 155 | malloc_mutex_lock(&enq_mtx); |
| 156 | enq = true; |
| 157 | malloc_mutex_unlock(&enq_mtx); |
| 158 | |
| 159 | malloc_mutex_lock(&bt2ctx_mtx); |
| 160 | } |
| 161 | |
| 162 | static inline void |
| 163 | prof_leave(void) |
| 164 | { |
Jason Evans | e733970 | 2010-10-23 18:37:06 -0700 | [diff] [blame] | 165 | bool idump, gdump; |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 166 | |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 167 | cassert(config_prof); |
| 168 | |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 169 | malloc_mutex_unlock(&bt2ctx_mtx); |
| 170 | |
| 171 | malloc_mutex_lock(&enq_mtx); |
| 172 | enq = false; |
Jason Evans | d34f9e7 | 2010-02-11 13:19:21 -0800 | [diff] [blame] | 173 | idump = enq_idump; |
| 174 | enq_idump = false; |
Jason Evans | e733970 | 2010-10-23 18:37:06 -0700 | [diff] [blame] | 175 | gdump = enq_gdump; |
| 176 | enq_gdump = false; |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 177 | malloc_mutex_unlock(&enq_mtx); |
| 178 | |
Jason Evans | d34f9e7 | 2010-02-11 13:19:21 -0800 | [diff] [blame] | 179 | if (idump) |
| 180 | prof_idump(); |
Jason Evans | e733970 | 2010-10-23 18:37:06 -0700 | [diff] [blame] | 181 | if (gdump) |
| 182 | prof_gdump(); |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 183 | } |
| 184 | |
Jason Evans | 77f350b | 2011-03-15 22:23:12 -0700 | [diff] [blame] | 185 | #ifdef JEMALLOC_PROF_LIBUNWIND |
Jason Evans | 4d6a134 | 2010-10-20 19:05:59 -0700 | [diff] [blame] | 186 | void |
Jason Evans | 5389146 | 2012-02-13 18:23:41 -0800 | [diff] [blame] | 187 | prof_backtrace(prof_bt_t *bt, unsigned nignore) |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 188 | { |
| 189 | unw_context_t uc; |
| 190 | unw_cursor_t cursor; |
| 191 | unsigned i; |
| 192 | int err; |
| 193 | |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 194 | cassert(config_prof); |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 195 | assert(bt->len == 0); |
| 196 | assert(bt->vec != NULL); |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 197 | |
| 198 | unw_getcontext(&uc); |
| 199 | unw_init_local(&cursor, &uc); |
| 200 | |
Jason Evans | 9f949f9 | 2011-03-22 20:44:40 -0700 | [diff] [blame] | 201 | /* Throw away (nignore+1) stack frames, if that many exist. */ |
| 202 | for (i = 0; i < nignore + 1; i++) { |
| 203 | err = unw_step(&cursor); |
| 204 | if (err <= 0) |
| 205 | return; |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 206 | } |
| 207 | |
Jason Evans | 9f949f9 | 2011-03-22 20:44:40 -0700 | [diff] [blame] | 208 | /* |
| 209 | * Iterate over stack frames until there are no more, or until no space |
| 210 | * remains in bt. |
| 211 | */ |
Jason Evans | 5389146 | 2012-02-13 18:23:41 -0800 | [diff] [blame] | 212 | for (i = 0; i < PROF_BT_MAX; i++) { |
Jason Evans | 9f949f9 | 2011-03-22 20:44:40 -0700 | [diff] [blame] | 213 | unw_get_reg(&cursor, UNW_REG_IP, (unw_word_t *)&bt->vec[i]); |
| 214 | bt->len++; |
| 215 | err = unw_step(&cursor); |
| 216 | if (err <= 0) |
| 217 | break; |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 218 | } |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 219 | } |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 220 | #elif (defined(JEMALLOC_PROF_LIBGCC)) |
Jason Evans | 77f350b | 2011-03-15 22:23:12 -0700 | [diff] [blame] | 221 | static _Unwind_Reason_Code |
| 222 | prof_unwind_init_callback(struct _Unwind_Context *context, void *arg) |
| 223 | { |
| 224 | |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 225 | cassert(config_prof); |
| 226 | |
Jason Evans | 77f350b | 2011-03-15 22:23:12 -0700 | [diff] [blame] | 227 | return (_URC_NO_REASON); |
| 228 | } |
| 229 | |
| 230 | static _Unwind_Reason_Code |
| 231 | prof_unwind_callback(struct _Unwind_Context *context, void *arg) |
| 232 | { |
| 233 | prof_unwind_data_t *data = (prof_unwind_data_t *)arg; |
| 234 | |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 235 | cassert(config_prof); |
| 236 | |
Jason Evans | 77f350b | 2011-03-15 22:23:12 -0700 | [diff] [blame] | 237 | if (data->nignore > 0) |
| 238 | data->nignore--; |
| 239 | else { |
| 240 | data->bt->vec[data->bt->len] = (void *)_Unwind_GetIP(context); |
| 241 | data->bt->len++; |
| 242 | if (data->bt->len == data->max) |
| 243 | return (_URC_END_OF_STACK); |
| 244 | } |
| 245 | |
| 246 | return (_URC_NO_REASON); |
| 247 | } |
| 248 | |
| 249 | void |
Jason Evans | 5389146 | 2012-02-13 18:23:41 -0800 | [diff] [blame] | 250 | prof_backtrace(prof_bt_t *bt, unsigned nignore) |
Jason Evans | 77f350b | 2011-03-15 22:23:12 -0700 | [diff] [blame] | 251 | { |
Jason Evans | 5389146 | 2012-02-13 18:23:41 -0800 | [diff] [blame] | 252 | prof_unwind_data_t data = {bt, nignore, PROF_BT_MAX}; |
Jason Evans | 77f350b | 2011-03-15 22:23:12 -0700 | [diff] [blame] | 253 | |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 254 | cassert(config_prof); |
| 255 | |
Jason Evans | 77f350b | 2011-03-15 22:23:12 -0700 | [diff] [blame] | 256 | _Unwind_Backtrace(prof_unwind_callback, &data); |
| 257 | } |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 258 | #elif (defined(JEMALLOC_PROF_GCC)) |
Jason Evans | 4d6a134 | 2010-10-20 19:05:59 -0700 | [diff] [blame] | 259 | void |
Jason Evans | 5389146 | 2012-02-13 18:23:41 -0800 | [diff] [blame] | 260 | prof_backtrace(prof_bt_t *bt, unsigned nignore) |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 261 | { |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 262 | #define BT_FRAME(i) \ |
Jason Evans | 5389146 | 2012-02-13 18:23:41 -0800 | [diff] [blame] | 263 | if ((i) < nignore + PROF_BT_MAX) { \ |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 264 | void *p; \ |
| 265 | if (__builtin_frame_address(i) == 0) \ |
Jason Evans | b27805b | 2010-02-10 18:15:53 -0800 | [diff] [blame] | 266 | return; \ |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 267 | p = __builtin_return_address(i); \ |
| 268 | if (p == NULL) \ |
Jason Evans | b27805b | 2010-02-10 18:15:53 -0800 | [diff] [blame] | 269 | return; \ |
Jason Evans | e4f7846 | 2010-10-22 10:45:59 -0700 | [diff] [blame] | 270 | if (i >= nignore) { \ |
| 271 | bt->vec[(i) - nignore] = p; \ |
| 272 | bt->len = (i) - nignore + 1; \ |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 273 | } \ |
| 274 | } else \ |
Jason Evans | b27805b | 2010-02-10 18:15:53 -0800 | [diff] [blame] | 275 | return; |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 276 | |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 277 | cassert(config_prof); |
Jason Evans | b04a940 | 2010-10-27 19:47:40 -0700 | [diff] [blame] | 278 | assert(nignore <= 3); |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 279 | |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 280 | BT_FRAME(0) |
| 281 | BT_FRAME(1) |
| 282 | BT_FRAME(2) |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 283 | BT_FRAME(3) |
| 284 | BT_FRAME(4) |
| 285 | BT_FRAME(5) |
| 286 | BT_FRAME(6) |
| 287 | BT_FRAME(7) |
| 288 | BT_FRAME(8) |
| 289 | BT_FRAME(9) |
| 290 | |
| 291 | BT_FRAME(10) |
| 292 | BT_FRAME(11) |
| 293 | BT_FRAME(12) |
| 294 | BT_FRAME(13) |
| 295 | BT_FRAME(14) |
| 296 | BT_FRAME(15) |
| 297 | BT_FRAME(16) |
| 298 | BT_FRAME(17) |
| 299 | BT_FRAME(18) |
| 300 | BT_FRAME(19) |
| 301 | |
| 302 | BT_FRAME(20) |
| 303 | BT_FRAME(21) |
| 304 | BT_FRAME(22) |
| 305 | BT_FRAME(23) |
| 306 | BT_FRAME(24) |
| 307 | BT_FRAME(25) |
| 308 | BT_FRAME(26) |
| 309 | BT_FRAME(27) |
| 310 | BT_FRAME(28) |
| 311 | BT_FRAME(29) |
| 312 | |
| 313 | BT_FRAME(30) |
| 314 | BT_FRAME(31) |
| 315 | BT_FRAME(32) |
| 316 | BT_FRAME(33) |
| 317 | BT_FRAME(34) |
| 318 | BT_FRAME(35) |
| 319 | BT_FRAME(36) |
| 320 | BT_FRAME(37) |
| 321 | BT_FRAME(38) |
| 322 | BT_FRAME(39) |
| 323 | |
| 324 | BT_FRAME(40) |
| 325 | BT_FRAME(41) |
| 326 | BT_FRAME(42) |
| 327 | BT_FRAME(43) |
| 328 | BT_FRAME(44) |
| 329 | BT_FRAME(45) |
| 330 | BT_FRAME(46) |
| 331 | BT_FRAME(47) |
| 332 | BT_FRAME(48) |
| 333 | BT_FRAME(49) |
| 334 | |
| 335 | BT_FRAME(50) |
| 336 | BT_FRAME(51) |
| 337 | BT_FRAME(52) |
| 338 | BT_FRAME(53) |
| 339 | BT_FRAME(54) |
| 340 | BT_FRAME(55) |
| 341 | BT_FRAME(56) |
| 342 | BT_FRAME(57) |
| 343 | BT_FRAME(58) |
| 344 | BT_FRAME(59) |
| 345 | |
| 346 | BT_FRAME(60) |
| 347 | BT_FRAME(61) |
| 348 | BT_FRAME(62) |
| 349 | BT_FRAME(63) |
| 350 | BT_FRAME(64) |
| 351 | BT_FRAME(65) |
| 352 | BT_FRAME(66) |
| 353 | BT_FRAME(67) |
| 354 | BT_FRAME(68) |
| 355 | BT_FRAME(69) |
| 356 | |
| 357 | BT_FRAME(70) |
| 358 | BT_FRAME(71) |
| 359 | BT_FRAME(72) |
| 360 | BT_FRAME(73) |
| 361 | BT_FRAME(74) |
| 362 | BT_FRAME(75) |
| 363 | BT_FRAME(76) |
| 364 | BT_FRAME(77) |
| 365 | BT_FRAME(78) |
| 366 | BT_FRAME(79) |
| 367 | |
| 368 | BT_FRAME(80) |
| 369 | BT_FRAME(81) |
| 370 | BT_FRAME(82) |
| 371 | BT_FRAME(83) |
| 372 | BT_FRAME(84) |
| 373 | BT_FRAME(85) |
| 374 | BT_FRAME(86) |
| 375 | BT_FRAME(87) |
| 376 | BT_FRAME(88) |
| 377 | BT_FRAME(89) |
| 378 | |
| 379 | BT_FRAME(90) |
| 380 | BT_FRAME(91) |
| 381 | BT_FRAME(92) |
| 382 | BT_FRAME(93) |
| 383 | BT_FRAME(94) |
| 384 | BT_FRAME(95) |
| 385 | BT_FRAME(96) |
| 386 | BT_FRAME(97) |
| 387 | BT_FRAME(98) |
| 388 | BT_FRAME(99) |
| 389 | |
| 390 | BT_FRAME(100) |
| 391 | BT_FRAME(101) |
| 392 | BT_FRAME(102) |
| 393 | BT_FRAME(103) |
| 394 | BT_FRAME(104) |
| 395 | BT_FRAME(105) |
| 396 | BT_FRAME(106) |
| 397 | BT_FRAME(107) |
| 398 | BT_FRAME(108) |
| 399 | BT_FRAME(109) |
| 400 | |
| 401 | BT_FRAME(110) |
| 402 | BT_FRAME(111) |
| 403 | BT_FRAME(112) |
| 404 | BT_FRAME(113) |
| 405 | BT_FRAME(114) |
| 406 | BT_FRAME(115) |
| 407 | BT_FRAME(116) |
| 408 | BT_FRAME(117) |
| 409 | BT_FRAME(118) |
| 410 | BT_FRAME(119) |
| 411 | |
| 412 | BT_FRAME(120) |
| 413 | BT_FRAME(121) |
| 414 | BT_FRAME(122) |
| 415 | BT_FRAME(123) |
| 416 | BT_FRAME(124) |
| 417 | BT_FRAME(125) |
| 418 | BT_FRAME(126) |
| 419 | BT_FRAME(127) |
| 420 | |
Jason Evans | b04a940 | 2010-10-27 19:47:40 -0700 | [diff] [blame] | 421 | /* Extras to compensate for nignore. */ |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 422 | BT_FRAME(128) |
| 423 | BT_FRAME(129) |
| 424 | BT_FRAME(130) |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 425 | #undef BT_FRAME |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 426 | } |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 427 | #else |
| 428 | void |
Jason Evans | 5389146 | 2012-02-13 18:23:41 -0800 | [diff] [blame] | 429 | prof_backtrace(prof_bt_t *bt, unsigned nignore) |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 430 | { |
| 431 | |
| 432 | cassert(config_prof); |
| 433 | assert(false); |
| 434 | } |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 435 | #endif |
| 436 | |
Jason Evans | 4d6a134 | 2010-10-20 19:05:59 -0700 | [diff] [blame] | 437 | prof_thr_cnt_t * |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 438 | prof_lookup(prof_bt_t *bt) |
| 439 | { |
Jason Evans | 075e77c | 2010-09-20 19:53:25 -0700 | [diff] [blame] | 440 | union { |
| 441 | prof_thr_cnt_t *p; |
| 442 | void *v; |
| 443 | } ret; |
Jason Evans | 4d6a134 | 2010-10-20 19:05:59 -0700 | [diff] [blame] | 444 | prof_tdata_t *prof_tdata; |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 445 | |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 446 | cassert(config_prof); |
| 447 | |
Jason Evans | cd9a134 | 2012-03-21 18:33:03 -0700 | [diff] [blame] | 448 | prof_tdata = *prof_tdata_tsd_get(); |
Jason Evans | 4d6a134 | 2010-10-20 19:05:59 -0700 | [diff] [blame] | 449 | if (prof_tdata == NULL) { |
| 450 | prof_tdata = prof_tdata_init(); |
| 451 | if (prof_tdata == NULL) |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 452 | return (NULL); |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 453 | } |
| 454 | |
Jason Evans | 4d6a134 | 2010-10-20 19:05:59 -0700 | [diff] [blame] | 455 | if (ckh_search(&prof_tdata->bt2cnt, bt, NULL, &ret.v)) { |
Jason Evans | 075e77c | 2010-09-20 19:53:25 -0700 | [diff] [blame] | 456 | union { |
| 457 | prof_bt_t *p; |
| 458 | void *v; |
| 459 | } btkey; |
| 460 | union { |
| 461 | prof_ctx_t *p; |
| 462 | void *v; |
| 463 | } ctx; |
Jason Evans | 10e4523 | 2011-01-14 17:27:44 -0800 | [diff] [blame] | 464 | bool new_ctx; |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 465 | |
| 466 | /* |
| 467 | * This thread's cache lacks bt. Look for it in the global |
| 468 | * cache. |
| 469 | */ |
| 470 | prof_enter(); |
Jason Evans | 075e77c | 2010-09-20 19:53:25 -0700 | [diff] [blame] | 471 | if (ckh_search(&bt2ctx, bt, &btkey.v, &ctx.v)) { |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 472 | /* bt has never been seen before. Insert it. */ |
Jason Evans | 075e77c | 2010-09-20 19:53:25 -0700 | [diff] [blame] | 473 | ctx.v = imalloc(sizeof(prof_ctx_t)); |
| 474 | if (ctx.v == NULL) { |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 475 | prof_leave(); |
| 476 | return (NULL); |
| 477 | } |
Jason Evans | 075e77c | 2010-09-20 19:53:25 -0700 | [diff] [blame] | 478 | btkey.p = bt_dup(bt); |
| 479 | if (btkey.v == NULL) { |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 480 | prof_leave(); |
Jason Evans | 075e77c | 2010-09-20 19:53:25 -0700 | [diff] [blame] | 481 | idalloc(ctx.v); |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 482 | return (NULL); |
| 483 | } |
Jason Evans | 075e77c | 2010-09-20 19:53:25 -0700 | [diff] [blame] | 484 | ctx.p->bt = btkey.p; |
Jason Evans | 6da5418 | 2012-03-23 18:05:51 -0700 | [diff] [blame] | 485 | ctx.p->lock = prof_ctx_mutex_choose(); |
Jason Evans | 075e77c | 2010-09-20 19:53:25 -0700 | [diff] [blame] | 486 | memset(&ctx.p->cnt_merged, 0, sizeof(prof_cnt_t)); |
| 487 | ql_new(&ctx.p->cnts_ql); |
| 488 | if (ckh_insert(&bt2ctx, btkey.v, ctx.v)) { |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 489 | /* OOM. */ |
| 490 | prof_leave(); |
Jason Evans | 075e77c | 2010-09-20 19:53:25 -0700 | [diff] [blame] | 491 | idalloc(btkey.v); |
| 492 | idalloc(ctx.v); |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 493 | return (NULL); |
| 494 | } |
Jason Evans | 10e4523 | 2011-01-14 17:27:44 -0800 | [diff] [blame] | 495 | /* |
| 496 | * Artificially raise curobjs, in order to avoid a race |
| 497 | * condition with prof_ctx_merge()/prof_ctx_destroy(). |
Jason Evans | a9076c9 | 2011-08-30 23:40:11 -0700 | [diff] [blame] | 498 | * |
| 499 | * No locking is necessary for ctx here because no other |
| 500 | * threads have had the opportunity to fetch it from |
| 501 | * bt2ctx yet. |
Jason Evans | 10e4523 | 2011-01-14 17:27:44 -0800 | [diff] [blame] | 502 | */ |
| 503 | ctx.p->cnt_merged.curobjs++; |
| 504 | new_ctx = true; |
Jason Evans | a9076c9 | 2011-08-30 23:40:11 -0700 | [diff] [blame] | 505 | } else { |
| 506 | /* |
| 507 | * Artificially raise curobjs, in order to avoid a race |
| 508 | * condition with prof_ctx_merge()/prof_ctx_destroy(). |
| 509 | */ |
Jason Evans | 6da5418 | 2012-03-23 18:05:51 -0700 | [diff] [blame] | 510 | malloc_mutex_lock(ctx.p->lock); |
Jason Evans | a9076c9 | 2011-08-30 23:40:11 -0700 | [diff] [blame] | 511 | ctx.p->cnt_merged.curobjs++; |
Jason Evans | 6da5418 | 2012-03-23 18:05:51 -0700 | [diff] [blame] | 512 | malloc_mutex_unlock(ctx.p->lock); |
Jason Evans | 10e4523 | 2011-01-14 17:27:44 -0800 | [diff] [blame] | 513 | new_ctx = false; |
Jason Evans | a9076c9 | 2011-08-30 23:40:11 -0700 | [diff] [blame] | 514 | } |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 515 | prof_leave(); |
| 516 | |
| 517 | /* Link a prof_thd_cnt_t into ctx for this thread. */ |
Jason Evans | 0b526ff | 2012-02-13 18:04:26 -0800 | [diff] [blame] | 518 | if (ckh_count(&prof_tdata->bt2cnt) == PROF_TCMAX) { |
Jason Evans | 4d6a134 | 2010-10-20 19:05:59 -0700 | [diff] [blame] | 519 | assert(ckh_count(&prof_tdata->bt2cnt) > 0); |
Jason Evans | a881cd2 | 2010-10-02 15:18:50 -0700 | [diff] [blame] | 520 | /* |
Jason Evans | e4f7846 | 2010-10-22 10:45:59 -0700 | [diff] [blame] | 521 | * Flush the least recently used cnt in order to keep |
| 522 | * bt2cnt from becoming too large. |
Jason Evans | a881cd2 | 2010-10-02 15:18:50 -0700 | [diff] [blame] | 523 | */ |
Jason Evans | 4d6a134 | 2010-10-20 19:05:59 -0700 | [diff] [blame] | 524 | ret.p = ql_last(&prof_tdata->lru_ql, lru_link); |
Jason Evans | a881cd2 | 2010-10-02 15:18:50 -0700 | [diff] [blame] | 525 | assert(ret.v != NULL); |
Jason Evans | a9076c9 | 2011-08-30 23:40:11 -0700 | [diff] [blame] | 526 | if (ckh_remove(&prof_tdata->bt2cnt, ret.p->ctx->bt, |
| 527 | NULL, NULL)) |
| 528 | assert(false); |
Jason Evans | 4d6a134 | 2010-10-20 19:05:59 -0700 | [diff] [blame] | 529 | ql_remove(&prof_tdata->lru_ql, ret.p, lru_link); |
Jason Evans | a881cd2 | 2010-10-02 15:18:50 -0700 | [diff] [blame] | 530 | prof_ctx_merge(ret.p->ctx, ret.p); |
| 531 | /* ret can now be re-used. */ |
| 532 | } else { |
Jason Evans | 0b526ff | 2012-02-13 18:04:26 -0800 | [diff] [blame] | 533 | assert(ckh_count(&prof_tdata->bt2cnt) < PROF_TCMAX); |
Jason Evans | a881cd2 | 2010-10-02 15:18:50 -0700 | [diff] [blame] | 534 | /* Allocate and partially initialize a new cnt. */ |
| 535 | ret.v = imalloc(sizeof(prof_thr_cnt_t)); |
Jason Evans | b04a940 | 2010-10-27 19:47:40 -0700 | [diff] [blame] | 536 | if (ret.p == NULL) { |
Jason Evans | 0cdd42e | 2011-08-09 19:06:06 -0700 | [diff] [blame] | 537 | if (new_ctx) |
| 538 | prof_ctx_destroy(ctx.p); |
Jason Evans | a881cd2 | 2010-10-02 15:18:50 -0700 | [diff] [blame] | 539 | return (NULL); |
Jason Evans | b04a940 | 2010-10-27 19:47:40 -0700 | [diff] [blame] | 540 | } |
Jason Evans | a881cd2 | 2010-10-02 15:18:50 -0700 | [diff] [blame] | 541 | ql_elm_new(ret.p, cnts_link); |
| 542 | ql_elm_new(ret.p, lru_link); |
| 543 | } |
| 544 | /* Finish initializing ret. */ |
Jason Evans | 075e77c | 2010-09-20 19:53:25 -0700 | [diff] [blame] | 545 | ret.p->ctx = ctx.p; |
| 546 | ret.p->epoch = 0; |
| 547 | memset(&ret.p->cnts, 0, sizeof(prof_cnt_t)); |
Jason Evans | 4d6a134 | 2010-10-20 19:05:59 -0700 | [diff] [blame] | 548 | if (ckh_insert(&prof_tdata->bt2cnt, btkey.v, ret.v)) { |
Jason Evans | 0cdd42e | 2011-08-09 19:06:06 -0700 | [diff] [blame] | 549 | if (new_ctx) |
| 550 | prof_ctx_destroy(ctx.p); |
Jason Evans | 075e77c | 2010-09-20 19:53:25 -0700 | [diff] [blame] | 551 | idalloc(ret.v); |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 552 | return (NULL); |
| 553 | } |
Jason Evans | 4d6a134 | 2010-10-20 19:05:59 -0700 | [diff] [blame] | 554 | ql_head_insert(&prof_tdata->lru_ql, ret.p, lru_link); |
Jason Evans | 6da5418 | 2012-03-23 18:05:51 -0700 | [diff] [blame] | 555 | malloc_mutex_lock(ctx.p->lock); |
Jason Evans | a881cd2 | 2010-10-02 15:18:50 -0700 | [diff] [blame] | 556 | ql_tail_insert(&ctx.p->cnts_ql, ret.p, cnts_link); |
Jason Evans | a9076c9 | 2011-08-30 23:40:11 -0700 | [diff] [blame] | 557 | ctx.p->cnt_merged.curobjs--; |
Jason Evans | 6da5418 | 2012-03-23 18:05:51 -0700 | [diff] [blame] | 558 | malloc_mutex_unlock(ctx.p->lock); |
Jason Evans | a881cd2 | 2010-10-02 15:18:50 -0700 | [diff] [blame] | 559 | } else { |
| 560 | /* Move ret to the front of the LRU. */ |
Jason Evans | 4d6a134 | 2010-10-20 19:05:59 -0700 | [diff] [blame] | 561 | ql_remove(&prof_tdata->lru_ql, ret.p, lru_link); |
| 562 | ql_head_insert(&prof_tdata->lru_ql, ret.p, lru_link); |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 563 | } |
| 564 | |
Jason Evans | 075e77c | 2010-09-20 19:53:25 -0700 | [diff] [blame] | 565 | return (ret.p); |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 566 | } |
| 567 | |
Jason Evans | 22ca855 | 2010-03-02 11:57:30 -0800 | [diff] [blame] | 568 | static bool |
| 569 | prof_flush(bool propagate_err) |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 570 | { |
Jason Evans | 22ca855 | 2010-03-02 11:57:30 -0800 | [diff] [blame] | 571 | bool ret = false; |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 572 | ssize_t err; |
| 573 | |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 574 | cassert(config_prof); |
| 575 | |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 576 | err = write(prof_dump_fd, prof_dump_buf, prof_dump_buf_end); |
| 577 | if (err == -1) { |
Jason Evans | 22ca855 | 2010-03-02 11:57:30 -0800 | [diff] [blame] | 578 | if (propagate_err == false) { |
Jason Evans | 698805c | 2010-03-03 17:45:38 -0800 | [diff] [blame] | 579 | malloc_write("<jemalloc>: write() failed during heap " |
| 580 | "profile flush\n"); |
Jason Evans | 22ca855 | 2010-03-02 11:57:30 -0800 | [diff] [blame] | 581 | if (opt_abort) |
| 582 | abort(); |
| 583 | } |
| 584 | ret = true; |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 585 | } |
| 586 | prof_dump_buf_end = 0; |
Jason Evans | 22ca855 | 2010-03-02 11:57:30 -0800 | [diff] [blame] | 587 | |
| 588 | return (ret); |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 589 | } |
| 590 | |
Jason Evans | 22ca855 | 2010-03-02 11:57:30 -0800 | [diff] [blame] | 591 | static bool |
Jason Evans | d81e4bd | 2012-03-06 14:57:45 -0800 | [diff] [blame] | 592 | prof_write(bool propagate_err, const char *s) |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 593 | { |
| 594 | unsigned i, slen, n; |
| 595 | |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 596 | cassert(config_prof); |
| 597 | |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 598 | i = 0; |
| 599 | slen = strlen(s); |
| 600 | while (i < slen) { |
| 601 | /* Flush the buffer if it is full. */ |
Jason Evans | cd9a134 | 2012-03-21 18:33:03 -0700 | [diff] [blame] | 602 | if (prof_dump_buf_end == PROF_DUMP_BUFSIZE) |
Jason Evans | 22ca855 | 2010-03-02 11:57:30 -0800 | [diff] [blame] | 603 | if (prof_flush(propagate_err) && propagate_err) |
| 604 | return (true); |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 605 | |
Jason Evans | cd9a134 | 2012-03-21 18:33:03 -0700 | [diff] [blame] | 606 | if (prof_dump_buf_end + slen <= PROF_DUMP_BUFSIZE) { |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 607 | /* Finish writing. */ |
| 608 | n = slen - i; |
| 609 | } else { |
| 610 | /* Write as much of s as will fit. */ |
Jason Evans | cd9a134 | 2012-03-21 18:33:03 -0700 | [diff] [blame] | 611 | n = PROF_DUMP_BUFSIZE - prof_dump_buf_end; |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 612 | } |
| 613 | memcpy(&prof_dump_buf[prof_dump_buf_end], &s[i], n); |
| 614 | prof_dump_buf_end += n; |
| 615 | i += n; |
| 616 | } |
Jason Evans | 22ca855 | 2010-03-02 11:57:30 -0800 | [diff] [blame] | 617 | |
| 618 | return (false); |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 619 | } |
| 620 | |
Jason Evans | d81e4bd | 2012-03-06 14:57:45 -0800 | [diff] [blame] | 621 | JEMALLOC_ATTR(format(printf, 2, 3)) |
| 622 | static bool |
| 623 | prof_printf(bool propagate_err, const char *format, ...) |
| 624 | { |
| 625 | bool ret; |
| 626 | va_list ap; |
Jason Evans | cd9a134 | 2012-03-21 18:33:03 -0700 | [diff] [blame] | 627 | char buf[PROF_PRINTF_BUFSIZE]; |
Jason Evans | d81e4bd | 2012-03-06 14:57:45 -0800 | [diff] [blame] | 628 | |
| 629 | va_start(ap, format); |
Jason Evans | 6da5418 | 2012-03-23 18:05:51 -0700 | [diff] [blame] | 630 | malloc_vsnprintf(buf, sizeof(buf), format, ap); |
Jason Evans | d81e4bd | 2012-03-06 14:57:45 -0800 | [diff] [blame] | 631 | va_end(ap); |
Jason Evans | cd9a134 | 2012-03-21 18:33:03 -0700 | [diff] [blame] | 632 | ret = prof_write(propagate_err, buf); |
Jason Evans | d81e4bd | 2012-03-06 14:57:45 -0800 | [diff] [blame] | 633 | |
| 634 | return (ret); |
| 635 | } |
| 636 | |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 637 | static void |
Jason Evans | a881cd2 | 2010-10-02 15:18:50 -0700 | [diff] [blame] | 638 | prof_ctx_sum(prof_ctx_t *ctx, prof_cnt_t *cnt_all, size_t *leak_nctx) |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 639 | { |
| 640 | prof_thr_cnt_t *thr_cnt; |
| 641 | prof_cnt_t tcnt; |
| 642 | |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 643 | cassert(config_prof); |
| 644 | |
Jason Evans | 6da5418 | 2012-03-23 18:05:51 -0700 | [diff] [blame] | 645 | malloc_mutex_lock(ctx->lock); |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 646 | |
Jason Evans | a881cd2 | 2010-10-02 15:18:50 -0700 | [diff] [blame] | 647 | memcpy(&ctx->cnt_summed, &ctx->cnt_merged, sizeof(prof_cnt_t)); |
| 648 | ql_foreach(thr_cnt, &ctx->cnts_ql, cnts_link) { |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 649 | volatile unsigned *epoch = &thr_cnt->epoch; |
| 650 | |
| 651 | while (true) { |
| 652 | unsigned epoch0 = *epoch; |
| 653 | |
| 654 | /* Make sure epoch is even. */ |
| 655 | if (epoch0 & 1U) |
| 656 | continue; |
| 657 | |
| 658 | memcpy(&tcnt, &thr_cnt->cnts, sizeof(prof_cnt_t)); |
| 659 | |
| 660 | /* Terminate if epoch didn't change while reading. */ |
| 661 | if (*epoch == epoch0) |
| 662 | break; |
| 663 | } |
| 664 | |
Jason Evans | a881cd2 | 2010-10-02 15:18:50 -0700 | [diff] [blame] | 665 | ctx->cnt_summed.curobjs += tcnt.curobjs; |
| 666 | ctx->cnt_summed.curbytes += tcnt.curbytes; |
| 667 | if (opt_prof_accum) { |
| 668 | ctx->cnt_summed.accumobjs += tcnt.accumobjs; |
| 669 | ctx->cnt_summed.accumbytes += tcnt.accumbytes; |
| 670 | } |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 671 | } |
| 672 | |
Jason Evans | 9ce3bfd | 2010-10-02 22:39:59 -0700 | [diff] [blame] | 673 | if (ctx->cnt_summed.curobjs != 0) |
| 674 | (*leak_nctx)++; |
| 675 | |
Jason Evans | a881cd2 | 2010-10-02 15:18:50 -0700 | [diff] [blame] | 676 | /* Add to cnt_all. */ |
| 677 | cnt_all->curobjs += ctx->cnt_summed.curobjs; |
| 678 | cnt_all->curbytes += ctx->cnt_summed.curbytes; |
| 679 | if (opt_prof_accum) { |
| 680 | cnt_all->accumobjs += ctx->cnt_summed.accumobjs; |
| 681 | cnt_all->accumbytes += ctx->cnt_summed.accumbytes; |
| 682 | } |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 683 | |
Jason Evans | 6da5418 | 2012-03-23 18:05:51 -0700 | [diff] [blame] | 684 | malloc_mutex_unlock(ctx->lock); |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 685 | } |
| 686 | |
Jason Evans | a881cd2 | 2010-10-02 15:18:50 -0700 | [diff] [blame] | 687 | static void |
| 688 | prof_ctx_destroy(prof_ctx_t *ctx) |
| 689 | { |
| 690 | |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 691 | cassert(config_prof); |
| 692 | |
Jason Evans | a881cd2 | 2010-10-02 15:18:50 -0700 | [diff] [blame] | 693 | /* |
| 694 | * Check that ctx is still unused by any thread cache before destroying |
Jason Evans | 0cdd42e | 2011-08-09 19:06:06 -0700 | [diff] [blame] | 695 | * it. prof_lookup() artificially raises ctx->cnt_merge.curobjs in |
| 696 | * order to avoid a race condition with this function, as does |
| 697 | * prof_ctx_merge() in order to avoid a race between the main body of |
| 698 | * prof_ctx_merge() and entry into this function. |
Jason Evans | a881cd2 | 2010-10-02 15:18:50 -0700 | [diff] [blame] | 699 | */ |
| 700 | prof_enter(); |
Jason Evans | 6da5418 | 2012-03-23 18:05:51 -0700 | [diff] [blame] | 701 | malloc_mutex_lock(ctx->lock); |
Jason Evans | b04a940 | 2010-10-27 19:47:40 -0700 | [diff] [blame] | 702 | if (ql_first(&ctx->cnts_ql) == NULL && ctx->cnt_merged.curobjs == 1) { |
Jason Evans | a881cd2 | 2010-10-02 15:18:50 -0700 | [diff] [blame] | 703 | assert(ctx->cnt_merged.curbytes == 0); |
| 704 | assert(ctx->cnt_merged.accumobjs == 0); |
| 705 | assert(ctx->cnt_merged.accumbytes == 0); |
| 706 | /* Remove ctx from bt2ctx. */ |
Jason Evans | a9076c9 | 2011-08-30 23:40:11 -0700 | [diff] [blame] | 707 | if (ckh_remove(&bt2ctx, ctx->bt, NULL, NULL)) |
| 708 | assert(false); |
Jason Evans | a881cd2 | 2010-10-02 15:18:50 -0700 | [diff] [blame] | 709 | prof_leave(); |
| 710 | /* Destroy ctx. */ |
Jason Evans | 6da5418 | 2012-03-23 18:05:51 -0700 | [diff] [blame] | 711 | malloc_mutex_unlock(ctx->lock); |
Jason Evans | a881cd2 | 2010-10-02 15:18:50 -0700 | [diff] [blame] | 712 | bt_destroy(ctx->bt); |
Jason Evans | a881cd2 | 2010-10-02 15:18:50 -0700 | [diff] [blame] | 713 | idalloc(ctx); |
| 714 | } else { |
Jason Evans | 0cdd42e | 2011-08-09 19:06:06 -0700 | [diff] [blame] | 715 | /* |
| 716 | * Compensate for increment in prof_ctx_merge() or |
| 717 | * prof_lookup(). |
| 718 | */ |
Jason Evans | b04a940 | 2010-10-27 19:47:40 -0700 | [diff] [blame] | 719 | ctx->cnt_merged.curobjs--; |
Jason Evans | 6da5418 | 2012-03-23 18:05:51 -0700 | [diff] [blame] | 720 | malloc_mutex_unlock(ctx->lock); |
Jason Evans | a881cd2 | 2010-10-02 15:18:50 -0700 | [diff] [blame] | 721 | prof_leave(); |
| 722 | } |
| 723 | } |
| 724 | |
| 725 | static void |
| 726 | prof_ctx_merge(prof_ctx_t *ctx, prof_thr_cnt_t *cnt) |
| 727 | { |
| 728 | bool destroy; |
| 729 | |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 730 | cassert(config_prof); |
| 731 | |
Jason Evans | a881cd2 | 2010-10-02 15:18:50 -0700 | [diff] [blame] | 732 | /* Merge cnt stats and detach from ctx. */ |
Jason Evans | 6da5418 | 2012-03-23 18:05:51 -0700 | [diff] [blame] | 733 | malloc_mutex_lock(ctx->lock); |
Jason Evans | a881cd2 | 2010-10-02 15:18:50 -0700 | [diff] [blame] | 734 | ctx->cnt_merged.curobjs += cnt->cnts.curobjs; |
| 735 | ctx->cnt_merged.curbytes += cnt->cnts.curbytes; |
| 736 | ctx->cnt_merged.accumobjs += cnt->cnts.accumobjs; |
| 737 | ctx->cnt_merged.accumbytes += cnt->cnts.accumbytes; |
| 738 | ql_remove(&ctx->cnts_ql, cnt, cnts_link); |
| 739 | if (opt_prof_accum == false && ql_first(&ctx->cnts_ql) == NULL && |
Jason Evans | b04a940 | 2010-10-27 19:47:40 -0700 | [diff] [blame] | 740 | ctx->cnt_merged.curobjs == 0) { |
| 741 | /* |
| 742 | * Artificially raise ctx->cnt_merged.curobjs in order to keep |
| 743 | * another thread from winning the race to destroy ctx while |
| 744 | * this one has ctx->lock dropped. Without this, it would be |
| 745 | * possible for another thread to: |
| 746 | * |
| 747 | * 1) Sample an allocation associated with ctx. |
| 748 | * 2) Deallocate the sampled object. |
| 749 | * 3) Successfully prof_ctx_destroy(ctx). |
| 750 | * |
| 751 | * The result would be that ctx no longer exists by the time |
| 752 | * this thread accesses it in prof_ctx_destroy(). |
| 753 | */ |
| 754 | ctx->cnt_merged.curobjs++; |
Jason Evans | a881cd2 | 2010-10-02 15:18:50 -0700 | [diff] [blame] | 755 | destroy = true; |
Jason Evans | b04a940 | 2010-10-27 19:47:40 -0700 | [diff] [blame] | 756 | } else |
Jason Evans | a881cd2 | 2010-10-02 15:18:50 -0700 | [diff] [blame] | 757 | destroy = false; |
Jason Evans | 6da5418 | 2012-03-23 18:05:51 -0700 | [diff] [blame] | 758 | malloc_mutex_unlock(ctx->lock); |
Jason Evans | a881cd2 | 2010-10-02 15:18:50 -0700 | [diff] [blame] | 759 | if (destroy) |
| 760 | prof_ctx_destroy(ctx); |
| 761 | } |
| 762 | |
Jason Evans | 22ca855 | 2010-03-02 11:57:30 -0800 | [diff] [blame] | 763 | static bool |
Jason Evans | d81e4bd | 2012-03-06 14:57:45 -0800 | [diff] [blame] | 764 | prof_dump_ctx(bool propagate_err, prof_ctx_t *ctx, prof_bt_t *bt) |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 765 | { |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 766 | unsigned i; |
| 767 | |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 768 | cassert(config_prof); |
| 769 | |
Jason Evans | a881cd2 | 2010-10-02 15:18:50 -0700 | [diff] [blame] | 770 | if (opt_prof_accum == false && ctx->cnt_summed.curobjs == 0) { |
| 771 | assert(ctx->cnt_summed.curbytes == 0); |
| 772 | assert(ctx->cnt_summed.accumobjs == 0); |
| 773 | assert(ctx->cnt_summed.accumbytes == 0); |
| 774 | return (false); |
| 775 | } |
| 776 | |
Jason Evans | d81e4bd | 2012-03-06 14:57:45 -0800 | [diff] [blame] | 777 | if (prof_printf(propagate_err, "%"PRId64": %"PRId64 |
| 778 | " [%"PRIu64": %"PRIu64"] @", |
| 779 | ctx->cnt_summed.curobjs, ctx->cnt_summed.curbytes, |
| 780 | ctx->cnt_summed.accumobjs, ctx->cnt_summed.accumbytes)) |
Jason Evans | 22ca855 | 2010-03-02 11:57:30 -0800 | [diff] [blame] | 781 | return (true); |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 782 | |
| 783 | for (i = 0; i < bt->len; i++) { |
Jason Evans | 2bb6c7a | 2012-03-12 13:38:00 -0700 | [diff] [blame] | 784 | if (prof_printf(propagate_err, " %#"PRIxPTR, |
Jason Evans | d81e4bd | 2012-03-06 14:57:45 -0800 | [diff] [blame] | 785 | (uintptr_t)bt->vec[i])) |
Jason Evans | 22ca855 | 2010-03-02 11:57:30 -0800 | [diff] [blame] | 786 | return (true); |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 787 | } |
| 788 | |
Jason Evans | d81e4bd | 2012-03-06 14:57:45 -0800 | [diff] [blame] | 789 | if (prof_write(propagate_err, "\n")) |
Jason Evans | 22ca855 | 2010-03-02 11:57:30 -0800 | [diff] [blame] | 790 | return (true); |
| 791 | |
| 792 | return (false); |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 793 | } |
| 794 | |
Jason Evans | 22ca855 | 2010-03-02 11:57:30 -0800 | [diff] [blame] | 795 | static bool |
| 796 | prof_dump_maps(bool propagate_err) |
Jason Evans | c717718 | 2010-02-11 09:25:56 -0800 | [diff] [blame] | 797 | { |
| 798 | int mfd; |
Jason Evans | cd9a134 | 2012-03-21 18:33:03 -0700 | [diff] [blame] | 799 | char filename[PATH_MAX + 1]; |
Jason Evans | c717718 | 2010-02-11 09:25:56 -0800 | [diff] [blame] | 800 | |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 801 | cassert(config_prof); |
| 802 | |
Jason Evans | cd9a134 | 2012-03-21 18:33:03 -0700 | [diff] [blame] | 803 | malloc_snprintf(filename, sizeof(filename), "/proc/%d/maps", |
| 804 | (int)getpid()); |
| 805 | mfd = open(filename, O_RDONLY); |
Jason Evans | c717718 | 2010-02-11 09:25:56 -0800 | [diff] [blame] | 806 | if (mfd != -1) { |
| 807 | ssize_t nread; |
| 808 | |
Jason Evans | d81e4bd | 2012-03-06 14:57:45 -0800 | [diff] [blame] | 809 | if (prof_write(propagate_err, "\nMAPPED_LIBRARIES:\n") && |
Jason Evans | 22ca855 | 2010-03-02 11:57:30 -0800 | [diff] [blame] | 810 | propagate_err) |
| 811 | return (true); |
Jason Evans | c717718 | 2010-02-11 09:25:56 -0800 | [diff] [blame] | 812 | nread = 0; |
| 813 | do { |
| 814 | prof_dump_buf_end += nread; |
Jason Evans | cd9a134 | 2012-03-21 18:33:03 -0700 | [diff] [blame] | 815 | if (prof_dump_buf_end == PROF_DUMP_BUFSIZE) { |
Jason Evans | c717718 | 2010-02-11 09:25:56 -0800 | [diff] [blame] | 816 | /* Make space in prof_dump_buf before read(). */ |
Jason Evans | 22ca855 | 2010-03-02 11:57:30 -0800 | [diff] [blame] | 817 | if (prof_flush(propagate_err) && propagate_err) |
| 818 | return (true); |
Jason Evans | c717718 | 2010-02-11 09:25:56 -0800 | [diff] [blame] | 819 | } |
| 820 | nread = read(mfd, &prof_dump_buf[prof_dump_buf_end], |
Jason Evans | cd9a134 | 2012-03-21 18:33:03 -0700 | [diff] [blame] | 821 | PROF_DUMP_BUFSIZE - prof_dump_buf_end); |
Jason Evans | c717718 | 2010-02-11 09:25:56 -0800 | [diff] [blame] | 822 | } while (nread > 0); |
Jason Evans | d34f9e7 | 2010-02-11 13:19:21 -0800 | [diff] [blame] | 823 | close(mfd); |
Jason Evans | 22ca855 | 2010-03-02 11:57:30 -0800 | [diff] [blame] | 824 | } else |
| 825 | return (true); |
| 826 | |
| 827 | return (false); |
Jason Evans | c717718 | 2010-02-11 09:25:56 -0800 | [diff] [blame] | 828 | } |
| 829 | |
Jason Evans | 22ca855 | 2010-03-02 11:57:30 -0800 | [diff] [blame] | 830 | static bool |
Jason Evans | d81e4bd | 2012-03-06 14:57:45 -0800 | [diff] [blame] | 831 | prof_dump(bool propagate_err, const char *filename, bool leakcheck) |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 832 | { |
| 833 | prof_cnt_t cnt_all; |
| 834 | size_t tabind; |
Jason Evans | 075e77c | 2010-09-20 19:53:25 -0700 | [diff] [blame] | 835 | union { |
| 836 | prof_bt_t *p; |
| 837 | void *v; |
| 838 | } bt; |
| 839 | union { |
| 840 | prof_ctx_t *p; |
| 841 | void *v; |
| 842 | } ctx; |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 843 | size_t leak_nctx; |
| 844 | |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 845 | cassert(config_prof); |
| 846 | |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 847 | prof_enter(); |
| 848 | prof_dump_fd = creat(filename, 0644); |
| 849 | if (prof_dump_fd == -1) { |
Jason Evans | 22ca855 | 2010-03-02 11:57:30 -0800 | [diff] [blame] | 850 | if (propagate_err == false) { |
Jason Evans | d81e4bd | 2012-03-06 14:57:45 -0800 | [diff] [blame] | 851 | malloc_printf( |
| 852 | "<jemalloc>: creat(\"%s\"), 0644) failed\n", |
| 853 | filename); |
Jason Evans | 22ca855 | 2010-03-02 11:57:30 -0800 | [diff] [blame] | 854 | if (opt_abort) |
| 855 | abort(); |
| 856 | } |
Jason Evans | 22ca855 | 2010-03-02 11:57:30 -0800 | [diff] [blame] | 857 | goto ERROR; |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | /* Merge per thread profile stats, and sum them in cnt_all. */ |
| 861 | memset(&cnt_all, 0, sizeof(prof_cnt_t)); |
| 862 | leak_nctx = 0; |
Jason Evans | 588a32c | 2010-10-02 22:38:14 -0700 | [diff] [blame] | 863 | for (tabind = 0; ckh_iter(&bt2ctx, &tabind, NULL, &ctx.v) == false;) |
Jason Evans | a881cd2 | 2010-10-02 15:18:50 -0700 | [diff] [blame] | 864 | prof_ctx_sum(ctx.p, &cnt_all, &leak_nctx); |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 865 | |
| 866 | /* Dump profile header. */ |
Jason Evans | 22ca855 | 2010-03-02 11:57:30 -0800 | [diff] [blame] | 867 | if (opt_lg_prof_sample == 0) { |
Jason Evans | d81e4bd | 2012-03-06 14:57:45 -0800 | [diff] [blame] | 868 | if (prof_printf(propagate_err, |
| 869 | "heap profile: %"PRId64": %"PRId64 |
| 870 | " [%"PRIu64": %"PRIu64"] @ heapprofile\n", |
| 871 | cnt_all.curobjs, cnt_all.curbytes, |
| 872 | cnt_all.accumobjs, cnt_all.accumbytes)) |
Jason Evans | 22ca855 | 2010-03-02 11:57:30 -0800 | [diff] [blame] | 873 | goto ERROR; |
| 874 | } else { |
Jason Evans | d81e4bd | 2012-03-06 14:57:45 -0800 | [diff] [blame] | 875 | if (prof_printf(propagate_err, |
| 876 | "heap profile: %"PRId64": %"PRId64 |
| 877 | " [%"PRIu64": %"PRIu64"] @ heap_v2/%"PRIu64"\n", |
| 878 | cnt_all.curobjs, cnt_all.curbytes, |
| 879 | cnt_all.accumobjs, cnt_all.accumbytes, |
| 880 | ((uint64_t)1U << opt_lg_prof_sample))) |
Jason Evans | 22ca855 | 2010-03-02 11:57:30 -0800 | [diff] [blame] | 881 | goto ERROR; |
Jason Evans | b9477e7 | 2010-03-01 20:15:26 -0800 | [diff] [blame] | 882 | } |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 883 | |
| 884 | /* Dump per ctx profile stats. */ |
Jason Evans | 075e77c | 2010-09-20 19:53:25 -0700 | [diff] [blame] | 885 | for (tabind = 0; ckh_iter(&bt2ctx, &tabind, &bt.v, &ctx.v) |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 886 | == false;) { |
Jason Evans | d81e4bd | 2012-03-06 14:57:45 -0800 | [diff] [blame] | 887 | if (prof_dump_ctx(propagate_err, ctx.p, bt.p)) |
Jason Evans | 22ca855 | 2010-03-02 11:57:30 -0800 | [diff] [blame] | 888 | goto ERROR; |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 889 | } |
| 890 | |
Jason Evans | c717718 | 2010-02-11 09:25:56 -0800 | [diff] [blame] | 891 | /* Dump /proc/<pid>/maps if possible. */ |
Jason Evans | 22ca855 | 2010-03-02 11:57:30 -0800 | [diff] [blame] | 892 | if (prof_dump_maps(propagate_err)) |
| 893 | goto ERROR; |
Jason Evans | c717718 | 2010-02-11 09:25:56 -0800 | [diff] [blame] | 894 | |
Jason Evans | 22ca855 | 2010-03-02 11:57:30 -0800 | [diff] [blame] | 895 | if (prof_flush(propagate_err)) |
| 896 | goto ERROR; |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 897 | close(prof_dump_fd); |
| 898 | prof_leave(); |
| 899 | |
| 900 | if (leakcheck && cnt_all.curbytes != 0) { |
Jason Evans | d81e4bd | 2012-03-06 14:57:45 -0800 | [diff] [blame] | 901 | malloc_printf("<jemalloc>: Leak summary: %"PRId64" byte%s, %" |
| 902 | PRId64" object%s, %zu context%s\n", |
| 903 | cnt_all.curbytes, (cnt_all.curbytes != 1) ? "s" : "", |
| 904 | cnt_all.curobjs, (cnt_all.curobjs != 1) ? "s" : "", |
| 905 | leak_nctx, (leak_nctx != 1) ? "s" : ""); |
| 906 | malloc_printf( |
| 907 | "<jemalloc>: Run pprof on \"%s\" for leak detail\n", |
| 908 | filename); |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 909 | } |
Jason Evans | 22ca855 | 2010-03-02 11:57:30 -0800 | [diff] [blame] | 910 | |
| 911 | return (false); |
| 912 | ERROR: |
| 913 | prof_leave(); |
| 914 | return (true); |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 915 | } |
| 916 | |
Jason Evans | d81e4bd | 2012-03-06 14:57:45 -0800 | [diff] [blame] | 917 | #define DUMP_FILENAME_BUFSIZE (PATH_MAX + 1) |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 918 | static void |
| 919 | prof_dump_filename(char *filename, char v, int64_t vseq) |
| 920 | { |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 921 | |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 922 | cassert(config_prof); |
| 923 | |
Jason Evans | b8c8be7 | 2012-03-05 12:26:26 -0800 | [diff] [blame] | 924 | if (vseq != UINT64_C(0xffffffffffffffff)) { |
Jason Evans | d81e4bd | 2012-03-06 14:57:45 -0800 | [diff] [blame] | 925 | /* "<prefix>.<pid>.<seq>.v<vseq>.heap" */ |
| 926 | malloc_snprintf(filename, DUMP_FILENAME_BUFSIZE, |
| 927 | "%s.%d.%"PRIu64".%c%"PRId64".heap", |
| 928 | opt_prof_prefix, (int)getpid(), prof_dump_seq, v, vseq); |
| 929 | } else { |
| 930 | /* "<prefix>.<pid>.<seq>.<v>.heap" */ |
| 931 | malloc_snprintf(filename, DUMP_FILENAME_BUFSIZE, |
| 932 | "%s.%d.%"PRIu64".%c.heap", |
| 933 | opt_prof_prefix, (int)getpid(), prof_dump_seq, v); |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 934 | } |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 935 | } |
| 936 | |
| 937 | static void |
| 938 | prof_fdump(void) |
| 939 | { |
| 940 | char filename[DUMP_FILENAME_BUFSIZE]; |
| 941 | |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 942 | cassert(config_prof); |
| 943 | |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 944 | if (prof_booted == false) |
| 945 | return; |
| 946 | |
Jason Evans | e733970 | 2010-10-23 18:37:06 -0700 | [diff] [blame] | 947 | if (opt_prof_prefix[0] != '\0') { |
| 948 | malloc_mutex_lock(&prof_dump_seq_mtx); |
Jason Evans | b8c8be7 | 2012-03-05 12:26:26 -0800 | [diff] [blame] | 949 | prof_dump_filename(filename, 'f', UINT64_C(0xffffffffffffffff)); |
Jason Evans | e733970 | 2010-10-23 18:37:06 -0700 | [diff] [blame] | 950 | malloc_mutex_unlock(&prof_dump_seq_mtx); |
Jason Evans | d81e4bd | 2012-03-06 14:57:45 -0800 | [diff] [blame] | 951 | prof_dump(false, filename, opt_prof_leak); |
Jason Evans | e733970 | 2010-10-23 18:37:06 -0700 | [diff] [blame] | 952 | } |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 953 | } |
| 954 | |
| 955 | void |
| 956 | prof_idump(void) |
| 957 | { |
Jason Evans | d81e4bd | 2012-03-06 14:57:45 -0800 | [diff] [blame] | 958 | char filename[PATH_MAX + 1]; |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 959 | |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 960 | cassert(config_prof); |
| 961 | |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 962 | if (prof_booted == false) |
| 963 | return; |
Jason Evans | d34f9e7 | 2010-02-11 13:19:21 -0800 | [diff] [blame] | 964 | malloc_mutex_lock(&enq_mtx); |
| 965 | if (enq) { |
| 966 | enq_idump = true; |
| 967 | malloc_mutex_unlock(&enq_mtx); |
| 968 | return; |
| 969 | } |
| 970 | malloc_mutex_unlock(&enq_mtx); |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 971 | |
Jason Evans | e733970 | 2010-10-23 18:37:06 -0700 | [diff] [blame] | 972 | if (opt_prof_prefix[0] != '\0') { |
| 973 | malloc_mutex_lock(&prof_dump_seq_mtx); |
| 974 | prof_dump_filename(filename, 'i', prof_dump_iseq); |
| 975 | prof_dump_iseq++; |
| 976 | malloc_mutex_unlock(&prof_dump_seq_mtx); |
Jason Evans | d81e4bd | 2012-03-06 14:57:45 -0800 | [diff] [blame] | 977 | prof_dump(false, filename, false); |
Jason Evans | e733970 | 2010-10-23 18:37:06 -0700 | [diff] [blame] | 978 | } |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 979 | } |
| 980 | |
Jason Evans | 22ca855 | 2010-03-02 11:57:30 -0800 | [diff] [blame] | 981 | bool |
| 982 | prof_mdump(const char *filename) |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 983 | { |
Jason Evans | 22ca855 | 2010-03-02 11:57:30 -0800 | [diff] [blame] | 984 | char filename_buf[DUMP_FILENAME_BUFSIZE]; |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 985 | |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 986 | cassert(config_prof); |
| 987 | |
Jason Evans | 22ca855 | 2010-03-02 11:57:30 -0800 | [diff] [blame] | 988 | if (opt_prof == false || prof_booted == false) |
| 989 | return (true); |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 990 | |
Jason Evans | 22ca855 | 2010-03-02 11:57:30 -0800 | [diff] [blame] | 991 | if (filename == NULL) { |
| 992 | /* No filename specified, so automatically generate one. */ |
Jason Evans | e733970 | 2010-10-23 18:37:06 -0700 | [diff] [blame] | 993 | if (opt_prof_prefix[0] == '\0') |
| 994 | return (true); |
Jason Evans | 22ca855 | 2010-03-02 11:57:30 -0800 | [diff] [blame] | 995 | malloc_mutex_lock(&prof_dump_seq_mtx); |
| 996 | prof_dump_filename(filename_buf, 'm', prof_dump_mseq); |
| 997 | prof_dump_mseq++; |
| 998 | malloc_mutex_unlock(&prof_dump_seq_mtx); |
| 999 | filename = filename_buf; |
| 1000 | } |
Jason Evans | d81e4bd | 2012-03-06 14:57:45 -0800 | [diff] [blame] | 1001 | return (prof_dump(true, filename, false)); |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 1002 | } |
| 1003 | |
| 1004 | void |
Jason Evans | e733970 | 2010-10-23 18:37:06 -0700 | [diff] [blame] | 1005 | prof_gdump(void) |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 1006 | { |
| 1007 | char filename[DUMP_FILENAME_BUFSIZE]; |
| 1008 | |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1009 | cassert(config_prof); |
| 1010 | |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 1011 | if (prof_booted == false) |
| 1012 | return; |
| 1013 | malloc_mutex_lock(&enq_mtx); |
| 1014 | if (enq) { |
Jason Evans | e733970 | 2010-10-23 18:37:06 -0700 | [diff] [blame] | 1015 | enq_gdump = true; |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 1016 | malloc_mutex_unlock(&enq_mtx); |
| 1017 | return; |
| 1018 | } |
| 1019 | malloc_mutex_unlock(&enq_mtx); |
| 1020 | |
Jason Evans | e733970 | 2010-10-23 18:37:06 -0700 | [diff] [blame] | 1021 | if (opt_prof_prefix[0] != '\0') { |
| 1022 | malloc_mutex_lock(&prof_dump_seq_mtx); |
| 1023 | prof_dump_filename(filename, 'u', prof_dump_useq); |
| 1024 | prof_dump_useq++; |
| 1025 | malloc_mutex_unlock(&prof_dump_seq_mtx); |
Jason Evans | d81e4bd | 2012-03-06 14:57:45 -0800 | [diff] [blame] | 1026 | prof_dump(false, filename, false); |
Jason Evans | e733970 | 2010-10-23 18:37:06 -0700 | [diff] [blame] | 1027 | } |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 1028 | } |
| 1029 | |
| 1030 | static void |
| 1031 | prof_bt_hash(const void *key, unsigned minbits, size_t *hash1, size_t *hash2) |
| 1032 | { |
| 1033 | size_t ret1, ret2; |
| 1034 | uint64_t h; |
| 1035 | prof_bt_t *bt = (prof_bt_t *)key; |
| 1036 | |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1037 | cassert(config_prof); |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 1038 | assert(minbits <= 32 || (SIZEOF_PTR == 8 && minbits <= 64)); |
| 1039 | assert(hash1 != NULL); |
| 1040 | assert(hash2 != NULL); |
| 1041 | |
Jason Evans | b8c8be7 | 2012-03-05 12:26:26 -0800 | [diff] [blame] | 1042 | h = hash(bt->vec, bt->len * sizeof(void *), |
| 1043 | UINT64_C(0x94122f335b332aea)); |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 1044 | if (minbits <= 32) { |
| 1045 | /* |
| 1046 | * Avoid doing multiple hashes, since a single hash provides |
| 1047 | * enough bits. |
| 1048 | */ |
| 1049 | ret1 = h & ZU(0xffffffffU); |
| 1050 | ret2 = h >> 32; |
| 1051 | } else { |
| 1052 | ret1 = h; |
| 1053 | ret2 = hash(bt->vec, bt->len * sizeof(void *), |
Jason Evans | b8c8be7 | 2012-03-05 12:26:26 -0800 | [diff] [blame] | 1054 | UINT64_C(0x8432a476666bbc13)); |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 1055 | } |
| 1056 | |
| 1057 | *hash1 = ret1; |
| 1058 | *hash2 = ret2; |
| 1059 | } |
| 1060 | |
| 1061 | static bool |
| 1062 | prof_bt_keycomp(const void *k1, const void *k2) |
| 1063 | { |
| 1064 | const prof_bt_t *bt1 = (prof_bt_t *)k1; |
| 1065 | const prof_bt_t *bt2 = (prof_bt_t *)k2; |
| 1066 | |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1067 | cassert(config_prof); |
| 1068 | |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 1069 | if (bt1->len != bt2->len) |
| 1070 | return (false); |
| 1071 | return (memcmp(bt1->vec, bt2->vec, bt1->len * sizeof(void *)) == 0); |
| 1072 | } |
| 1073 | |
Jason Evans | 6da5418 | 2012-03-23 18:05:51 -0700 | [diff] [blame] | 1074 | static malloc_mutex_t * |
| 1075 | prof_ctx_mutex_choose(void) |
| 1076 | { |
| 1077 | unsigned nctxs = atomic_add_u(&cum_ctxs, 1); |
| 1078 | |
| 1079 | return (&ctx_locks[(nctxs - 1) % PROF_NCTX_LOCKS]); |
| 1080 | } |
| 1081 | |
Jason Evans | 4d6a134 | 2010-10-20 19:05:59 -0700 | [diff] [blame] | 1082 | prof_tdata_t * |
| 1083 | prof_tdata_init(void) |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 1084 | { |
Jason Evans | 4d6a134 | 2010-10-20 19:05:59 -0700 | [diff] [blame] | 1085 | prof_tdata_t *prof_tdata; |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 1086 | |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1087 | cassert(config_prof); |
| 1088 | |
Jason Evans | 4d6a134 | 2010-10-20 19:05:59 -0700 | [diff] [blame] | 1089 | /* Initialize an empty cache for this thread. */ |
| 1090 | prof_tdata = (prof_tdata_t *)imalloc(sizeof(prof_tdata_t)); |
| 1091 | if (prof_tdata == NULL) |
| 1092 | return (NULL); |
| 1093 | |
| 1094 | if (ckh_new(&prof_tdata->bt2cnt, PROF_CKH_MINITEMS, |
| 1095 | prof_bt_hash, prof_bt_keycomp)) { |
| 1096 | idalloc(prof_tdata); |
| 1097 | return (NULL); |
| 1098 | } |
| 1099 | ql_new(&prof_tdata->lru_ql); |
| 1100 | |
Jason Evans | 5389146 | 2012-02-13 18:23:41 -0800 | [diff] [blame] | 1101 | prof_tdata->vec = imalloc(sizeof(void *) * PROF_BT_MAX); |
Jason Evans | 4d6a134 | 2010-10-20 19:05:59 -0700 | [diff] [blame] | 1102 | if (prof_tdata->vec == NULL) { |
Jason Evans | 4d6a134 | 2010-10-20 19:05:59 -0700 | [diff] [blame] | 1103 | ckh_delete(&prof_tdata->bt2cnt); |
| 1104 | idalloc(prof_tdata); |
| 1105 | return (NULL); |
| 1106 | } |
| 1107 | |
Jason Evans | 84f7cdb | 2012-03-02 15:59:45 -0800 | [diff] [blame] | 1108 | prof_tdata->prng_state = 0; |
Jason Evans | 4d6a134 | 2010-10-20 19:05:59 -0700 | [diff] [blame] | 1109 | prof_tdata->threshold = 0; |
| 1110 | prof_tdata->accum = 0; |
| 1111 | |
Jason Evans | cd9a134 | 2012-03-21 18:33:03 -0700 | [diff] [blame] | 1112 | prof_tdata_tsd_set(&prof_tdata); |
Jason Evans | 4d6a134 | 2010-10-20 19:05:59 -0700 | [diff] [blame] | 1113 | |
| 1114 | return (prof_tdata); |
| 1115 | } |
| 1116 | |
Jason Evans | cd9a134 | 2012-03-21 18:33:03 -0700 | [diff] [blame] | 1117 | void |
Jason Evans | 4d6a134 | 2010-10-20 19:05:59 -0700 | [diff] [blame] | 1118 | prof_tdata_cleanup(void *arg) |
| 1119 | { |
Jason Evans | 41b954e | 2011-08-08 17:10:07 -0700 | [diff] [blame] | 1120 | prof_thr_cnt_t *cnt; |
Jason Evans | cd9a134 | 2012-03-21 18:33:03 -0700 | [diff] [blame] | 1121 | prof_tdata_t *prof_tdata = *(prof_tdata_t **)arg; |
Jason Evans | 4d6a134 | 2010-10-20 19:05:59 -0700 | [diff] [blame] | 1122 | |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1123 | cassert(config_prof); |
| 1124 | |
Jason Evans | 41b954e | 2011-08-08 17:10:07 -0700 | [diff] [blame] | 1125 | /* |
Jason Evans | 0cdd42e | 2011-08-09 19:06:06 -0700 | [diff] [blame] | 1126 | * Delete the hash table. All of its contents can still be iterated |
| 1127 | * over via the LRU. |
Jason Evans | 41b954e | 2011-08-08 17:10:07 -0700 | [diff] [blame] | 1128 | */ |
| 1129 | ckh_delete(&prof_tdata->bt2cnt); |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 1130 | |
Jason Evans | 0cdd42e | 2011-08-09 19:06:06 -0700 | [diff] [blame] | 1131 | /* Iteratively merge cnt's into the global stats and delete them. */ |
Jason Evans | 41b954e | 2011-08-08 17:10:07 -0700 | [diff] [blame] | 1132 | while ((cnt = ql_last(&prof_tdata->lru_ql, lru_link)) != NULL) { |
Jason Evans | 41b954e | 2011-08-08 17:10:07 -0700 | [diff] [blame] | 1133 | ql_remove(&prof_tdata->lru_ql, cnt, lru_link); |
Jason Evans | 0cdd42e | 2011-08-09 19:06:06 -0700 | [diff] [blame] | 1134 | prof_ctx_merge(cnt->ctx, cnt); |
Jason Evans | 41b954e | 2011-08-08 17:10:07 -0700 | [diff] [blame] | 1135 | idalloc(cnt); |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 1136 | } |
Jason Evans | 41b954e | 2011-08-08 17:10:07 -0700 | [diff] [blame] | 1137 | |
| 1138 | idalloc(prof_tdata->vec); |
| 1139 | |
| 1140 | idalloc(prof_tdata); |
Jason Evans | cd9a134 | 2012-03-21 18:33:03 -0700 | [diff] [blame] | 1141 | prof_tdata = NULL; |
| 1142 | prof_tdata_tsd_set(&prof_tdata); |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 1143 | } |
| 1144 | |
| 1145 | void |
| 1146 | prof_boot0(void) |
| 1147 | { |
| 1148 | |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1149 | cassert(config_prof); |
| 1150 | |
Jason Evans | e733970 | 2010-10-23 18:37:06 -0700 | [diff] [blame] | 1151 | memcpy(opt_prof_prefix, PROF_PREFIX_DEFAULT, |
| 1152 | sizeof(PROF_PREFIX_DEFAULT)); |
| 1153 | } |
| 1154 | |
| 1155 | void |
| 1156 | prof_boot1(void) |
| 1157 | { |
| 1158 | |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1159 | cassert(config_prof); |
| 1160 | |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 1161 | /* |
Jason Evans | 0b270a9 | 2010-03-31 16:45:04 -0700 | [diff] [blame] | 1162 | * opt_prof and prof_promote must be in their final state before any |
| 1163 | * arenas are initialized, so this function must be executed early. |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 1164 | */ |
| 1165 | |
| 1166 | if (opt_prof_leak && opt_prof == false) { |
| 1167 | /* |
| 1168 | * Enable opt_prof, but in such a way that profiles are never |
| 1169 | * automatically dumped. |
| 1170 | */ |
| 1171 | opt_prof = true; |
Jason Evans | e733970 | 2010-10-23 18:37:06 -0700 | [diff] [blame] | 1172 | opt_prof_gdump = false; |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 1173 | prof_interval = 0; |
Jason Evans | a02fc08 | 2010-03-31 17:35:51 -0700 | [diff] [blame] | 1174 | } else if (opt_prof) { |
| 1175 | if (opt_lg_prof_interval >= 0) { |
| 1176 | prof_interval = (((uint64_t)1U) << |
| 1177 | opt_lg_prof_interval); |
| 1178 | } else |
| 1179 | prof_interval = 0; |
| 1180 | } |
Jason Evans | 0b270a9 | 2010-03-31 16:45:04 -0700 | [diff] [blame] | 1181 | |
Jason Evans | ae4c7b4 | 2012-04-02 07:04:34 -0700 | [diff] [blame^] | 1182 | prof_promote = (opt_prof && opt_lg_prof_sample > LG_PAGE); |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 1183 | } |
| 1184 | |
| 1185 | bool |
Jason Evans | e733970 | 2010-10-23 18:37:06 -0700 | [diff] [blame] | 1186 | prof_boot2(void) |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 1187 | { |
| 1188 | |
Jason Evans | 7372b15 | 2012-02-10 20:22:09 -0800 | [diff] [blame] | 1189 | cassert(config_prof); |
| 1190 | |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 1191 | if (opt_prof) { |
Jason Evans | 6da5418 | 2012-03-23 18:05:51 -0700 | [diff] [blame] | 1192 | unsigned i; |
| 1193 | |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 1194 | if (ckh_new(&bt2ctx, PROF_CKH_MINITEMS, prof_bt_hash, |
| 1195 | prof_bt_keycomp)) |
| 1196 | return (true); |
| 1197 | if (malloc_mutex_init(&bt2ctx_mtx)) |
| 1198 | return (true); |
Jason Evans | cd9a134 | 2012-03-21 18:33:03 -0700 | [diff] [blame] | 1199 | if (prof_tdata_tsd_boot()) { |
Jason Evans | 698805c | 2010-03-03 17:45:38 -0800 | [diff] [blame] | 1200 | malloc_write( |
| 1201 | "<jemalloc>: Error in pthread_key_create()\n"); |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 1202 | abort(); |
| 1203 | } |
| 1204 | |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 1205 | if (malloc_mutex_init(&prof_dump_seq_mtx)) |
| 1206 | return (true); |
| 1207 | |
| 1208 | if (malloc_mutex_init(&enq_mtx)) |
| 1209 | return (true); |
| 1210 | enq = false; |
Jason Evans | d34f9e7 | 2010-02-11 13:19:21 -0800 | [diff] [blame] | 1211 | enq_idump = false; |
Jason Evans | e733970 | 2010-10-23 18:37:06 -0700 | [diff] [blame] | 1212 | enq_gdump = false; |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 1213 | |
| 1214 | if (atexit(prof_fdump) != 0) { |
Jason Evans | 698805c | 2010-03-03 17:45:38 -0800 | [diff] [blame] | 1215 | malloc_write("<jemalloc>: Error in atexit()\n"); |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 1216 | if (opt_abort) |
| 1217 | abort(); |
| 1218 | } |
Jason Evans | 6da5418 | 2012-03-23 18:05:51 -0700 | [diff] [blame] | 1219 | |
| 1220 | ctx_locks = (malloc_mutex_t *)base_alloc(PROF_NCTX_LOCKS * |
| 1221 | sizeof(malloc_mutex_t)); |
| 1222 | if (ctx_locks == NULL) |
| 1223 | return (true); |
| 1224 | for (i = 0; i < PROF_NCTX_LOCKS; i++) { |
| 1225 | if (malloc_mutex_init(&ctx_locks[i])) |
| 1226 | return (true); |
| 1227 | } |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 1228 | } |
| 1229 | |
Jason Evans | b27805b | 2010-02-10 18:15:53 -0800 | [diff] [blame] | 1230 | #ifdef JEMALLOC_PROF_LIBGCC |
| 1231 | /* |
| 1232 | * Cause the backtracing machinery to allocate its internal state |
| 1233 | * before enabling profiling. |
| 1234 | */ |
| 1235 | _Unwind_Backtrace(prof_unwind_init_callback, NULL); |
| 1236 | #endif |
| 1237 | |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 1238 | prof_booted = true; |
| 1239 | |
| 1240 | return (false); |
| 1241 | } |
| 1242 | |
Jason Evans | 6109fe0 | 2010-02-10 10:37:56 -0800 | [diff] [blame] | 1243 | /******************************************************************************/ |