mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-19 08:39:57 -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:
@@ -14,14 +14,14 @@ from pathlib import Path
|
||||
|
||||
from PIL import Image, ImageDraw
|
||||
|
||||
BLOCKED = ['pace_ms', 'fence_ms', 'drain_ms', 'pipe_ms', 'xlate_ms', 'tex_ms', 'astc_ms']
|
||||
BLOCKED = ['pace_ms', 'fence_ms', 'drain_ms', 'pipe_ms', 'xlate_ms', 'tex_ms', 'astc_ms', 'handoff_ms']
|
||||
# Counts that are 0 in a steady frame: any non-zero value is listed.
|
||||
RARE = ['shaders_xlated', 'pipe_built', 'pipe_waited', 'oneshot_waited', 'pipe_bg_used', 'draws_skip_pipe',
|
||||
'draws_skip_shader', 'tex_new', 'tex_alias', 'tex_up', 'tex_reup', 'wb_done', 'wb_skip']
|
||||
# Counts with a steady level: frames off the median by more than a quarter are listed.
|
||||
LEVEL = ['submits', 'passes', 'draws', 'draws_seen', 'clears', 'copies', 'dispatches']
|
||||
SHORT = {'interval_ms': 'ms', 'pace_ms': 'pace', 'fence_ms': 'fence', 'drain_ms': 'drain', 'pipe_ms': 'pipe',
|
||||
'xlate_ms': 'xlate', 'tex_ms': 'tex', 'astc_ms': 'astc'}
|
||||
'xlate_ms': 'xlate', 'tex_ms': 'tex', 'astc_ms': 'astc', 'handoff_ms': 'handoff'}
|
||||
|
||||
|
||||
def load(dump):
|
||||
|
||||
@@ -4,6 +4,12 @@
|
||||
|
||||
`mem: dirty` lines (vk_memory.c dirty census) are summarised per pool class (CPU_CACHED, CPU_UNCACHED, other): what
|
||||
a device-local mirror of buffer-bound pools would upload per frame and per submit, FlushMappedRange use, mirror size.
|
||||
|
||||
The present side (runtime/vk_backend.c present_main): the `present:` lines of NX2NAVI_TRACE=present give percentiles
|
||||
of the host present's interval, its paced wait, how far past its target it went, the present call and the presenting
|
||||
thread's hand-off wait (the last two only in logs that have them), and the `perf: present thread` lines of
|
||||
NX2NAVI_TRACE=perf the present thread's averages per window. The render thread's hand-off share is read from the perf
|
||||
lines that have it.
|
||||
"""
|
||||
import re
|
||||
import statistics
|
||||
@@ -14,6 +20,12 @@ PERF = re.compile(r'perf: frame (\d+): interval avg ([\d.]+) ms max ([\d.]+) ms
|
||||
GPU = re.compile(r'perf: frame (\d+): gpu avg (?:([\d.]+) ms|n/a).*?fence wait per frame: render thread ([\d.]+) ms, '
|
||||
r'other threads ([\d.]+) ms; vram (?:([\d.]+) of ([\d.]+) MiB|n/a).*?ram working set ([\d.]+) MiB, '
|
||||
r'private ([\d.]+) MiB; bound: (\w+)')
|
||||
HANDOFF = re.compile(r' handoff (\d+)% ')
|
||||
PRESENT = re.compile(r'present: frame (\d+) interval ([\d.]+) ms, game ([\d.]+) ms, waited ([\d.]+) ms, ([\d.]+) ms past '
|
||||
r'target(?:; present call ([\d.]+) ms, hand-off ([\d.]+) ms)?')
|
||||
PRESENT_WIN = re.compile(r'perf: present thread frame (\d+): (\d+) presents; blit and submit avg ([\d.]+) ms, paced wait '
|
||||
r'avg ([\d.]+) ms, present call avg ([\d.]+) ms max ([\d.]+) ms, past target avg ([\d.]+) ms; '
|
||||
r'the presenting thread waited to hand over avg ([\d.]+) ms max ([\d.]+) ms')
|
||||
SCHED = re.compile(r'sched: frame (\d+): (.*)')
|
||||
THREAD = re.compile(r'sched: (render )?(0x[0-9a-f]+) (p\d+ m\d+) run (\d+)% core (\d+)% host (\d+)% sleep (\d+)% '
|
||||
r'sync (\d+)% cv (\d+)% lock (\d+)% addr (\d+)% cpu (\d+)% blocks (\d+) preempted (\d+)')
|
||||
@@ -30,8 +42,34 @@ def dirty_fields(text):
|
||||
|
||||
|
||||
def p95(v):
|
||||
return pct(v, 0.95)
|
||||
|
||||
|
||||
def pct(v, q):
|
||||
"""The q quantile of v (nearest rank below), 0 for none."""
|
||||
v = sorted(v)
|
||||
return v[min(len(v) - 1, int(0.95 * len(v)))] if v else 0.0
|
||||
return v[min(len(v) - 1, int(q * len(v)))] if v else 0.0
|
||||
|
||||
|
||||
def present_summary(pres, wins):
|
||||
"""pres: {field: [ms]} of the window's `present:` lines; wins: the `perf: present thread` lines' fields."""
|
||||
if pres.get('interval'):
|
||||
parts = []
|
||||
for key, name in (('interval', 'interval'), ('waited', 'paced wait'), ('past', 'past target'),
|
||||
('call', 'present call'), ('handoff', 'hand-off')):
|
||||
v = pres.get(key)
|
||||
if v:
|
||||
parts.append(f'{name} p50 {pct(v, 0.5):.2f} p95 {pct(v, 0.95):.2f} p99 {pct(v, 0.99):.2f} '
|
||||
f'max {max(v):.2f}')
|
||||
print(f'SUMMARY present: {len(pres["interval"])} presents; ' + '; '.join(parts) + ' (ms)')
|
||||
if wins:
|
||||
n = sum(w[0] for w in wins)
|
||||
|
||||
def avg(i): # present-weighted mean of a window average
|
||||
return sum(w[i] * w[0] for w in wins) / n
|
||||
print(f'SUMMARY present thread: {n} presents in {len(wins)} windows; blit and submit avg {avg(1):.2f} ms, paced '
|
||||
f'wait avg {avg(2):.2f} ms, present call avg {avg(3):.2f} ms max {max(w[4] for w in wins):.2f} ms, past '
|
||||
f'target avg {avg(5):.2f} ms; hand-off avg {avg(6):.2f} ms max {max(w[7] for w in wins):.2f} ms')
|
||||
|
||||
|
||||
def dirty_summary(lines, frames):
|
||||
@@ -70,6 +108,7 @@ def main():
|
||||
hi = int(sys.argv[3]) if len(sys.argv) > 3 else 10**9
|
||||
fr, fps, mx, gpu, vram, ram, bound = None, [], [], [], [], [], {}
|
||||
dirty, dframes, dlast = [], [], None
|
||||
pres, wins, handoff = {}, [], []
|
||||
for line in open(sys.argv[1], encoding='utf-8', errors='replace'):
|
||||
if line.startswith('run_game:'):
|
||||
print(line.rstrip())
|
||||
@@ -87,7 +126,11 @@ def main():
|
||||
if lo < f <= hi:
|
||||
fps.append(float(m[4]))
|
||||
mx.append(float(m[3]))
|
||||
print(f'perf {f}: {m[4]} fps max {m[3]} pacing {m[5]}% pipe {m[6]}% tex {m[7]}%')
|
||||
h = HANDOFF.search(line)
|
||||
if h:
|
||||
handoff.append(int(h[1]))
|
||||
print(f'perf {f}: {m[4]} fps max {m[3]} pacing {m[5]}%' + (f' handoff {h[1]}%' if h else '') +
|
||||
f' pipe {m[6]}% tex {m[7]}%')
|
||||
elif m := GPU.search(line):
|
||||
f = int(m[1])
|
||||
if lo < f <= hi:
|
||||
@@ -99,6 +142,16 @@ def main():
|
||||
bound[m[9]] = bound.get(m[9], 0) + 1
|
||||
print(f' gpu {f}: {m[2] or "n/a"} ms, fence wait render {m[3]} other {m[4]} ms, '
|
||||
f'vram {m[5] or "n/a"} MiB, ram ws {m[7]} private {m[8]} MiB, bound {m[9]}')
|
||||
elif m := PRESENT_WIN.search(line):
|
||||
f = int(m[1])
|
||||
if lo < f <= hi:
|
||||
wins.append((int(m[2]), *(float(x) for x in m.groups()[2:])))
|
||||
elif m := PRESENT.search(line):
|
||||
f = int(m[1])
|
||||
if lo < f <= hi:
|
||||
for key, g in (('interval', 2), ('waited', 4), ('past', 5), ('call', 6), ('handoff', 7)):
|
||||
if m[g] is not None and (key != 'interval' or float(m[g]) > 0):
|
||||
pres.setdefault(key, []).append(float(m[g]))
|
||||
elif m := SCHED.search(line):
|
||||
fr = int(m[1])
|
||||
if lo < fr <= hi:
|
||||
@@ -110,13 +163,15 @@ def main():
|
||||
print(f' rw{m[1]}: {m[2]}')
|
||||
if fps:
|
||||
print(f'SUMMARY frames {lo}-{hi}: mean fps {statistics.mean(fps):.1f}, min window fps {min(fps):.1f}, '
|
||||
f'max frame {max(mx):.1f} ms')
|
||||
f'max frame {max(mx):.1f} ms' + (f', render thread blocked at the hand-off {statistics.mean(handoff):.1f}% '
|
||||
f'of the time (the highest window {max(handoff)}%)' if handoff else ''))
|
||||
if ram:
|
||||
g = f'gpu mean {statistics.mean(gpu):.2f} ms' if gpu else 'gpu n/a'
|
||||
v = f'vram max {max(u for u, _ in vram):.0f} of {vram[-1][1]:.0f} MiB' if vram else 'vram n/a'
|
||||
b = ', '.join(f'{k} {n}' for k, n in sorted(bound.items()))
|
||||
print(f'SUMMARY gpu: {g}, {v}, ram ws max {max(w for w, _ in ram):.0f} MiB, '
|
||||
f'private max {max(p for _, p in ram):.0f} MiB; bound windows: {b}')
|
||||
present_summary(pres, wins)
|
||||
dirty_summary(dirty, dframes)
|
||||
|
||||
|
||||
|
||||
@@ -27,13 +27,13 @@ HEAD = re.compile(r'stutter map \(([^)]*)\): ([\d.]+) min of play in (\d+) areas
|
||||
AREA = re.compile(r'stutter map: (.+?): ([\d.]+) min at (\d+) fps; hitches (\d+) \(([\d.]+) a minute(.*?)\), worst '
|
||||
r'([\d.]+) ms \(frame (\d+)\); over 25 ms (\d+); after its loads (\d+); draws that met a pipeline '
|
||||
r'missing (\d+), a shader (\d+), ([\d.]+) ms on the replay thread')
|
||||
CAUSE = re.compile(r'; (\w+) (\d+), ([\d.]+) ms avg')
|
||||
CAUSE = re.compile(r'; ([\w-]+) (\d+), ([\d.]+) ms avg') # hand-off has a hyphen
|
||||
PIPES = re.compile(r'stutter map: (\d+) pipelines draws met missing: (\d+) that this install had recorded before .*?, '
|
||||
r'(\d+) new to it, (\d+) with a shader translated in play, (\d+) still translating when met')
|
||||
PIPE = re.compile(r'stutter map: (mesh|vertex) (\S+)/(\S+) first met in (.+?): (\d+) draws met it missing, (\d+) its '
|
||||
r'shader, ([\d.]+) ms on the replay thread; usable after (\d+) ms at most \((\d+) times\); (.*)$')
|
||||
HITCH = re.compile(r'stutter: frame (\d+) at ([\d.]+) s, ([\d.]+) ms \(frames about ([\d.]+) ms\) in (.+?)(, after its '
|
||||
r'load)?: .*?\(charged to (\w+)\)')
|
||||
r'load)?: .*?\(charged to ([\w-]+)\)')
|
||||
|
||||
|
||||
def read_log(path):
|
||||
|
||||
Reference in New Issue
Block a user