| 960 | } |
| 961 | |
| 962 | void cbm_mem_phase_mark(const char *label) { |
| 963 | cbm_memev_phase(label); /* waste sanitizer: dormant unless CBM_MEMWASTE=1 */ |
| 964 | if (!mem_phase_enabled()) { |
| 965 | return; |
| 966 | } |
| 967 | size_t now = mem_phase_committed(); |
| 968 | cbm_mutex_lock(&g_mem_phase_mutex); |
| 969 | if (g_mem_phase_open) { |
| 970 | int slot = -1; |
| 971 | for (int i = 0; i < g_mem_phase_count; i++) { |
| 972 | if (g_mem_phases[i].label == g_mem_phase_open || |
| 973 | strcmp(g_mem_phases[i].label, g_mem_phase_open) == 0) { |
| 974 | slot = i; |
| 975 | break; |
| 976 | } |
| 977 | } |
| 978 | if (slot < 0 && g_mem_phase_count < MEM_PHASE_SLOTS) { |
| 979 | slot = g_mem_phase_count++; |
| 980 | g_mem_phases[slot].label = g_mem_phase_open; |
| 981 | g_mem_phases[slot].bytes = 0; |
| 982 | g_mem_phases[slot].hits = 0; |
| 983 | } |
| 984 | if (slot >= 0) { |
| 985 | g_mem_phases[slot].bytes += (int64_t)now - (int64_t)g_mem_phase_baseline; |
| 986 | g_mem_phases[slot].hits++; |
| 987 | } |
| 988 | } |
| 989 | g_mem_phase_open = label; |
| 990 | g_mem_phase_baseline = now; |
| 991 | cbm_mutex_unlock(&g_mem_phase_mutex); |
| 992 | } |
| 993 | |
| 994 | void cbm_mem_phase_reset(void) { |
| 995 | if (!mem_phase_enabled()) { |
no test coverage detected