Cleanup: Wrap shared_pool debug fprintf in #if !HAKMEM_BUILD_RELEASE
- Lock stats (P0 instrumentation): ~10 fprintf wrapped - Stage stats (S1/S2/S3 breakdown): ~8 fprintf wrapped - Release build now has no-op stubs for stats init functions - Data collection APIs kept for learning layer compatibility
This commit is contained in:
@ -14,8 +14,9 @@
|
|||||||
#include <sys/mman.h> // For mmap/munmap (used in shared_pool_ensure_capacity_unlocked)
|
#include <sys/mman.h> // 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_acquire_count = 0; // Total lock acquisitions
|
||||||
static _Atomic uint64_t g_lock_release_count = 0; // Total lock releases
|
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
|
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");
|
fprintf(stderr, "===================================\n");
|
||||||
fflush(stderr);
|
fflush(stderr);
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
// Release build: No-op stubs
|
||||||
|
static inline void lock_stats_init(void) {}
|
||||||
|
#endif
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// SP Acquire Stage Statistics (Stage1/2/3 breakdown)
|
// 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];
|
static _Atomic uint64_t g_sp_stage3_hits[TINY_NUM_CLASSES_SS];
|
||||||
// Data collection gate (0=off, 1=on). 学習層からも有効化される。
|
// Data collection gate (0=off, 1=on). 学習層からも有効化される。
|
||||||
static int g_sp_stage_stats_enabled = 0;
|
static int g_sp_stage_stats_enabled = 0;
|
||||||
|
|
||||||
|
#if !HAKMEM_BUILD_RELEASE
|
||||||
// Logging gate for destructor(ENV: HAKMEM_SHARED_POOL_STAGE_STATS)
|
// 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
|
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, "\n=== SHARED POOL STAGE STATISTICS ===\n");
|
||||||
fprintf(stderr, "Per-class acquire_slab() stage hits (Stage1=EMPTY, Stage2=UNUSED, Stage3=new SS)\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++) {
|
for (int cls = 0; cls < TINY_NUM_CLASSES_SS; cls++) {
|
||||||
uint64_t s1 = atomic_load(&g_sp_stage1_hits[cls]);
|
uint64_t s1 = atomic_load(&g_sp_stage1_hits[cls]);
|
||||||
uint64_t s2 = atomic_load(&g_sp_stage2_hits[cls]);
|
uint64_t s2 = atomic_load(&g_sp_stage2_hits[cls]);
|
||||||
uint64_t s3 = atomic_load(&g_sp_stage3_hits[cls]);
|
uint64_t s3 = atomic_load(&g_sp_stage3_hits[cls]);
|
||||||
uint64_t total = s1 + s2 + s3;
|
uint64_t total = s1 + s2 + s3;
|
||||||
if (total == 0) continue; // Skip unused classes
|
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)s2, p2,
|
||||||
(unsigned long long)s3, p3);
|
(unsigned long long)s3, p3);
|
||||||
}
|
}
|
||||||
fprintf(stderr, "====================================\n");
|
fprintf(stderr, "====================================\n");
|
||||||
fflush(stderr);
|
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.
|
// Snapshot Tiny-related backend metrics for learner / observability.
|
||||||
void
|
void
|
||||||
|
|||||||
Reference in New Issue
Block a user