| 362 | } |
| 363 | |
| 364 | static size_t |
| 365 | prof_log_bt_index(tsd_t *tsd, prof_bt_t *bt) { |
| 366 | assert(prof_logging_state == prof_logging_state_started); |
| 367 | malloc_mutex_assert_owner(tsd_tsdn(tsd), &log_mtx); |
| 368 | |
| 369 | prof_bt_node_t dummy_node; |
| 370 | dummy_node.bt = *bt; |
| 371 | prof_bt_node_t *node; |
| 372 | |
| 373 | /* See if this backtrace is already cached in the table. */ |
| 374 | if (ckh_search(&log_bt_node_set, (void *)(&dummy_node), |
| 375 | (void **)(&node), NULL)) { |
| 376 | size_t sz = offsetof(prof_bt_node_t, vec) + |
| 377 | (bt->len * sizeof(void *)); |
| 378 | prof_bt_node_t *new_node = (prof_bt_node_t *) |
| 379 | iallocztm(tsd_tsdn(tsd), sz, sz_size2index(sz), false, NULL, |
| 380 | true, arena_get(TSDN_NULL, 0, true), true); |
| 381 | if (log_bt_first == NULL) { |
| 382 | log_bt_first = new_node; |
| 383 | log_bt_last = new_node; |
| 384 | } else { |
| 385 | log_bt_last->next = new_node; |
| 386 | log_bt_last = new_node; |
| 387 | } |
| 388 | |
| 389 | new_node->next = NULL; |
| 390 | new_node->index = log_bt_index; |
| 391 | /* |
| 392 | * Copy the backtrace: bt is inside a tdata or gctx, which |
| 393 | * might die before prof_log_stop is called. |
| 394 | */ |
| 395 | new_node->bt.len = bt->len; |
| 396 | memcpy(new_node->vec, bt->vec, bt->len * sizeof(void *)); |
| 397 | new_node->bt.vec = new_node->vec; |
| 398 | |
| 399 | log_bt_index++; |
| 400 | ckh_insert(tsd, &log_bt_node_set, (void *)new_node, NULL); |
| 401 | return new_node->index; |
| 402 | } else { |
| 403 | return node->index; |
| 404 | } |
| 405 | } |
| 406 | static size_t |
| 407 | prof_log_thr_index(tsd_t *tsd, uint64_t thr_uid, const char *name) { |
| 408 | assert(prof_logging_state == prof_logging_state_started); |
no test coverage detected