diff --git a/core/hakmem_shared_pool.c b/core/hakmem_shared_pool.c index 7ff712e2..66f50574 100644 --- a/core/hakmem_shared_pool.c +++ b/core/hakmem_shared_pool.c @@ -14,8 +14,9 @@ #include // For mmap/munmap (used in shared_pool_ensure_capacity_unlocked) // ============================================================================ -// P0 Lock Contention Instrumentation +// P0 Lock Contention Instrumentation (Debug build only) // ============================================================================ +#if !HAKMEM_BUILD_RELEASE static _Atomic uint64_t g_lock_acquire_count = 0; // Total lock acquisitions static _Atomic uint64_t g_lock_release_count = 0; // Total lock releases static _Atomic uint64_t g_lock_acquire_slab_count = 0; // Locks from acquire_slab path @@ -54,6 +55,10 @@ static void __attribute__((destructor)) lock_stats_report(void) { fprintf(stderr, "===================================\n"); fflush(stderr); } +#else +// Release build: No-op stubs +static inline void lock_stats_init(void) {} +#endif // ============================================================================ // SP Acquire Stage Statistics (Stage1/2/3 breakdown) @@ -63,6 +68,8 @@ static _Atomic uint64_t g_sp_stage2_hits[TINY_NUM_CLASSES_SS]; static _Atomic uint64_t g_sp_stage3_hits[TINY_NUM_CLASSES_SS]; // Data collection gate (0=off, 1=on). 学習層からも有効化される。 static int g_sp_stage_stats_enabled = 0; + +#if !HAKMEM_BUILD_RELEASE // Logging gate for destructor(ENV: HAKMEM_SHARED_POOL_STAGE_STATS) static int g_sp_stage_stats_log_enabled = -1; // -1=uninitialized, 0=off, 1=on @@ -85,10 +92,10 @@ static void __attribute__((destructor)) sp_stage_stats_report(void) { fprintf(stderr, "\n=== SHARED POOL STAGE STATISTICS ===\n"); fprintf(stderr, "Per-class acquire_slab() stage hits (Stage1=EMPTY, Stage2=UNUSED, Stage3=new SS)\n"); - for (int cls = 0; cls < TINY_NUM_CLASSES_SS; cls++) { - uint64_t s1 = atomic_load(&g_sp_stage1_hits[cls]); - uint64_t s2 = atomic_load(&g_sp_stage2_hits[cls]); - uint64_t s3 = atomic_load(&g_sp_stage3_hits[cls]); + for (int cls = 0; cls < TINY_NUM_CLASSES_SS; cls++) { + uint64_t s1 = atomic_load(&g_sp_stage1_hits[cls]); + uint64_t s2 = atomic_load(&g_sp_stage2_hits[cls]); + uint64_t s3 = atomic_load(&g_sp_stage3_hits[cls]); uint64_t total = s1 + s2 + s3; if (total == 0) continue; // Skip unused classes @@ -104,9 +111,13 @@ static void __attribute__((destructor)) sp_stage_stats_report(void) { (unsigned long long)s2, p2, (unsigned long long)s3, p3); } - fprintf(stderr, "====================================\n"); - fflush(stderr); - } + fprintf(stderr, "====================================\n"); + fflush(stderr); +} +#else +// Release build: No-op stubs +static inline void sp_stage_stats_init(void) {} +#endif // Snapshot Tiny-related backend metrics for learner / observability. void