mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-19 15:09:58 -04:00
Make the stutter map name the areas without the perf trace, and count a hitch only when the frames after it are shorter: a hitch is now measured against the median of the last 32 frames, so a steady change of pace (the game drawing at 60 fps after 200) is no longer counted as a run of hitches.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
61
tests/stutter_hitch_check.c
Normal file
61
tests/stutter_hitch_check.c
Normal file
@@ -0,0 +1,61 @@
|
||||
// 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++;
|
||||
}
|
||||
|
||||
static const char *const names[7] = {"pipeline", "translation", "texture", "fence", "pacing", "replay", "unattributed"};
|
||||
static uint64_t frame_no;
|
||||
|
||||
static void frames(int n, double ms) {
|
||||
uint64_t part[7] = {0};
|
||||
for (int i = 0; i < n; i++) {
|
||||
uint64_t d = (uint64_t)(ms * 1e6);
|
||||
clock_ns += d;
|
||||
part[6] = d;
|
||||
stutter_frame(++frame_no, clock_ns, d, part, names, 7, 6);
|
||||
}
|
||||
}
|
||||
|
||||
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: the second stands out
|
||||
expect("two frames over the sure line", areas[0].hitch, 7);
|
||||
frames(1, 40.0), frames(1, 40.0), frames(60, 7.0); // a double spike: the second one counts
|
||||
expect("a double spike", areas[0].hitch, 8);
|
||||
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);
|
||||
if (!logged) printf("FAIL nothing was logged\n"), fails++;
|
||||
if (fails) return 1;
|
||||
printf("stutter_hitch_check: all checks passed\n");
|
||||
return 0;
|
||||
}
|
||||
40
tests/stutter_hitch_check.py
Normal file
40
tests/stutter_hitch_check.py
Normal file
@@ -0,0 +1,40 @@
|
||||
"""Build and run tests/stutter_hitch_check.c: runtime/stutter_map.c's hitch rule on made-up frame times. A steady
|
||||
change of pace is no hitch, isolated long frames are, and frames right after an area load count as the load's.
|
||||
|
||||
No GPU, no game files, any Python.
|
||||
|
||||
Usage: stutter_hitch_check.py
|
||||
"""
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
MSYS_BIN = Path(r'C:\msys64\ucrt64\bin')
|
||||
|
||||
|
||||
def compiler():
|
||||
"""$CC, else MSYS2 UCRT64's clang, else clang on PATH (as tests/diff/common.py picks it, without its Unicorn)."""
|
||||
if os.environ.get('CC'):
|
||||
return os.environ['CC']
|
||||
if os.name == 'nt' and (MSYS_BIN / 'clang.exe').exists():
|
||||
return str(MSYS_BIN / 'clang.exe')
|
||||
return shutil.which('clang') or 'clang'
|
||||
|
||||
|
||||
def main():
|
||||
work = ROOT / 'build' / 'test' / 'stutter_hitch'
|
||||
work.mkdir(parents=True, exist_ok=True)
|
||||
exe = work / ('stutter_hitch_check.exe' if os.name == 'nt' else 'stutter_hitch_check')
|
||||
env = dict(os.environ)
|
||||
if os.name == 'nt' and MSYS_BIN.exists():
|
||||
env['PATH'] = str(MSYS_BIN) + os.pathsep + env.get('PATH', '')
|
||||
subprocess.check_call([compiler(), '-std=gnu11', '-O1', '-Wall', '-Werror', '-I', str(ROOT / 'runtime'),
|
||||
str(ROOT / 'tests' / 'stutter_hitch_check.c'), '-o', str(exe)], env=env)
|
||||
return subprocess.run([str(exe)], env=env).returncode
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
||||
@@ -23,7 +23,8 @@ def main():
|
||||
src = C_SOURCE.read_text(encoding='utf-8')
|
||||
# the format strings the parser depends on must still be in the runtime
|
||||
for piece in ('stutter map (%s): %.1f min of play in %d areas; %llu hitches in play and %llu ',
|
||||
'"after area loads; in play by cause:"', 'stutter map: %s: %.1f min at %.0f fps; hitches %llu (%.2f a minute',
|
||||
'"after area loads; %llu long frames were a change of pace (the frames after them as long), not "',
|
||||
'"hitches; in play by cause:"', 'stutter map: %s: %.1f min at %.0f fps; hitches %llu (%.2f a minute',
|
||||
'"; %s %llu, %.1f ms avg"', '"), worst %.1f ms (frame %llu); over 25 ms %llu; after its "',
|
||||
'"loads %llu; draws that met a pipeline missing %llu, a shader %llu, %.1f ms on the replay thread"',
|
||||
'stutter: frame %llu at %.1f s, %.1f ms (frames about %.1f ms) in %s%s:', '" (charged to %s)"',
|
||||
@@ -37,7 +38,8 @@ def main():
|
||||
'[host] ' + c_fmt('stutter: frame %llu at %.1f s, %.1f ms (frames about %.1f ms) in %s%s:', 1300, 80.0, 60.0, 7.0,
|
||||
'Kakariko Village', ', after its load') + ' unattributed 55.0 (charged to unattributed)',
|
||||
'[host] ' + c_fmt('stutter map (%s): %.1f min of play in %d areas; %llu hitches in play and %llu '
|
||||
'after area loads; in play by cause:', 'exit', 12.5, 2, 3, 1) + ' pipeline 2 texture 1',
|
||||
'after area loads; %llu long frames were a change of pace (the frames after them as long), not '
|
||||
'hitches; in play by cause:', 'exit', 12.5, 2, 3, 1, 7) + ' pipeline 2 texture 1',
|
||||
'[host] ' + c_fmt('stutter map: %s: %.1f min at %.0f fps; hitches %llu (%.2f a minute', 'Kakariko Village', 10.0,
|
||||
139.6, 3, 0.3)
|
||||
+ c_fmt('; %s %llu, %.1f ms avg', 'pipeline', 2, 30.2) + c_fmt('; %s %llu, %.1f ms avg', 'texture', 1, 19.0)
|
||||
@@ -74,7 +76,8 @@ def main():
|
||||
out = Path(d) / 'map.md'
|
||||
stutter_map.report([log], out)
|
||||
text = out.read_text(encoding='utf-8')
|
||||
assert '**3 hitches in play**' in text and '| Kakariko Village | 10.0 | 140 |' in text, text
|
||||
assert block['head'][5] == '7' and block['head'][6] == ' pipeline 2 texture 1', block['head']
|
||||
assert '7 long frames left out' in text and '**3 hitches in play**' in text and '| Kakariko Village | 10.0 | 140 |' in text, text
|
||||
print('stutter_map_check: ok')
|
||||
return 0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user