| 78 | } |
| 79 | |
| 80 | bool cbm_mem_profile_enabled(void) { |
| 81 | int state = atomic_load_explicit(&g_profile_enabled, memory_order_acquire); |
| 82 | if (state >= 0) { |
| 83 | return state == 1; |
| 84 | } |
| 85 | char buf[CBM_SZ_32]; |
| 86 | bool on = cbm_safe_getenv("CBM_MEM_PROFILE", buf, sizeof(buf), NULL) != NULL && buf[0] == '1'; |
| 87 | if (on) { |
| 88 | char min_buf[CBM_SZ_32]; |
| 89 | if (cbm_safe_getenv("CBM_MEM_PROFILE_MIN", min_buf, sizeof(min_buf), NULL) != NULL) { |
| 90 | long parsed = strtol(min_buf, NULL, 10); |
| 91 | if (parsed > 0) { |
| 92 | g_profile_min = (size_t)parsed; |
| 93 | } |
| 94 | } |
| 95 | cbm_mutex_init(&g_profile_mutex); |
| 96 | } |
| 97 | atomic_store_explicit(&g_profile_enabled, on ? 1 : 0, memory_order_release); |
| 98 | return on; |
| 99 | } |
| 100 | |
| 101 | /* FNV-1a over the return addresses: cheap, and collisions merely merge two |
| 102 | * sites rather than corrupting counts. */ |
no test coverage detected