diff --git a/core/hakmem_debug.c b/core/hakmem_debug.c index 7e077171..c9708eae 100644 --- a/core/hakmem_debug.c +++ b/core/hakmem_debug.c @@ -4,6 +4,7 @@ // Date: 2025-10-21 #include "hakmem_debug.h" +#include "hakmem_env_cache.h" // Priority-2: ENV cache #include #include #include @@ -150,11 +151,8 @@ void hkm_timing_init(void) { if (g_initialized) return; #if !HAKMEM_BUILD_RELEASE - // Check HAKMEM_TIMING environment variable (gated behind !HAKMEM_BUILD_RELEASE) - const char* env = getenv("HAKMEM_TIMING"); - if (env && strcmp(env, "1") == 0) { - g_timing_enabled = 1; - } + // Priority-2: Use cached ENV (gated behind !HAKMEM_BUILD_RELEASE) + g_timing_enabled = HAK_ENV_TIMING_ENABLED(); #else g_timing_enabled = 0; // Always disabled in release builds #endif diff --git a/core/hakmem_env_cache.h b/core/hakmem_env_cache.h index c3e6bd3f..6b14b0ff 100644 --- a/core/hakmem_env_cache.h +++ b/core/hakmem_env_cache.h @@ -84,6 +84,9 @@ typedef struct { // ===== Warm Path: SmallMid (1 variable) ===== int smallmid_enable; // HAKMEM_SMALLMID_ENABLE (default: 0) + // ===== Cold Path: Debug/Timing (1 variable) ===== + int timing_enabled; // HAKMEM_TIMING (default: 0) + } HakEnvCache; // Global cache instance (initialized once at startup) @@ -268,10 +271,17 @@ static inline void hakmem_env_cache_init(void) { g_hak_env_cache.smallmid_enable = (e && atoi(e) == 1) ? 1 : 0; // default: 0 (OFF) } + // ===== Cold Path: Debug/Timing ===== + { + const char* e; + e = getenv("HAKMEM_TIMING"); + g_hak_env_cache.timing_enabled = (e && strcmp(e, "1") == 0) ? 1 : 0; // default: 0 (OFF) + } + #if !HAKMEM_BUILD_RELEASE // Debug: Print cache summary (stderr only) if (!g_hak_env_cache.quiet) { - fprintf(stderr, "[ENV_CACHE_INIT] Parsed %d ENV variables at startup\n", 47); + fprintf(stderr, "[ENV_CACHE_INIT] Parsed %d ENV variables at startup\n", 48); fprintf(stderr, "[ENV_CACHE_INIT] Hot path syscalls eliminated: ~2000/sec → 0/sec\n"); fflush(stderr); } @@ -334,4 +344,7 @@ static inline void hakmem_env_cache_init(void) { // Warm path: SmallMid #define HAK_ENV_SMALLMID_ENABLE() (g_hak_env_cache.smallmid_enable) +// Cold path: Debug/Timing +#define HAK_ENV_TIMING_ENABLED() (g_hak_env_cache.timing_enabled) + #endif // HAKMEM_ENV_CACHE_H