Phase 4c: Add master trace control (HAKMEM_TRACE)

Add unified trace control that allows enabling specific trace modules
using comma-separated values or "all" to enable everything.

New file: core/hakmem_trace_master.h
- HAKMEM_TRACE=all: Enable all trace modules
- HAKMEM_TRACE=ptr,refill,free,mailbox: Enable specific modules
- HAKMEM_TRACE_LEVEL=N: Set trace verbosity (1-3)
- hak_trace_check(): Check if module should enable tracing

Available trace modules:
  ptr, refill, superslab, ring, free, mailbox, registry

Priority order:
1. HAKMEM_QUIET=1 → suppress all
2. Specific module ENV (e.g., HAKMEM_PTR_TRACE=1)
3. HAKMEM_TRACE=module1,module2
4. Default → disabled

Updated files:
- core/tiny_refill.h: Use hak_trace_check() for refill tracing
- core/box/mailbox_box.c: Use hak_trace_check() for mailbox tracing

Performance: No regression (72.9M ops/s)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Moe Charm (CI)
2025-11-28 16:08:44 +09:00
parent 322d94ac6a
commit f36ebe83aa
3 changed files with 156 additions and 9 deletions

View File

@ -2,6 +2,7 @@
#pragma once
#include <stdatomic.h>
#include "hakmem_tiny_superslab.h"
#include "hakmem_trace_master.h" // Phase 4c: Master trace control
#include "slab_handle.h"
#include "tiny_sticky.h"
#include "tiny_ready.h"
@ -86,13 +87,13 @@ static inline SuperSlab* tiny_refill_try_fast(int class_idx, TinyTLSSlab* tls) {
}
}
}
// One-shot entry trace (env: HAKMEM_TINY_RF_TRACE), disabled in release builds
// One-shot entry trace (env: HAKMEM_TINY_RF_TRACE or HAKMEM_TRACE=refill)
// Phase 4c: Now uses hak_trace_check() for unified trace control
#if !HAKMEM_BUILD_RELEASE
do {
static int en = -1; static _Atomic int printed[8];
if (__builtin_expect(en == -1, 0)) {
const char* e = getenv("HAKMEM_TINY_RF_TRACE");
en = (e && atoi(e) != 0) ? 1 : 0;
en = hak_trace_check("HAKMEM_TINY_RF_TRACE", "refill");
}
if (en) {
int expected = 0;