| 719 | } |
| 720 | |
| 721 | void cbm_mem_phase_mark(const char *label) { |
| 722 | if (!mem_phase_enabled()) { |
| 723 | return; |
| 724 | } |
| 725 | size_t now = mem_phase_committed(); |
| 726 | cbm_mutex_lock(&g_mem_phase_mutex); |
| 727 | if (g_mem_phase_open) { |
| 728 | int slot = -1; |
| 729 | for (int i = 0; i < g_mem_phase_count; i++) { |
| 730 | if (g_mem_phases[i].label == g_mem_phase_open || |
| 731 | strcmp(g_mem_phases[i].label, g_mem_phase_open) == 0) { |
| 732 | slot = i; |
| 733 | break; |
| 734 | } |
| 735 | } |
| 736 | if (slot < 0 && g_mem_phase_count < MEM_PHASE_SLOTS) { |
| 737 | slot = g_mem_phase_count++; |
| 738 | g_mem_phases[slot].label = g_mem_phase_open; |
| 739 | g_mem_phases[slot].bytes = 0; |
| 740 | g_mem_phases[slot].hits = 0; |
| 741 | } |
| 742 | if (slot >= 0) { |
| 743 | g_mem_phases[slot].bytes += (int64_t)now - (int64_t)g_mem_phase_baseline; |
| 744 | g_mem_phases[slot].hits++; |
| 745 | } |
| 746 | } |
| 747 | g_mem_phase_open = label; |
| 748 | g_mem_phase_baseline = now; |
| 749 | cbm_mutex_unlock(&g_mem_phase_mutex); |
| 750 | } |
| 751 | |
| 752 | void cbm_mem_phase_reset(void) { |
| 753 | if (!mem_phase_enabled()) { |
no test coverage detected