43 lines
1.4 KiB
C
43 lines
1.4 KiB
C
|
|
// tiny_front_stats_box.h - Front class distribution counters (ENV gated)
|
||
|
|
#pragma once
|
||
|
|
|
||
|
|
#include <stdint.h>
|
||
|
|
#include <stdlib.h>
|
||
|
|
#include <stdatomic.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) {
|
||
|
|
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;
|
||
|
|
}
|
||
|
|
|
||
|
|
static inline int tiny_front_class_stats_dump_enabled(void) {
|
||
|
|
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;
|
||
|
|
}
|
||
|
|
|
||
|
|
static inline void tiny_front_alloc_stat_inc(int class_idx) {
|
||
|
|
if (__builtin_expect(tiny_front_class_stats_enabled(), 0)) {
|
||
|
|
atomic_fetch_add_explicit(&g_tiny_front_alloc_class[class_idx], 1, memory_order_relaxed);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
static inline void tiny_front_free_stat_inc(int class_idx) {
|
||
|
|
if (__builtin_expect(tiny_front_class_stats_enabled(), 0)) {
|
||
|
|
atomic_fetch_add_explicit(&g_tiny_front_free_class[class_idx], 1, memory_order_relaxed);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|