fix(m0): keep the game in front for the whole frames window and record the game_frames results

On the game PC the game went behind another window right after Jarvis
started and stayed there for three windows, drawing at its background rate
(about 58 fps). The kit only checked the window in front at the end of a
window, so the window in which the user clicked back into the game counted
and showed yielding as a 47 % drop in 1 % low.

- FrontWatch checks every second from the start of a window to its end and
  spoils the window if the game was behind anything at any check.
- Before a window the kit asks the user, with a beep, to go back to the
  game and waits up to two minutes.
- What was in front is kept only as a category (a Jarvis process, a console
  window, Explorer, another app), never an app name.

Results: with the game in front, a busy Jarvis cost 0.2 % of the average
fps and 3.3 % of the 1 % low with no frames over 50 ms, so by the
pre-registered rule nothing is added and yielding is not adopted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
javis-bot
2026-11-11 09:35:38 +09:00
parent cec52165b2
commit 8f2470af2a
6 changed files with 202 additions and 18 deletions

View File

@@ -78,6 +78,6 @@ LLM 단계는 8080 포트를 씁니다. 다른 프로그램이 이 포트를 쓰
`run_m0_video.bat`을 더블클릭하면 Jarvis 옆에서 보는 영상이 끊기는지 잽니다(`video_drops`). 크롬(없으면 엣지)이 새 임시 프로필로 떠서 유튜브의 Blender 영상(Big Buck Bunny, 1080p 60fps, 소리 끔)을 틉니다. 광고가 나오면 건너뛸 수 있을 때 건너뛰고 끝날 때까지 기다립니다. 영상을 틀어 둔 채로 (1) Jarvis를 끈 상태 1분, (2) LLM(평소 배치, STT 자리와 여유 1GB)과 STT를 켜 두고 쉬는 상태 1분, (3) LLM이 답하고 STT가 10명 동시 전사를 쉬지 않고 하는 상태를 GPU 95% 제한 없이 두 번, 제한을 켜고 두 번, (4) 다시 Jarvis를 끈 상태 1분을 잽니다. 각각 끊긴 프레임 수(유튜브 "전문가용 통계"의 Dropped Frames와 같은 값)와, 화면에 프레임이 50ms·100ms 넘게 안 바뀐 횟수를 셉니다. 10~15분 걸립니다. 그동안 브라우저 창을 가리거나 최소화하지 말고 PC에 손대지 않으시면 됩니다. 광고, 일시정지, 버퍼링, 건너뛰기가 끼었거나 화질이 1080p 60fps가 아니었던 구간, 제한을 켰는데 Jarvis를 실제로 멈추지 못한 구간은 기록만 하고 비교에서는 뺍니다. 영상이 멈추거나 유튜브 오류가 뜨거나 페이지가 새로고침되면 키트가 알아서 다시 틀고(재생을 누르고, 안 되면 페이지를 다시 엽니다) 그 구간을 최대 3번까지 다시 잽니다. 직접 새로고침하지 않으셔도 됩니다. 화질이나 프레임 수가 떨어진 구간은 GPU 탓일 수 있어서 다시 재지 않습니다.
`run_m0_game_frames.bat`을 더블클릭하면 Jarvis가 게임 화면을 끊기게 하는지 잽니다(`game_frames`). 게임 프레임은 Windows 이벤트 기록으로 재므로 처음에 관리자 권한을 묻는 창이 한 번 뜹니다. 게임을 켜기 전에 "예"를 눌러 주세요. 그다음 게임을 켜고 플레이 화면까지 들어간 뒤 Enter를 누르고 15초 안에 게임으로 돌아가면 됩니다. 끝날 때까지 캐릭터를 한자리에 세워 두고 마우스·키보드에 손대지 마세요. 창마다 1분씩 (1) 게임만, (2) Jarvis(게임 중 배치)를 켜 두고 쉴 때, (3) LLM이 답하고 음성 인식이 최종 전사를 하는 동안을 그냥 두 번, Jarvis의 CPU·GPU 우선순위를 낮춰 게임에 양보하게 하고 두 번, (4) 다시 게임만 잽니다. 10~15분 걸리고 끝나면 알림음이 울립니다. fps와 긴 프레임은 화면이 실제로 바뀐 간격으로 셉니다. 게임이 앞에 없었던 구간, 프레임 기록이 실패한 구간, Jarvis를 끄거나 쉬게 둔 동안 게임이 프레임을 거의 내지 않은 구간, LLM이나 음성 인식 부하가 제대로 돌지 않은 바쁨 구간, Jarvis 프로세스 하나라도 우선순위가 낮아지지 않은 양보 구간은 기록만 하고 비교에서 뺍니다. 프레임 제한(수직 동기화나 fps 제한)은 평소 쓰시는 대로 두셔도 됩니다.
`run_m0_game_frames.bat`을 더블클릭하면 Jarvis가 게임 화면을 끊기게 하는지 잽니다(`game_frames`). 게임 프레임은 Windows 이벤트 기록으로 재므로 처음에 관리자 권한을 묻는 창이 한 번 뜹니다. 게임을 켜기 전에 "예"를 눌러 주세요. 그다음 게임을 켜고 플레이 화면까지 들어간 뒤 Enter를 누르고 15초 안에 게임으로 돌아가면 됩니다. 끝날 때까지 캐릭터를 한자리에 세워 두고 마우스·키보드에 손대지 마세요. 창마다 1분씩 (1) 게임만, (2) Jarvis(게임 중 배치)를 켜 두고 쉴 때, (3) LLM이 답하고 음성 인식이 최종 전사를 하는 동안을 그냥 두 번, Jarvis의 CPU·GPU 우선순위를 낮춰 게임에 양보하게 하고 두 번, (4) 다시 게임만 잽니다. 10~15분 걸리고 끝나면 알림음이 울립니다. fps와 긴 프레임은 화면이 실제로 바뀐 간격으로 셉니다. 측정 중에 게임 화면이 뒤로 가면(예: 다른 창이 앞으로 옴) 알림음과 함께 게임으로 돌아가 달라고 안내하고, 돌아오실 때까지 최대 2분 기다렸다가 잽니다. 잠깐이라도 게임이 앞에 없었던 구간, 프레임 기록이 실패한 구간, Jarvis를 끄거나 쉬게 둔 동안 게임이 프레임을 거의 내지 않은 구간, LLM이나 음성 인식 부하가 제대로 돌지 않은 바쁨 구간, Jarvis 프로세스 하나라도 우선순위가 낮아지지 않은 양보 구간은 기록만 하고 비교에서 뺍니다. 프레임 제한(수직 동기화나 fps 제한)은 평소 쓰시는 대로 두셔도 됩니다.
다 끝나고 필요 없으면 작업 폴더(`\JarvisM0`)를 통째로 지우면 됩니다. Python, 모델, Strata(엔진과 설정 포함)는 모두 그 안에 설치하도록 지정해 두었습니다.

