| 690 | } |
| 691 | |
| 692 | void cbm_mem_phase_mark(const char *label) { |
| 693 | if (!mem_phase_enabled()) { |
| 694 | return; |
| 695 | } |
| 696 | size_t now = mem_phase_committed(); |
| 697 | cbm_mutex_lock(&g_mem_phase_mutex); |
| 698 | if (g_mem_phase_open) { |
| 699 | int slot = -1; |
| 700 | for (int i = 0; i < g_mem_phase_count; i++) { |
| 701 | if (g_mem_phases[i].label == g_mem_phase_open || |
| 702 | strcmp(g_mem_phases[i].label, g_mem_phase_open) == 0) { |
| 703 | slot = i; |
| 704 | break; |
| 705 | } |
| 706 | } |
| 707 | if (slot < 0 && g_mem_phase_count < MEM_PHASE_SLOTS) { |
| 708 | slot = g_mem_phase_count++; |
| 709 | g_mem_phases[slot].label = g_mem_phase_open; |
| 710 | g_mem_phases[slot].bytes = 0; |
| 711 | g_mem_phases[slot].hits = 0; |
| 712 | } |
| 713 | if (slot >= 0) { |
| 714 | g_mem_phases[slot].bytes += (int64_t)now - (int64_t)g_mem_phase_baseline; |
| 715 | g_mem_phases[slot].hits++; |
| 716 | } |
| 717 | } |
| 718 | g_mem_phase_open = label; |
| 719 | g_mem_phase_baseline = now; |
| 720 | cbm_mutex_unlock(&g_mem_phase_mutex); |
| 721 | } |
| 722 | |
| 723 | void cbm_mem_phase_reset(void) { |
| 724 | if (!mem_phase_enabled()) { |
no test coverage detected