Charge the frames a memory-census walk overlapped to census, the memory report's time to a report part, and walk once at frame 3600N.

With mem_census = 1 and trace = perf, vk_memory.c census_main walks the address space for 100-240 ms on its own
thread, holding the process's address-space lock. The replaying thread's write-watch queries wait for that lock
("mem: slow write-watch query: 20-34 ms ... 0 pages written"), and ft_frame charged the frame to "replay": in the
0.10.0 fresh session (nx2navi.1.log, 7,974,927 bytes) 63 of the stutter map's 66 replay hitches sat beside such a
walk, 49 of them at frames 600N+1..3. The presenting thread's own 600-frame memory report (10-17 ms, timed in
vk_mem_census since b81a9561) went to "unattributed". And at frame 3600N, census_check walked on the presenting thread
and the same frame's heap_log started census_main's second walk.

- perf.c perf_census_walk brackets census_main's walk (atomics); ft_frame moves the part of a frame over 25 ms (or a
  stutter-map candidate) that overlapped the walk out of the replay part first, then out of the unattributed part,
  into "census". The rule is runtime/perf_census.h census_charge, capped by the overlap and the frame.
- A new cause "report": vk_mem_census feeds the report's time (perf_report_part), and so do perf.c's memory
  snapshots and its 600-frame sizes lines; the next frame takes it, so the overlap rule no longer has to infer it.
  The cause list changes together: perf.c FT_C_* and ft_cause_name, stutter_map.c SM_CAUSES and cause_short,
  tests/stutter_hitch_check.c names[].
- census_check records the frame it walked (perf_census_walked_frame); heap_log does not start census_main for that
  frame, so frame 3600N walks once. A frame stamp, not a time window, since prof_commit_census can fail and leave
  perf_note_wc uncalled.
- The "mem: process" line gives the walk's start and end on the run's clock and its length, so a play-test with
  mem_census = 0 can tell the walk from the presenting thread's report as the cause of the 600N+1 hitches.

New tests/census_charge_check.py builds runtime/perf_census.h alone: no overlap, partial, contained and still-running
walks, the charge from replay first, capped by the overlap and the parts, and 100,000 random frames in which the census
part never passes the frame; docs/building.md describes it. Diagnostics only: NX2NAVI_MEM_CENSUS defaults to 0, and
nothing in gameplay, pacing or the save changes. Not reproduced before the change (it needs a game run). The pass's
known-issues table, which should say that hitch counts are taken with mem_census = 0 and trace off, is not in the
repository. census_charge_check, stutter_hitch_check and stutter_map_check pass; every runtime file compiles with the
dev flags, and perf.c, stutter_map.c and vk_memory.c add no -Wall -Wextra warnings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-13 17:20:25 -05:00
parent 0472734008
commit af8e2a323b
9 changed files with 216 additions and 15 deletions

View File

@@ -128,6 +128,14 @@ extern void (*perf_gpu_stats)(PerfGpu *out);
// commit census). perf_wc_recent: the last such figure when it is at most max_age_ns old, else 0.
void perf_note_wc(uint64_t wc, uint64_t vram_used);
int perf_wc_recent(uint64_t max_age_ns, uint64_t *wc, uint64_t *vram_used);
// The frame-time summary's "census" and "report" parts (perf.c ft_frame). perf_census_walk(1) and (0) bracket a walk of
// the address space on another thread (vk_memory.c census_main): a frame that overlapped it has that much moved to
// "census". perf_report_part adds the time the memory report took on the presenting thread (vk_memory.c
// vk_mem_census), any thread, to the next present's "report". perf_census_walked_frame: the frame whose present walked
// the address space itself (perf.c census_check), UINT64_MAX before any, so a report of that frame skips its own walk.
void perf_census_walk(int begin);
void perf_report_part(uint64_t ns);
uint64_t perf_census_walked_frame(void);
// The performance overlay (perfmon.c): mode 0 off, 1 fps, 2 full. While it is on, perf_present hands every frame to
// perfmon_frame; full also takes the event counts (perf_count) and the GPU timestamps as NX2NAVI_TRACE=perf does.
void perf_set_overlay(int mode);