81 lines
3.1 KiB
C
81 lines
3.1 KiB
C
|
|
// pool_stats.inc.h — Box: L2 Pool statistics and snapshots
|
||
|
|
#ifndef POOL_STATS_INC_H
|
||
|
|
#define POOL_STATS_INC_H
|
||
|
|
|
||
|
|
void hak_pool_print_stats(void) {
|
||
|
|
if (!g_pool.initialized) return;
|
||
|
|
|
||
|
|
printf("\n========================================\n");
|
||
|
|
printf("L2 Pool Statistics\n");
|
||
|
|
printf("========================================\n");
|
||
|
|
|
||
|
|
uint64_t total_hits = 0, total_misses = 0, total_refills = 0, total_frees = 0;
|
||
|
|
|
||
|
|
for (int i = 0; i < POOL_NUM_CLASSES; i++) {
|
||
|
|
if (g_class_sizes[i] == 0) continue; // skip disabled dynamic class
|
||
|
|
total_hits += g_pool.hits[i];
|
||
|
|
total_misses += g_pool.misses[i];
|
||
|
|
total_refills += g_pool.refills[i];
|
||
|
|
total_frees += g_pool.frees[i];
|
||
|
|
|
||
|
|
printf("Class %zu KB:\n", g_class_sizes[i] / 1024);
|
||
|
|
printf(" Hits: %lu\n", (unsigned long)g_pool.hits[i]);
|
||
|
|
printf(" Misses: %lu\n", (unsigned long)g_pool.misses[i]);
|
||
|
|
printf(" Refills: %lu\n", (unsigned long)g_pool.refills[i]);
|
||
|
|
printf(" Frees: %lu\n", (unsigned long)g_pool.frees[i]);
|
||
|
|
|
||
|
|
if (g_pool.hits[i] + g_pool.misses[i] > 0) {
|
||
|
|
double hit_rate = (double)g_pool.hits[i] / (g_pool.hits[i] + g_pool.misses[i]) * 100.0;
|
||
|
|
printf(" Hit rate: %.1f%%\n", hit_rate);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
printf("\n----------------------------------------\n");
|
||
|
|
printf("Summary:\n");
|
||
|
|
printf(" Total hits: %lu\n", (unsigned long)total_hits);
|
||
|
|
printf(" Total misses: %lu\n", (unsigned long)total_misses);
|
||
|
|
printf(" Total refills: %lu\n", (unsigned long)total_refills);
|
||
|
|
printf(" Total frees: %lu\n", (unsigned long)total_frees);
|
||
|
|
printf(" Pages allocated: %lu\n", (unsigned long)g_pool.total_pages_allocated);
|
||
|
|
printf(" Bytes allocated: %lu KB\n", (unsigned long)(g_pool.total_bytes_allocated / 1024));
|
||
|
|
|
||
|
|
if (total_hits + total_misses > 0) {
|
||
|
|
double hit_rate = (double)total_hits / (total_hits + total_misses) * 100.0;
|
||
|
|
printf(" Overall hit rate: %.1f%%\n", hit_rate);
|
||
|
|
}
|
||
|
|
|
||
|
|
printf("========================================\n");
|
||
|
|
}
|
||
|
|
|
||
|
|
void hak_pool_stats_snapshot(uint64_t hits[], uint64_t misses[], uint64_t refills[], uint64_t frees[]) {
|
||
|
|
if (!g_pool.initialized) {
|
||
|
|
for (int i = 0; i < POOL_NUM_CLASSES; i++) {
|
||
|
|
if (hits) hits[i] = 0;
|
||
|
|
if (misses) misses[i] = 0;
|
||
|
|
if (refills) refills[i] = 0;
|
||
|
|
if (frees) frees[i] = 0;
|
||
|
|
}
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
for (int i = 0; i < POOL_NUM_CLASSES; i++) {
|
||
|
|
if (hits) hits[i] = g_pool.hits[i];
|
||
|
|
if (misses) misses[i] = g_pool.misses[i];
|
||
|
|
if (refills) refills[i] = g_pool.refills[i];
|
||
|
|
if (frees) frees[i] = g_pool.frees[i];
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
void hak_pool_extra_metrics_snapshot(uint64_t* trylock_attempts, uint64_t* trylock_success, uint64_t* ring_underflow) {
|
||
|
|
if (trylock_attempts) {
|
||
|
|
*trylock_attempts = atomic_load_explicit(&g_pool.trylock_attempts, memory_order_relaxed);
|
||
|
|
}
|
||
|
|
if (trylock_success) {
|
||
|
|
*trylock_success = atomic_load_explicit(&g_pool.trylock_success, memory_order_relaxed);
|
||
|
|
}
|
||
|
|
if (ring_underflow) {
|
||
|
|
*ring_underflow = atomic_load_explicit(&g_pool.ring_underflow, memory_order_relaxed);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
#endif // POOL_STATS_INC_H
|