View File

@@ -46,6 +46,12 @@ ROUNDS = ("busy", "busy_yield", "busy_yield_2", "busy_2")
# The foreground window belongs to one of these when the user did not get back to the game.
NOT_A_GAME = {"windowsterminal.exe", "openconsole.exe", "conhost.exe", "cmd.exe", "powershell.exe",
"pwsh.exe", "explorer.exe"}
# A game behind another window draws at its background rate, so the game must stay in front for the
# whole window, not only at its end (2026-11-11: the game went behind a window right after Jarvis
# started, and a window the user clicked back into midway still counted).
FRONT_EVERY_S = 1.0 # how often the window in front is checked
FRONT_WAIT_S = 120 # how long the kit waits for the user to get back to the game before a window
BACK_SETTLE_S = 3 # the game settles this long after it is back in front
# Windows' values: process priority classes and D3DKMT_SCHEDULINGPRIORITYCLASS.
CPU_NORMAL, CPU_BELOW_NORMAL = 0x20, 0x4000
GPU_NORMAL, GPU_BELOW_NORMAL = 2, 1
@@ -98,6 +104,92 @@ def foreground_process() -> tuple[int, str] | None:
return pid.value, name
def front_label(fg: tuple[int, str], jarvis: set[int]) -> str:
"""What was in front instead of the game, in words that name no app the user has open."""
pid, exe = fg
if pid in jarvis:
return "a Jarvis process"
if exe == "explorer.exe":
return "Explorer (desktop or taskbar)"
if exe in NOT_A_GAME:
return "a console window"
return "another app"
class FrontWatch:
"""Checks every FRONT_EVERY_S, from the start of a window to its end, that the game is in front.
A moment with no window in front at all (Windows switching) is not counted either way."""
def __init__(self, game: int, jarvis_pids):
self.game = game
self.jarvis_pids = jarvis_pids
self._jarvis: set[int] | None = None
self.samples = 0
self.away = 0
self.to: set[str] = set()
self._stop = threading.Event()
self._thread = threading.Thread(target=self._loop, daemon=True)
def check(self) -> None:
fg = foreground_process()
if fg is None:
return
self.samples += 1
if fg[0] != self.game:
self.away += 1
if self._jarvis is None:
self._jarvis = set(self.jarvis_pids())
self.to.add(front_label(fg, self._jarvis))
def _loop(self) -> None:
while not self._stop.wait(FRONT_EVERY_S):
self.check()
def __enter__(self) -> "FrontWatch":
self.check()
self._thread.start()
return self
def __exit__(self, *exc) -> None:
self._stop.set()
self._thread.join()
self.check()
def summary(self) -> dict:
return {"checks": self.samples, "away": self.away, "to": sorted(self.to)}
def _beep() -> None:
try:
import winsound
winsound.MessageBeep()
except Exception:
pass
def wait_for_game(game: int, jarvis_pids) -> dict | None:
"""None when the game is in front. Otherwise asks the user to go back to it and waits up to
FRONT_WAIT_S; says what was in front, how long it waited and whether the game came back."""
fg = foreground_process()
if fg is None or fg[0] == game:
return None
to = front_label(fg, set(jarvis_pids()))
say(" 게임 화면이 앞에 없습니다. 게임 화면을 한 번 눌러 돌아가 주세요. 돌아오시면 이어서 잽니다.")
_beep()
t0 = time.monotonic()
back = False
while time.monotonic() - t0 < FRONT_WAIT_S:
time.sleep(FRONT_EVERY_S)
fg = foreground_process()
if fg is not None and fg[0] == game:
back = True
break
waited = round(time.monotonic() - t0, 1)
if back:
time.sleep(BACK_SETTLE_S)
return {"to": to, "waited_s": waited, "back": back}
_API: dict = {}
@@ -405,19 +497,29 @@ def measure(r: StageResult, s: "llm.Strata", preset: dict, context: int, stt_pyt
r.note("measured while the user's game was running (its name is not kept)")
base = f"http://127.0.0.1:{llm.PORT}/v1"
def jarvis_pids() -> list[int]:
return llm.cap_pids(s, stt)
def window(key: str, kind: str) -> dict:
x: dict = {"key": key, "kind": kind}
lost = wait_for_game(game, jarvis_pids)
if lost:
x["front_lost_before"] = lost
r.note(f"{key}: the game was not in front before the window ({lost['to']}), "
f"{'back after' if lost['back'] else 'not back after'} {lost['waited_s']} s")
used = gpu_memory_mib()
if used:
x["vram_free_mib"] = used[1] - used[0]
with gpucap.UtilSampler() as util:
with gpucap.UtilSampler() as util, FrontWatch(game, jarvis_pids) as front:
frames, err = capture(pm, game, WINDOW_S, work / "cache" / "frames.csv", pm_log)
g = frame_stats(frames, WINDOW_S, MIN_FRAMES if kind in ("off", "idle") else 0)
g["gpu_util"] = util.summary()
now = foreground_process()
if now is not None and now[0] != game:
away = front.summary()
if away["away"]:
g["away_from_front"] = away
g["valid"] = False
g["invalid_because"] = g.get("invalid_because", []) + ["the game was not in front at the end"]
g["invalid_because"] = g.get("invalid_because", []) + [
f"the game was not in front for {away['away']} of {away['checks']} checks"]
if err:
# Frames from a capture that failed or was cut off do not cover the window.
r.error(f"frames {key}", err)
@@ -507,8 +609,4 @@ def measure(r: StageResult, s: "llm.Strata", preset: dict, context: int, stt_pyt
stt.close()
s.stop()
say("\a 게임 프레임 측정이 끝났습니다. 게임을 꺼도 됩니다.")
try:
import winsound
winsound.MessageBeep()
except Exception:
pass
_beep()