72 lines
1.7 KiB
C
72 lines
1.7 KiB
C
|
|
// init_diag_box.h — 初期化時の診断(SIGSEGV ハンドラ、ベースライン、ビルドバナー)
|
|||
|
|
#ifndef INIT_DIAG_BOX_H
|
|||
|
|
#define INIT_DIAG_BOX_H
|
|||
|
|
|
|||
|
|
#include <signal.h>
|
|||
|
|
#include <string.h>
|
|||
|
|
#include <stdlib.h>
|
|||
|
|
|
|||
|
|
// Debug-only SIGSEGV handler (gated by HAKMEM_DEBUG_SEGV)
|
|||
|
|
static inline void box_diag_install_sigsegv_handler(void (*handler)(int)) {
|
|||
|
|
const char* dbg = getenv("HAKMEM_DEBUG_SEGV");
|
|||
|
|
if (!dbg || atoi(dbg) == 0) return;
|
|||
|
|
|
|||
|
|
struct sigaction sa;
|
|||
|
|
memset(&sa, 0, sizeof(sa));
|
|||
|
|
sa.sa_flags = SA_RESETHAND;
|
|||
|
|
sa.sa_handler = handler;
|
|||
|
|
sigaction(SIGSEGV, &sa, NULL);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
static inline void box_diag_record_baseline(void) {
|
|||
|
|
#ifdef __linux__
|
|||
|
|
memset(g_latency_histogram, 0, sizeof(g_latency_histogram));
|
|||
|
|
g_latency_samples = 0;
|
|||
|
|
|
|||
|
|
get_page_faults(&g_baseline_soft_pf, &g_baseline_hard_pf);
|
|||
|
|
g_baseline_rss_kb = get_rss_kb();
|
|||
|
|
|
|||
|
|
HAKMEM_LOG("Baseline: soft_pf=%lu, hard_pf=%lu, rss=%lu KB\n",
|
|||
|
|
(unsigned long)g_baseline_soft_pf,
|
|||
|
|
(unsigned long)g_baseline_hard_pf,
|
|||
|
|
(unsigned long)g_baseline_rss_kb);
|
|||
|
|
#endif
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
static inline void box_diag_print_banner(void) {
|
|||
|
|
const char* bf = "UNKNOWN";
|
|||
|
|
#ifdef HAKMEM_BUILD_RELEASE
|
|||
|
|
bf = "RELEASE";
|
|||
|
|
#elif defined(HAKMEM_BUILD_DEBUG)
|
|||
|
|
bf = "DEBUG";
|
|||
|
|
#endif
|
|||
|
|
(void)bf;
|
|||
|
|
HAKMEM_LOG(
|
|||
|
|
"[Build] Flavor=%s Flags: HEADER_CLASSIDX=%d, AGGRESSIVE_INLINE=%d, "
|
|||
|
|
"POOL_TLS_PHASE1=%d, POOL_TLS_PREWARM=%d\n",
|
|||
|
|
bf,
|
|||
|
|
#if HAKMEM_TINY_HEADER_CLASSIDX
|
|||
|
|
1,
|
|||
|
|
#else
|
|||
|
|
0,
|
|||
|
|
#endif
|
|||
|
|
#ifdef HAKMEM_TINY_AGGRESSIVE_INLINE
|
|||
|
|
1,
|
|||
|
|
#else
|
|||
|
|
0,
|
|||
|
|
#endif
|
|||
|
|
#ifdef HAKMEM_POOL_TLS_PHASE1
|
|||
|
|
1,
|
|||
|
|
#else
|
|||
|
|
0,
|
|||
|
|
#endif
|
|||
|
|
#ifdef HAKMEM_POOL_TLS_PREWARM
|
|||
|
|
1
|
|||
|
|
#else
|
|||
|
|
0
|
|||
|
|
#endif
|
|||
|
|
);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#endif // INIT_DIAG_BOX_H
|