| 529 | |
| 530 | #define PROF_RECENT_PRINT_BUFSIZE 65536 |
| 531 | JEMALLOC_COLD |
| 532 | void |
| 533 | prof_recent_alloc_dump(tsd_t *tsd, write_cb_t *write_cb, void *cbopaque) { |
| 534 | cassert(config_prof); |
| 535 | malloc_mutex_lock(tsd_tsdn(tsd), &prof_recent_dump_mtx); |
| 536 | buf_writer_t buf_writer; |
| 537 | buf_writer_init(tsd_tsdn(tsd), &buf_writer, write_cb, cbopaque, NULL, |
| 538 | PROF_RECENT_PRINT_BUFSIZE); |
| 539 | emitter_t emitter; |
| 540 | emitter_init(&emitter, emitter_output_json_compact, buf_writer_cb, |
| 541 | &buf_writer); |
| 542 | prof_recent_list_t temp_list; |
| 543 | |
| 544 | malloc_mutex_lock(tsd_tsdn(tsd), &prof_recent_alloc_mtx); |
| 545 | prof_recent_alloc_assert_count(tsd); |
| 546 | ssize_t dump_max = prof_recent_alloc_max_get(tsd); |
| 547 | ql_move(&temp_list, &prof_recent_alloc_list); |
| 548 | ssize_t dump_count = prof_recent_alloc_count; |
| 549 | prof_recent_alloc_count = 0; |
| 550 | prof_recent_alloc_assert_count(tsd); |
| 551 | malloc_mutex_unlock(tsd_tsdn(tsd), &prof_recent_alloc_mtx); |
| 552 | |
| 553 | emitter_begin(&emitter); |
| 554 | uint64_t sample_interval = (uint64_t)1U << lg_prof_sample; |
| 555 | emitter_json_kv(&emitter, "sample_interval", emitter_type_uint64, |
| 556 | &sample_interval); |
| 557 | emitter_json_kv(&emitter, "recent_alloc_max", emitter_type_ssize, |
| 558 | &dump_max); |
| 559 | emitter_json_array_kv_begin(&emitter, "recent_alloc"); |
| 560 | prof_recent_t *node; |
| 561 | ql_foreach(node, &temp_list, link) { |
| 562 | prof_recent_alloc_dump_node(&emitter, node); |
| 563 | } |
| 564 | emitter_json_array_end(&emitter); |
| 565 | emitter_end(&emitter); |
| 566 | |
| 567 | malloc_mutex_lock(tsd_tsdn(tsd), &prof_recent_alloc_mtx); |
| 568 | prof_recent_alloc_assert_count(tsd); |
| 569 | ql_concat(&temp_list, &prof_recent_alloc_list, link); |
| 570 | ql_move(&prof_recent_alloc_list, &temp_list); |
| 571 | prof_recent_alloc_count += dump_count; |
| 572 | prof_recent_alloc_restore_locked(tsd, &temp_list); |
| 573 | malloc_mutex_unlock(tsd_tsdn(tsd), &prof_recent_alloc_mtx); |
| 574 | |
| 575 | buf_writer_terminate(tsd_tsdn(tsd), &buf_writer); |
| 576 | malloc_mutex_unlock(tsd_tsdn(tsd), &prof_recent_dump_mtx); |
| 577 | |
| 578 | prof_recent_alloc_async_cleanup(tsd, &temp_list); |
| 579 | } |
| 580 | #undef PROF_RECENT_PRINT_BUFSIZE |
| 581 | |
| 582 | bool |
no test coverage detected