Add OBSERVE stats and auto tiny policy profile
This commit is contained in:
@ -8,6 +8,8 @@
|
||||
#define TINY_CLASS_STATS_BOX_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdatomic.h>
|
||||
#include <stdio.h>
|
||||
#include "../hakmem_tiny_config.h"
|
||||
|
||||
typedef struct TinyClassStatsThread {
|
||||
@ -18,25 +20,44 @@ typedef struct TinyClassStatsThread {
|
||||
|
||||
extern __thread TinyClassStatsThread g_tiny_class_stats;
|
||||
|
||||
// Global (cross-thread) aggregates for OBSERVE/LEARN
|
||||
extern _Atomic uint64_t g_tiny_class_stats_uc_miss_global[TINY_NUM_CLASSES];
|
||||
extern _Atomic uint64_t g_tiny_class_stats_warm_hit_global[TINY_NUM_CLASSES];
|
||||
extern _Atomic uint64_t g_tiny_class_stats_shared_lock_global[TINY_NUM_CLASSES];
|
||||
|
||||
static inline void tiny_class_stats_on_uc_miss(int ci) {
|
||||
if (ci >= 0 && ci < TINY_NUM_CLASSES) {
|
||||
g_tiny_class_stats.uc_miss[ci]++;
|
||||
atomic_fetch_add_explicit(&g_tiny_class_stats_uc_miss_global[ci],
|
||||
1, memory_order_relaxed);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void tiny_class_stats_on_warm_hit(int ci) {
|
||||
if (ci >= 0 && ci < TINY_NUM_CLASSES) {
|
||||
g_tiny_class_stats.warm_hit[ci]++;
|
||||
atomic_fetch_add_explicit(&g_tiny_class_stats_warm_hit_global[ci],
|
||||
1, memory_order_relaxed);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void tiny_class_stats_on_shared_lock(int ci) {
|
||||
if (ci >= 0 && ci < TINY_NUM_CLASSES) {
|
||||
g_tiny_class_stats.shared_lock[ci]++;
|
||||
atomic_fetch_add_explicit(&g_tiny_class_stats_shared_lock_global[ci],
|
||||
1, memory_order_relaxed);
|
||||
}
|
||||
}
|
||||
|
||||
// Optional: reset per-thread counters (cold path only).
|
||||
void tiny_class_stats_reset_thread(void);
|
||||
|
||||
// Snapshot helpers (cold path): copy current counters into caller-provided struct.
|
||||
void tiny_class_stats_snapshot_thread(TinyClassStatsThread* out);
|
||||
void tiny_class_stats_snapshot_global(TinyClassStatsThread* out);
|
||||
|
||||
// Simple stderr dump helpers (cold path)
|
||||
void tiny_class_stats_dump_thread(FILE* out, const char* tag);
|
||||
void tiny_class_stats_dump_global(FILE* out, const char* tag);
|
||||
|
||||
#endif // TINY_CLASS_STATS_BOX_H
|
||||
|
||||
Reference in New Issue
Block a user