mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-16 13:59:56 -04:00
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>
101 lines
5.0 KiB
C
101 lines
5.0 KiB
C
// tests/stutter_hitch_check.py builds this: runtime/stutter_map.c's hitch rule on made-up frame times, with the few
|
|
// runtime functions it calls stubbed. A steady change of pace (the game drawing at 60 fps after 200) counts no hitch;
|
|
// isolated long frames each count one; a frame over SM_HITCH_SURE_NS counts whatever follows it.
|
|
#include <stdarg.h>
|
|
#include <stdio.h>
|
|
|
|
#include "../runtime/stutter_map.c"
|
|
|
|
static uint64_t clock_ns;
|
|
int cfg_bool(const char *name) { return !strcmp(name, "NX2NAVI_STUTTER_MAP"); }
|
|
uint64_t kern_now_ns(void) { return clock_ns; }
|
|
void plat_mutex_lock(PlatMutex *m) { (void)m; }
|
|
void plat_mutex_unlock(PlatMutex *m) { (void)m; }
|
|
static int logged;
|
|
void rt_log(const char *fmt, ...) {
|
|
(void)fmt;
|
|
logged++;
|
|
}
|
|
|
|
// perf.c's causes, in its order (FT_C_*); the frames below are charged to the last, unattributed
|
|
static const char *const names[] = {"pipeline", "translation", "texture", "fence", "pacing", "hand-off", "replay",
|
|
"census", "report", "unattributed"};
|
|
#define OTHER (SM_CAUSES - 1)
|
|
_Static_assert(sizeof names / sizeof *names == SM_CAUSES, "names follows perf.c's FT_C_* list");
|
|
static uint64_t frame_no;
|
|
|
|
static void frames(int n, double ms) {
|
|
uint64_t part[SM_CAUSES] = {0};
|
|
for (int i = 0; i < n; i++) {
|
|
uint64_t d = (uint64_t)(ms * 1e6);
|
|
clock_ns += d;
|
|
part[OTHER] = d;
|
|
stutter_frame(++frame_no, clock_ns, d, part, names, SM_CAUSES, OTHER);
|
|
}
|
|
}
|
|
|
|
static int fails;
|
|
static void expect(const char *what, uint64_t got, uint64_t want) {
|
|
if (got != want) printf("FAIL %s: %llu, expected %llu\n", what, (unsigned long long)got, (unsigned long long)want), fails++;
|
|
}
|
|
|
|
int main(void) {
|
|
stutter_map_init();
|
|
clock_ns = 10000000000ull; // well past any area load
|
|
frames(200, 5.0);
|
|
expect("steady 200 fps", areas[0].hitch, 0);
|
|
frames(300, 16.6); // the game's menus at 60 fps
|
|
expect("a change to 60 fps", areas[0].hitch, 0);
|
|
if (!paced_out) printf("FAIL the change of pace was not counted as one\n"), fails++;
|
|
frames(200, 7.0);
|
|
for (int k = 0; k < 5; k++) frames(1, 30.0), frames(60, 7.0); // five isolated spikes
|
|
expect("five isolated spikes", areas[0].hitch, 5);
|
|
frames(1, 150.0), frames(1, 150.0), frames(60, 7.0); // two long frames in a row: one episode of 300 ms
|
|
expect("two frames over the sure line", areas[0].hitch, 6);
|
|
expect("their episode's time", areas[0].worst_ns, 300000000ull);
|
|
frames(1, 40.0), frames(1, 40.0), frames(60, 7.0); // a double spike: one episode
|
|
expect("a double spike", areas[0].hitch, 7);
|
|
// three long frames, each followed by one as long, as after an area load in a session of 2026-11-13 (87, 91 and
|
|
// 96 ms): one episode, not three changes of pace
|
|
uint64_t paced0 = paced_out, charged0 = areas[0].cause_ns[OTHER];
|
|
frames(1, 87.0), frames(1, 91.0), frames(1, 96.0), frames(60, 7.0);
|
|
expect("three slow frames in a row", areas[0].hitch, 8);
|
|
expect("not a change of pace", paced_out, paced0);
|
|
expect("the episode's time", areas[0].cause_ns[OTHER] - charged0, 274000000ull);
|
|
// a change to 30 fps from 140: a run of long frames longer than SM_EPISODE_MAX, a change of pace
|
|
frames(200, 7.0);
|
|
frames(300, 33.3);
|
|
expect("a change to 30 fps", areas[0].hitch, 8);
|
|
frames(200, 7.0);
|
|
stutter_area("Kakariko"); // a load: what follows within SM_LOAD_NS is the load's
|
|
frames(1, 60.0), frames(30, 7.0);
|
|
expect("a spike right after a load (play)", areas[1].hitch, 0);
|
|
expect("a spike right after a load (load)", areas[1].load_hitch, 1);
|
|
clock_ns += 10000000000ull;
|
|
frames(60, 7.0);
|
|
stutter_load(); // the texture pool's load of an area, without the game's
|
|
frames(1, 60.0), frames(30, 7.0);
|
|
expect("a spike right after the pool's load (play)", areas[1].hitch, 0);
|
|
expect("a spike right after the pool's load (load)", areas[1].load_hitch, 2);
|
|
// At 30 fps every frame is over SM_HITCH_ANY_NS and so a candidate: a hitch followed by the steady frames ends at
|
|
// itself, not at the end of the slow run (an episode of 301 frames, 10 s long, before)
|
|
stutter_area("Lake Hylia");
|
|
clock_ns += 10000000000ull;
|
|
frames(200, 7.0);
|
|
frames(1, 150.0), frames(300, 33.3);
|
|
expect("150 ms then 300 frames at 30 fps", areas[2].hitch, 1);
|
|
expect("150 ms then 300 frames at 30 fps (worst)", areas[2].worst_ns, 150000000ull);
|
|
frames(200, 7.0); // the end of the slow run stands out from the frames after it: one more
|
|
stutter_area("Gerudo Valley");
|
|
clock_ns += 10000000000ull;
|
|
frames(200, 33.3); // a steady 30 fps with a 120 ms hitch every 60 frames: each counts
|
|
for (int k = 0; k < 5; k++) frames(1, 120.0), frames(59, 33.3);
|
|
expect("five hitches at 30 fps", areas[3].hitch, 5);
|
|
expect("five hitches at 30 fps (worst)", areas[3].worst_ns, 120000000ull);
|
|
expect("five hitches at 30 fps (their time)", areas[3].cause_ns[OTHER], 600000000ull);
|
|
if (!logged) printf("FAIL nothing was logged\n"), fails++;
|
|
if (fails) return 1;
|
|
printf("stutter_hitch_check: all checks passed\n");
|
|
return 0;
|
|
}
|