fix(m0): judge game frames by what the screen showed and drop spoilt windows
- Frame rate, 1 % low and hitches come from msBetweenDisplayChange of the frames that reached the screen; frames never shown are counted apart and the presented rate is kept as presented_fps. A game presenting 60 fps while the screen changes every 167 ms now shows as the stutter it is. - A window whose capture failed, a busy window where the LLM finished no answer, and every busy window when the STT load failed are not counted. - A yielding window counts only when every Jarvis process got both its CPU and its GPU priority lowered. - The "game hardly drawing" floor applies only with Jarvis off or idle, so a game Jarvis slows that far still counts as harm. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1659,29 +1659,48 @@ def test_a_player_that_never_comes_back_is_tried_again_per_window_and_the_stage_
|
||||
|
||||
# --- game_frames: the user's game's frame times next to Jarvis, plain and yielding by priority --
|
||||
|
||||
# PresentMon 2.6 --v1_metrics with display tracking (--no_track_input), as the kit runs it.
|
||||
_PM_HEAD = ("Application,ProcessID,SwapChainAddress,Runtime,SyncInterval,PresentFlags,Dropped,TimeInSeconds,"
|
||||
"msInPresentAPI,msBetweenPresents\n")
|
||||
"msInPresentAPI,msBetweenPresents,AllowsTearing,PresentMode,msUntilRenderComplete,msUntilDisplayed,"
|
||||
"msBetweenDisplayChange,msFlipDelay,msUntilRenderStart,msGPUActive\n")
|
||||
|
||||
|
||||
def _pm_csv(frames_ms, chain="0x1", pid=7000, dropped=(), head=_PM_HEAD):
|
||||
t, lines = 0.0, []
|
||||
"""One row per presented frame; a shown frame's msBetweenDisplayChange is the time since the
|
||||
screen last changed (PresentMon writes 0 for a frame that was never shown)."""
|
||||
t, lines, since = 0.0, [], 0.0
|
||||
for i, ms in enumerate(frames_ms):
|
||||
t += ms / 1000
|
||||
lines.append(f"game.exe,{pid},{chain},DXGI,0,0,{1 if i in dropped else 0},{t:.4f},0.1,{ms}")
|
||||
since += ms
|
||||
gone = i in dropped
|
||||
lines.append(f"game.exe,{pid},{chain},DXGI,0,0,{1 if gone else 0},{t:.4f},0.1,{ms},0,"
|
||||
f"Hardware: Independent Flip,1.0,2.0,{0 if gone else round(since, 4)},0,0.5,3.0")
|
||||
if not gone:
|
||||
since = 0.0
|
||||
return head + "\n".join(lines) + "\n"
|
||||
|
||||
|
||||
def test_frame_stats_read_the_main_swap_chain_with_rate_one_percent_low_and_hitches():
|
||||
from m0lib import frames
|
||||
main = [10.0] * 200 + [60.0, 120.0]
|
||||
text = _pm_csv(main, dropped={5}) + _pm_csv([500.0] * 5, chain="0x2", head="")
|
||||
text = _pm_csv(main) + _pm_csv([500.0] * 5, chain="0x2", head="")
|
||||
g = frames.frame_stats(frames.parse_csv(text), 3.0)
|
||||
counted = main[1:] # the first row's interval reaches back before the capture
|
||||
assert g["valid"] and g["frames"] == len(counted)
|
||||
counted = main[2:] # the first rows' intervals reach back before the capture
|
||||
assert g["valid"] and g["frames"] == len(counted) and g["not_shown"] == 0
|
||||
assert g["fps"] == round(len(counted) / (sum(counted) / 1000), 1)
|
||||
p99 = sorted(counted)[int(len(counted) * 0.99)]
|
||||
assert g["low1_fps"] == round(1000 / p99, 1) and g["max_ms"] == 120.0
|
||||
assert g["hitches_over_ms"] == {"50": 2, "100": 1} and g["not_shown"] == 1
|
||||
assert g["hitches_over_ms"] == {"50": 2, "100": 1}
|
||||
|
||||
|
||||
def test_frames_the_screen_never_showed_count_as_a_stutter_even_when_the_game_presents_smoothly():
|
||||
from m0lib import frames
|
||||
# The game presents every 16.7 ms, but only every tenth frame reaches the screen.
|
||||
rows = frames.parse_csv(_pm_csv([16.67] * 3600, dropped={i for i in range(3600) if i % 10}))
|
||||
g = frames.frame_stats(rows, 60)
|
||||
assert g["presented_fps"] == round(1000 / 16.67, 1) and g["not_shown"] > 3000
|
||||
assert g["fps"] < 7 and g["low1_fps"] < 7 and g["hitches_over_ms"]["100"] == g["frames"]
|
||||
assert g["valid"] # a stutter is the harm being measured, not a spoilt window
|
||||
|
||||
|
||||
def test_frame_stats_read_presentmon_2_column_names_too():
|
||||
@@ -1693,8 +1712,11 @@ def test_frame_stats_read_presentmon_2_column_names_too():
|
||||
def test_a_window_where_the_game_drew_nothing_or_almost_nothing_is_not_counted():
|
||||
from m0lib import frames
|
||||
assert not frames.frame_stats([], 60)["valid"]
|
||||
few = frames.frame_stats(frames.parse_csv(_pm_csv([1000.0] * 30)), 60)
|
||||
assert not few["valid"] and "frames" in few["invalid_because"][0]
|
||||
few = frames.parse_csv(_pm_csv([1000.0] * 30))
|
||||
# With Jarvis off or idle that means the game was not drawing; next to a busy Jarvis it is a stutter.
|
||||
off = frames.frame_stats(few, 60, frames.MIN_FRAMES)
|
||||
assert not off["valid"] and "frames" in off["invalid_because"][0]
|
||||
assert frames.frame_stats(few, 60)["valid"]
|
||||
|
||||
|
||||
def test_compare_pools_the_valid_windows_against_the_game_alone():
|
||||
@@ -1741,7 +1763,9 @@ def test_yield_lowers_cpu_and_gpu_priority_and_puts_back_what_each_process_had(m
|
||||
assert pr.now[1] == (0x20, 2) and pr.now[2] == (0x8000, 2)
|
||||
s = y.summary()
|
||||
assert s == {"processes": 3, "cpu_lowered": 2, "gpu_lowered": 2, "restored": 2, "not_restored": 1}
|
||||
assert frames.yield_problems(s) == ["1 process(es) kept the lowered priority"]
|
||||
assert frames.yield_problems(s) == ["yield lowered the CPU priority of only 2 of 3 processes",
|
||||
"yield lowered the GPU priority of only 2 of 3 processes",
|
||||
"1 process(es) kept the lowered priority"]
|
||||
assert frames.yield_problems(frames.Yield([]).summary()) == ["yield found no Jarvis process"]
|
||||
|
||||
|
||||
@@ -1770,7 +1794,8 @@ def test_presentmon_records_only_the_game_for_a_fixed_time_and_a_bad_download_is
|
||||
GAME_PID = 7000
|
||||
|
||||
|
||||
def _run_frames_stage(tmp_path, monkeypatch, fake_server, admin=True, front=(GAME_PID, "game.exe"), pr=None):
|
||||
def _run_frames_stage(tmp_path, monkeypatch, fake_server, admin=True, front=(GAME_PID, "game.exe"), pr=None,
|
||||
capture_err=None, stt=None):
|
||||
from m0lib import frames
|
||||
pr = _FakePriorities() if pr is None else pr
|
||||
captured = []
|
||||
@@ -1784,10 +1809,10 @@ def _run_frames_stage(tmp_path, monkeypatch, fake_server, admin=True, front=(GAM
|
||||
|
||||
def capture(exe, pid, seconds, out_csv, log):
|
||||
captured.append((pid, dict(pr.now)))
|
||||
return frames.parse_csv(_pm_csv([16.0] * 4000, pid=pid)), None
|
||||
return frames.parse_csv(_pm_csv([16.0] * 4000, pid=pid)), capture_err
|
||||
|
||||
monkeypatch.setattr(frames, "capture", capture)
|
||||
stt = _FakeStt()
|
||||
stt = _FakeStt() if stt is None else stt
|
||||
r, started, running = _run_levels_stage(tmp_path, monkeypatch, fake_server, _vram, only="frames",
|
||||
extra_opts=["stt_python=py"], stt=stt)
|
||||
return r, started, running, stt, pr, captured
|
||||
@@ -1830,10 +1855,33 @@ def test_frames_stage_needs_administrator_rights_and_the_game_in_front_before_st
|
||||
|
||||
|
||||
def test_a_yield_that_lowered_nothing_does_not_count_as_a_yielding_window(tmp_path, monkeypatch, fake_server):
|
||||
pr = _FakePriorities(ignored={20, 21, STT_LAUNCHER_PID, STT_LAUNCHER_PID + 1})
|
||||
# One of Jarvis's four processes keeps its priorities: that is not the yield being measured.
|
||||
pr = _FakePriorities(ignored={21})
|
||||
r, *_ = _run_frames_stage(tmp_path, monkeypatch, fake_server, pr=pr)
|
||||
assert r["comparison"]["busy_yield"]["windows"] == 0 and r["comparison"]["busy"]["windows"] == 2
|
||||
assert r["status"] == "partial" and any("lowered no priority" in e["error"] for e in r["errors"])
|
||||
assert r["status"] == "partial" and any("only 3 of 4" in e["error"] for e in r["errors"])
|
||||
|
||||
|
||||
def test_a_failed_capture_is_not_counted(tmp_path, monkeypatch, fake_server):
|
||||
r, *_ = _run_frames_stage(tmp_path, monkeypatch, fake_server, capture_err="PresentMon exited with timeout")
|
||||
assert not any(x["game"]["valid"] for x in r["frame_rows"])
|
||||
assert all(r["comparison"][k]["windows"] == 0 for k in ("off", "busy", "busy_yield"))
|
||||
|
||||
|
||||
def test_a_busy_window_where_jarvis_answered_nothing_is_not_counted(tmp_path, monkeypatch, fake_server):
|
||||
from m0lib import frames
|
||||
monkeypatch.setattr(frames.BusyLlm, "_loop", lambda self: None) # no answer ever finishes
|
||||
r, *_ = _run_frames_stage(tmp_path, monkeypatch, fake_server)
|
||||
assert r["comparison"]["off"]["windows"] == 2
|
||||
assert r["comparison"]["busy"]["windows"] == 0 and r["comparison"]["busy_yield"]["windows"] == 0
|
||||
assert r["status"] == "partial"
|
||||
|
||||
|
||||
def test_busy_windows_do_not_count_when_the_stt_load_failed(tmp_path, monkeypatch, fake_server):
|
||||
stt = _FakeStt(finish_result={"status": "timeout", "errors": ["stt worker did not stop within 300 s"]})
|
||||
r, *_ = _run_frames_stage(tmp_path, monkeypatch, fake_server, stt=stt)
|
||||
assert r["comparison"]["off"]["windows"] == 2
|
||||
assert r["comparison"]["busy"]["windows"] == 0 and r["comparison"]["busy_yield"]["windows"] == 0
|
||||
|
||||
|
||||
def test_frames_stage_is_on_demand_with_the_stt_python_and_an_elevating_one_click_runner():
|
||||
|
||||
Reference in New Issue
Block a user