Log the sizes of the caches, pools and tables under the perf trace, every 600 presents and with each memory snapshot.

Four "mem: sizes" lines give the entries and bytes of what no other line counted: the guest heap, physical maps, kernel region, lazily written ranges and the fixed kernel, setjmp, save-file, RomFS and zstd tables; pool records, mirrors, deferred destructions, upload and staging buffers, the device address table and the texture, sampler and slot caches; image views, descriptor spares, the completion queue, uniform snapshot arenas, recording copies and pins; and pipelines, layouts, stage libraries, job queues, the shader memory cache and the translator processes. Each subsystem reads its own counters under its lock; settings now count the replaced values they keep. Segment and scene lines say "-" for the world clock before it starts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-10 19:51:36 -05:00
parent ecd34fb513
commit ded13958de
18 changed files with 359 additions and 9 deletions

View File

@@ -3304,3 +3304,31 @@ void gfx_shader_carry_start(void) {
}
if (!plat_thread_spawn(carry_main, NULL, "shader carry", 0)) rt_log("gfx_shader: carry: cannot start the background pass");
}
// NX2NAVI_TRACE=perf "mem: sizes" (perf.c): the shader memory cache's entries with their SPIR-V and reflection bytes
// (kept for the life of the process), the remembered failures, the translation and load queues, and the translator
// processes. cache_lock is held shared: lookups go on, a translator's insert waits for the walk.
void gfx_shader_sizes(PerfSizes *s) {
uint64_t n = 0, spv = 0, refl = 0, failed = 0, xq = 0, lq = 0, procs = 0, busy = 0;
plat_mutex_lock_shared(&cache_lock);
for (int i = 0; i < BUCKETS; i++)
for (const GfxShader *g = buckets[i]; g; g = g->next) n++, spv += g->words * 4, refl += g->reflection_size;
plat_mutex_unlock_shared(&cache_lock);
plat_mutex_lock(&failed_lock);
for (int i = 0; i < FAILED_N; i++) failed += failed_used[i] != 0;
plat_mutex_unlock(&failed_lock);
plat_mutex_lock(&X.lock);
for (const XJob *j = X.head; j; j = j->next) xq++;
for (const XJob *j = X.lhead; j; j = j->next) lq++;
plat_mutex_unlock(&X.lock);
plat_mutex_lock(&S.lock);
for (int i = 0; i < MAX_SVC; i++) procs += S.s[i].child != NULL, busy += S.s[i].busy != 0;
plat_mutex_unlock(&S.lock);
perf_size(s, "shader memory cache", n, 0, spv + refl);
perf_size(s, "of it reflection", PERF_SIZE_NONE, 0, refl);
perf_size(s, "failed shader keys", failed, FAILED_N, PERF_SIZE_NONE);
perf_size(s, "translations queued", xq, 0, PERF_SIZE_NONE);
perf_size(s, "shader loads queued", lq, 0, PERF_SIZE_NONE);
perf_size(s, "translator processes", procs, MAX_SVC, PERF_SIZE_NONE);
perf_size(s, "busy", busy, 0, PERF_SIZE_NONE);
}