66 lines
2.3 KiB
C
66 lines
2.3 KiB
C
// tiny_mem_stats_box.c - Memory accounting helpers for Tiny front components
|
|
|
|
#include "tiny_mem_stats_box.h"
|
|
|
|
#include <stdatomic.h>
|
|
#include <sys/types.h>
|
|
#include <stdio.h>
|
|
|
|
_Atomic long long g_tiny_mem_unified_cache_bytes = 0;
|
|
_Atomic long long g_tiny_mem_warm_pool_bytes = 0;
|
|
_Atomic long long g_tiny_mem_page_box_bytes = 0;
|
|
_Atomic long long g_tiny_mem_tls_magazine_bytes = 0;
|
|
_Atomic long long g_tiny_mem_policy_stats_bytes = 0;
|
|
|
|
static inline void tiny_mem_stats_add(_Atomic long long* target, ssize_t bytes) {
|
|
if (!target || bytes == 0) {
|
|
return;
|
|
}
|
|
atomic_fetch_add_explicit(target, (long long)bytes, memory_order_relaxed);
|
|
}
|
|
|
|
void tiny_mem_stats_add_unified(ssize_t bytes) {
|
|
tiny_mem_stats_add(&g_tiny_mem_unified_cache_bytes, bytes);
|
|
}
|
|
|
|
void tiny_mem_stats_add_warm(ssize_t bytes) {
|
|
tiny_mem_stats_add(&g_tiny_mem_warm_pool_bytes, bytes);
|
|
}
|
|
|
|
void tiny_mem_stats_add_pagebox(ssize_t bytes) {
|
|
tiny_mem_stats_add(&g_tiny_mem_page_box_bytes, bytes);
|
|
}
|
|
|
|
void tiny_mem_stats_add_tls_magazine(ssize_t bytes) {
|
|
tiny_mem_stats_add(&g_tiny_mem_tls_magazine_bytes, bytes);
|
|
}
|
|
|
|
void tiny_mem_stats_add_policy_stats(ssize_t bytes) {
|
|
tiny_mem_stats_add(&g_tiny_mem_policy_stats_bytes, bytes);
|
|
}
|
|
|
|
void tiny_mem_stats_dump(void) {
|
|
long long unified = atomic_load_explicit(&g_tiny_mem_unified_cache_bytes,
|
|
memory_order_relaxed);
|
|
long long warm = atomic_load_explicit(&g_tiny_mem_warm_pool_bytes,
|
|
memory_order_relaxed);
|
|
long long pagebox = atomic_load_explicit(&g_tiny_mem_page_box_bytes,
|
|
memory_order_relaxed);
|
|
long long tls_mag = atomic_load_explicit(&g_tiny_mem_tls_magazine_bytes,
|
|
memory_order_relaxed);
|
|
long long policy_stats = atomic_load_explicit(&g_tiny_mem_policy_stats_bytes,
|
|
memory_order_relaxed);
|
|
|
|
long long total = unified + warm + pagebox + tls_mag + policy_stats;
|
|
|
|
fprintf(stderr,
|
|
"[TINY_MEM_STATS] unified_cache=%lldKB warm_pool=%lldKB page_box=%lldKB "
|
|
"tls_mag=%lldKB policy_stats=%lldKB total=%lldKB\n",
|
|
unified / 1024,
|
|
warm / 1024,
|
|
pagebox / 1024,
|
|
tls_mag / 1024,
|
|
policy_stats / 1024,
|
|
total / 1024);
|
|
}
|