mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-19 15:09:58 -04:00
Time the hand-off to the present thread, the present call and other threads' acquire waits, and count the acquire's GPU wait once.
The perf lines could not see pacing. In the 0.10.0 fresh session (nx2navi.1.log, 7,974,927 bytes) all 666 windows read "pacing 0%" and "bound: cpu" and all 70 slow-frame lines "pacing 0.0 drain 0.0", while 610 windows had a 16.x ms interval at fps_limit 60 under the game's own limiter. The pacer's wait happened where perf does not count it: vk_backend.c present_image's wait for the present thread to take the previous picture was untimed, perf_end drops waits on any thread but the presenting and replay ones (a game may acquire its window image on another), and the acquire's GPU wait was counted twice, as pacing around b->fence_wait and as a fence wait inside vk_sync_fence_wait (F-7-04). - host.h: PERF_HANDOFF, the presenting thread's wait to hand the present thread the next picture, timed in present_image from under pl (where pending is read) and kept in PresentJob.handoff_ns. perf_end_any counts a wait on any other guest thread into a sum that perf_present adds to the frame before ft_frame reads its parts. - nvn_api_obj.c nvnWindowAcquireTexture: the pacer's sleep is timed with perf_end_any; the GPU wait counts only as the fence wait it is; one line names the threads that acquire and present once the first present is known. - vk_backend.c present_main: the TRACE=present line adds the present call's time (vkQueuePresentKHR, under the queue lock, where an overlay's frame limiter sleeps) and the job's hand-off wait; with trace=perf, a line per 60 presents gives the present thread's blit and submit, paced wait, present call (avg, max), time past target and the hand-off. - perf.c: "handoff" in the window line's shares and the slow-frame line, "hand-off" in the worst-frame lines and as a cause of its own for frames over 25 ms and the stutter map. The "bound:" rule stays as it is until play-test numbers exist. - 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[] (now sized from SM_CAUSES), and tools/stutter_map.py, whose cause and hitch patterns now take a hyphen. flight.c's frames.tsv gets a handoff_ms column (blocked_names checked against PERF_N), and tools/flight_view.py lists it. - tools/perf_summary.py reads the hand-off share, the present-thread lines and the TRACE=present lines, and prints percentiles of the present interval, paced wait, time past target, present call and hand-off. New tests/perf_summary_check.py makes lines with the runtime's format strings (checked against the C sources) and checks the percentiles, the window averages and the hand-off share, and that older lines without these fields still parse; tests/stutter_map_check.py gets a hand-off hitch and area cause, which the old patterns dropped. Diagnostics only: no wait, pacing or presentation change. Not reproduced before the change (it needs a game run with trace=perf). perf_summary_check, stutter_map_check, stutter_hitch_check, flight_flash_check and frame_step_check pass; every runtime file compiles with the dev flags after the host.h change, and the changed files add no -Wall -Wextra warnings. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
106
tests/perf_summary_check.py
Normal file
106
tests/perf_summary_check.py
Normal file
@@ -0,0 +1,106 @@
|
||||
"""tools/perf_summary.py reads the present side of a log: lines made with the runtime's format strings (copied below;
|
||||
keep them in step with runtime/perf.c perf_present and runtime/vk_backend.c present_main and present_window) give the
|
||||
present percentiles, the present thread's window averages and the render thread's hand-off share, and the lines of
|
||||
older logs (no hand-off share, no present call or hand-off on the `present:` lines) still parse.
|
||||
|
||||
python tests/perf_summary_check.py
|
||||
"""
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
TOOL = ROOT / 'tools' / 'perf_summary.py'
|
||||
|
||||
|
||||
def c_fmt(fmt, *args):
|
||||
"""A C printf format with %llu, %lld and %u as Python's %d and %% kept."""
|
||||
return fmt.replace('%llu', '%d').replace('%lld', '%d').replace('%u', '%d') % args
|
||||
|
||||
|
||||
# runtime/vk_backend.c present_main's TRACE=present line and present_window's line, as the C source has them
|
||||
PRESENT_OLD = 'present: frame %llu interval %.3f ms, game %.3f ms, waited %.3f ms, %.3f ms past target'
|
||||
PRESENT_TAIL = '; present call %.3f ms, hand-off %.3f ms'
|
||||
WINDOW = ('perf: present thread frame %llu: %llu presents; blit and submit avg %.2f ms, paced wait avg %.2f ms, present '
|
||||
'call avg %.2f ms max %.2f ms, past target avg %.2f ms; the presenting thread waited to hand over avg %.2f ms '
|
||||
'max %.2f ms')
|
||||
# runtime/perf.c perf_present's window line, its head to the shares (the rest is filled in below)
|
||||
PERF_HEAD = ('perf: frame %llu: interval avg %.2f ms max %.2f ms (%.1f fps); render thread blocked: pacing %.0f%% fence '
|
||||
'%.0f%% drain %.0f%% handoff %.0f%% pipeline build %.0f%% shader xlate %.0f%% texture %.0f%% (astc %.0f%%)')
|
||||
PERF_TAIL = ('; pipelines built in background 0, draws skipped pending 0, waited 0, waiting for a shader 0, one-shot waited '
|
||||
'0; textures uploaded 3 re-uploaded 0; slowest frame: xlate 0.0 ms texture 0.0 ms (astc 0.0) pipeline 0.0 ms '
|
||||
'fence 0.0 ms; shaders: 10 keys, 10 translated; render busy avg 5.00 ms; replay avg 3.00 ms; ab 0/60; world '
|
||||
'12.0 s; shader disk reads: 0 on the render thread (0.0 ms), 0 by the loaders')
|
||||
|
||||
|
||||
def source_has():
|
||||
"""The format strings above are still the runtime's (the C sources split them over string literals)."""
|
||||
def joined(path):
|
||||
text = path.read_text(encoding='utf-8')
|
||||
return re.sub(r'"\s*\n\s*"', '', text) # adjacent literals on following lines become one
|
||||
be, perf = joined(ROOT / 'runtime' / 'vk_backend.c'), joined(ROOT / 'runtime' / 'perf.c')
|
||||
for piece in (PRESENT_OLD + PRESENT_TAIL, WINDOW):
|
||||
assert piece in be, f'runtime/vk_backend.c no longer has: {piece}'
|
||||
assert PERF_HEAD in perf, f'runtime/perf.c no longer has: {PERF_HEAD}'
|
||||
|
||||
|
||||
def run(lines, lo=0):
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
log = Path(d) / 'nx2navi.log'
|
||||
log.write_text('\n'.join(lines) + '\n', encoding='utf-8')
|
||||
out = subprocess.run([sys.executable, str(TOOL), str(log), str(lo)], capture_output=True, text=True,
|
||||
encoding='utf-8', check=True).stdout
|
||||
return out
|
||||
|
||||
|
||||
def summary(out, head):
|
||||
found = [ln for ln in out.splitlines() if ln.startswith(head)]
|
||||
assert len(found) == 1, (head, out)
|
||||
return found[0]
|
||||
|
||||
|
||||
def main():
|
||||
source_has()
|
||||
lines = []
|
||||
# 100 presents of the new form: intervals 16.0..16.99 ms, then one 40 ms; the present call 0.1..1.09 ms; the
|
||||
# hand-off 2.0 ms each but one of 30 ms
|
||||
for i in range(100):
|
||||
lines.append('[host] ' + c_fmt(PRESENT_OLD + PRESENT_TAIL, 1000 + i, 16.0 + i / 100, 16.5, 1.0 + i / 100, 0.05,
|
||||
0.1 + i / 100, 30.0 if i == 50 else 2.0))
|
||||
lines.append('[host] ' + c_fmt(PRESENT_OLD + PRESENT_TAIL, 1100, 40.0, 40.0, 0.0, 0.5, 20.0, 2.0))
|
||||
lines.append('[host] ' + c_fmt(WINDOW, 1080, 60, 0.8, 1.5, 0.6, 1.09, 0.05, 2.5, 30.0))
|
||||
lines.append('[host] ' + c_fmt(WINDOW, 1140, 60, 1.0, 1.0, 1.0, 20.0, 0.10, 1.5, 3.0))
|
||||
lines.append('[host] ' + c_fmt(PERF_HEAD, 1080, 16.7, 40.0, 59.9, 0.0, 2.0, 0.0, 12.0, 0.0, 0.0, 1.0, 0.0) + PERF_TAIL)
|
||||
lines.append('[host] ' + c_fmt(PERF_HEAD, 1140, 16.7, 20.0, 59.9, 0.0, 2.0, 0.0, 18.0, 0.0, 0.0, 1.0, 0.0) + PERF_TAIL)
|
||||
out = run(lines)
|
||||
pres = summary(out, 'SUMMARY present:')
|
||||
# 101 intervals: p50 is the 51st smallest (16.50), p99 the 100th (16.99), max 40
|
||||
assert '101 presents' in pres and 'interval p50 16.50 p95 16.95 p99 16.99 max 40.00' in pres, pres
|
||||
assert 'present call p50 0.60 p95 1.05 p99 1.09 max 20.00' in pres, pres
|
||||
assert 'hand-off p50 2.00 p95 2.00 p99 2.00 max 30.00' in pres, pres
|
||||
win = summary(out, 'SUMMARY present thread:')
|
||||
assert '120 presents in 2 windows' in win and 'present call avg 0.80 ms max 20.00 ms' in win, win
|
||||
assert 'hand-off avg 2.00 ms max 30.00 ms' in win, win
|
||||
frames = summary(out, 'SUMMARY frames')
|
||||
assert 'blocked at the hand-off 15.0% of the time (the highest window 18%)' in frames, frames
|
||||
assert 'perf 1080: 59.9 fps max 40.00 pacing 0% handoff 12% pipe 0% tex 1%' in out, out
|
||||
|
||||
# an older log: no hand-off share on the perf line, no present call or hand-off on the present lines
|
||||
old_perf = PERF_HEAD.replace(' handoff %.0f%%', '')
|
||||
old = ['[host] ' + c_fmt(PRESENT_OLD, 2000 + i, 16.0 + i / 10, 16.5, 1.0, 0.0) for i in range(10)]
|
||||
old.append('[host] ' + c_fmt(old_perf, 2040, 16.7, 20.0, 59.9, 0.0, 2.0, 0.0, 0.0, 0.0, 1.0, 0.0) + PERF_TAIL)
|
||||
out = run(old)
|
||||
pres = summary(out, 'SUMMARY present:')
|
||||
assert '10 presents' in pres and 'interval p50 16.50' in pres and 'present call' not in pres, pres
|
||||
assert 'hand-off' not in pres, pres
|
||||
assert 'SUMMARY present thread' not in out, out
|
||||
frames = summary(out, 'SUMMARY frames')
|
||||
assert 'hand-off' not in frames and 'perf 2040: 59.9 fps max 20.00 pacing 0% pipe 0% tex 1%' in out, out
|
||||
print('perf_summary_check: ok')
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
||||
@@ -17,18 +17,20 @@ void rt_log(const char *fmt, ...) {
|
||||
logged++;
|
||||
}
|
||||
|
||||
// perf.c's causes, in its order (FT_C_*)
|
||||
static const char *const names[8] = {"pipeline", "translation", "texture", "fence", "pacing", "replay", "census",
|
||||
"unattributed"};
|
||||
// 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", "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[8] = {0};
|
||||
uint64_t part[SM_CAUSES] = {0};
|
||||
for (int i = 0; i < n; i++) {
|
||||
uint64_t d = (uint64_t)(ms * 1e6);
|
||||
clock_ns += d;
|
||||
part[7] = d;
|
||||
stutter_frame(++frame_no, clock_ns, d, part, names, 8, 7);
|
||||
part[OTHER] = d;
|
||||
stutter_frame(++frame_no, clock_ns, d, part, names, SM_CAUSES, OTHER);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,11 +57,11 @@ int main(void) {
|
||||
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[7];
|
||||
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[7] - charged0, 274000000ull);
|
||||
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);
|
||||
@@ -90,7 +92,7 @@ int main(void) {
|
||||
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[7], 600000000ull);
|
||||
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");
|
||||
|
||||
@@ -42,12 +42,16 @@ def main():
|
||||
'[host] ' + c_fmt('stutter: frame %llu at %.1f s, %.1f ms (frames about %.1f ms) in %s%s:%s; an episode of %d '
|
||||
"frames to frame %llu, %.1f ms the first, the parts above the first frame's", 1400, 90.0, 274.0,
|
||||
7.0, 'Kakariko Village', '', ' fence 77.1 replay 4.0 (charged to fence)', 3, 1402, 87.0),
|
||||
# a cause with a hyphen in its name
|
||||
'[host] ' + c_fmt('stutter: frame %llu at %.1f s, %.1f ms (frames about %.1f ms) in %s%s:', 1500, 95.0, 41.0, 7.0,
|
||||
'Kakariko Village', '') + ' hand-off 33.0 (charged to hand-off)',
|
||||
'[host] ' + c_fmt('stutter map (%s): %.1f min of play in %d areas; %llu hitches in play and %llu '
|
||||
'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',
|
||||
'hitches; in play by cause:', 'exit', 12.5, 2, 4, 1, 7) + ' pipeline 2 texture 1 hand-off 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)
|
||||
139.6, 4, 0.4)
|
||||
+ c_fmt('; %s %llu, %.1f ms avg', 'pipeline', 2, 30.2) + c_fmt('; %s %llu, %.1f ms avg', 'texture', 1, 19.0)
|
||||
+ c_fmt('; %s %llu, %.1f ms avg', 'hand-off', 1, 41.0)
|
||||
+ c_fmt('), 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',
|
||||
31.5, 1200, 1, 1, 4, 1, 40.2),
|
||||
@@ -68,22 +72,25 @@ def main():
|
||||
log = Path(d) / 'nx2navi.log'
|
||||
log.write_text('\n'.join(lines) + '\n', encoding='utf-8')
|
||||
block, hitches = stutter_map.read_log(log)
|
||||
assert block and block['head'][0] == 'exit' and block['head'][3] == '3', block and block['head']
|
||||
assert block and block['head'][0] == 'exit' and block['head'][3] == '4', block and block['head']
|
||||
a = block['areas'][0]
|
||||
assert a['name'] == 'Kakariko Village' and a['hitch'] == 3 and a['causes'] == {'pipeline': 2, 'texture': 1}, a
|
||||
assert a['name'] == 'Kakariko Village' and a['hitch'] == 4, a
|
||||
assert a['causes'] == {'pipeline': 2, 'texture': 1, 'hand-off': 1}, a
|
||||
assert a['pmiss'] == 4 and a['smiss'] == 1 and a['load'] == 1 and a['over25'] == 1, a
|
||||
assert block['areas'][1]['causes'] == {}, block['areas'][1]
|
||||
assert block['sum'] == (2, 1, 1, 1, 0), block['sum']
|
||||
p = block['pipes'][0]
|
||||
assert p['v'] == '1a2b3c4d' and p['f'] == '5e6f7a8b' and p['ready'] == 160 and p['misses'] == 3, p
|
||||
assert p['state'].startswith('new to this install'), p
|
||||
assert len(hitches) == 3 and hitches[0]['cause'] == 'pipeline' and hitches[1]['load'], hitches
|
||||
assert len(hitches) == 4 and hitches[0]['cause'] == 'pipeline' and hitches[1]['load'], hitches
|
||||
assert hitches[2]['ms'] == 274.0 and hitches[2]['cause'] == 'fence' and not hitches[2]['load'], hitches[2]
|
||||
assert hitches[3]['cause'] == 'hand-off', hitches[3]
|
||||
out = Path(d) / 'map.md'
|
||||
stutter_map.report([log], out)
|
||||
text = out.read_text(encoding='utf-8')
|
||||
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
|
||||
assert block['head'][5] == '7' and block['head'][6] == ' pipeline 2 texture 1 hand-off 1', block['head']
|
||||
assert '7 long frames left out' in text and '**4 hitches in play**' in text and '| Kakariko Village | 10.0 | 140 |' in text, text
|
||||
assert 'hand-off 1' in text, text
|
||||
print('stutter_map_check: ok')
|
||||
return 0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user