Files
hakmem/core/box/tiny_front_stats_box.h

59 lines
1.6 KiB
C
Raw Normal View History

// tiny_front_stats_box.h - Front class distribution counters (ENV gated)
#pragma once
#include <stdint.h>
#include <stdlib.h>
#include <stdatomic.h>
#include "../hakmem_build_flags.h"
#include "../hakmem_tiny_config.h"
extern _Atomic uint64_t g_tiny_front_alloc_class[TINY_NUM_CLASSES];
extern _Atomic uint64_t g_tiny_front_free_class[TINY_NUM_CLASSES];
static inline int tiny_front_class_stats_enabled(void) {
#if !HAKMEM_DEBUG_COUNTERS
return 0;
#else
static int g = -1;
if (__builtin_expect(g == -1, 0)) {
const char* e = getenv("HAKMEM_TINY_FRONT_CLASS_STATS");
g = (e && *e && *e != '0') ? 1 : 0;
}
return g;
#endif
}
static inline int tiny_front_class_stats_dump_enabled(void) {
#if !HAKMEM_DEBUG_COUNTERS
return 0;
#else
static int g = -1;
if (__builtin_expect(g == -1, 0)) {
const char* e = getenv("HAKMEM_TINY_FRONT_CLASS_STATS_DUMP");
const char* e2 = getenv("HAKMEM_TINY_FRONT_CLASS_STATS");
g = ((e && *e && *e != '0') || (e2 && *e2 && *e2 != '0')) ? 1 : 0;
}
return g;
#endif
}
static inline void tiny_front_alloc_stat_inc(int class_idx) {
#if HAKMEM_DEBUG_COUNTERS
if (__builtin_expect(tiny_front_class_stats_enabled(), 0)) {
atomic_fetch_add_explicit(&g_tiny_front_alloc_class[class_idx], 1, memory_order_relaxed);
}
#else
(void)class_idx;
#endif
}
static inline void tiny_front_free_stat_inc(int class_idx) {
#if HAKMEM_DEBUG_COUNTERS
if (__builtin_expect(tiny_front_class_stats_enabled(), 0)) {
atomic_fetch_add_explicit(&g_tiny_front_free_class[class_idx], 1, memory_order_relaxed);
}
#else
(void)class_idx;
#endif
}