summaryrefslogtreecommitdiff
path: root/src/LivingVillage.Desktop/Game.fs
diff options
context:
space:
mode:
authorSomhairle H. Marisol <[email protected]>2026-09-29 09:42:17 +0800
committerSomhairle H. Marisol <[email protected]>2026-09-29 09:42:17 +0800
commitf01aa1a9a8d19db5ab908ddbb30b0467be8aa092 (patch)
tree2385fd0b75b3b35f5a29ac9b5c02d9b9e5aea13b /src/LivingVillage.Desktop/Game.fs
parent54732d906a68d89ee1446ddb82ae639a016925be (diff)
downloadliving-village-f01aa1a9a8d19db5ab908ddbb30b0467be8aa092.tar.gz
p70: 启动帧率与渲染基准(真实可复跑数据)
- scripts/bench-p70.sh:两档基准——Kernel --performance-baseline(6000 tick ×3) + Desktop xvfb 60s 真实帧循环;scripts/analyze-p70.py 汇总裁决 - Game.fs:LV_FRAME_LOG=1 逐帧日志(墙钟帧间隔 + GC 线程分配增量 + tick/panel), 仅新增日志,不改渲染/更新逻辑 - P70PerformanceBaselineTests:Pin --performance-baseline final_digest=953775FA…(防漂移) - 实测:Kernel tps mean=466679 alloc=3032184 gen0/1/2=0/0/0 determinism=PASS; Desktop 60s frames=8788 fps=139.3 mean=7.179ms max=33.919ms 掉帧>33.3ms=2 每帧分配 mean=231KB p95=297KB;dotnet-counters 缺席已如实标注 - Desktop 338/338、Kernel 120/120;Kernel/Sim/渲染口径/字形表未动
Diffstat (limited to 'src/LivingVillage.Desktop/Game.fs')
-rw-r--r--src/LivingVillage.Desktop/Game.fs22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/LivingVillage.Desktop/Game.fs b/src/LivingVillage.Desktop/Game.fs
index 63f69cd..ff1dfe0 100644
--- a/src/LivingVillage.Desktop/Game.fs
+++ b/src/LivingVillage.Desktop/Game.fs
@@ -248,6 +248,14 @@ type LivingVillageGame() as this =
| _ -> 0.0
let perfSoakWatch = System.Diagnostics.Stopwatch()
let mutable perfSoakStarted = false
+ // P70 基准:LV_FRAME_LOG=1 时逐帧打印真实帧间隔(墙钟 ms,含 Update+Draw)与线程分配增量,
+ // 供 scripts/bench-p70.sh + analyze-p70.py 计算平均/最大帧间隔、掉帧与每帧分配。
+ // 仅新增日志,不改变渲染/更新逻辑;配合 LV_PERF_SOAK_SECONDS + LV_AUTOPLAY_SAMPLE 循环 N 秒。
+ let frameLogEnabled = Environment.GetEnvironmentVariable("LV_FRAME_LOG") = "1"
+ let frameLogWatch = System.Diagnostics.Stopwatch()
+ let mutable frameLogIndex = 0L
+ let mutable frameLogAllocStart = 0L
+ let mutable frameLogLastTick = 0L
let mutable prevKb = Unchecked.defaultof<KeyboardState>
let mutable relationView = false
let mutable relationSnapshot: float32[,] option = None
@@ -2240,6 +2248,20 @@ type LivingVillageGame() as this =
(Occupation.saveToken kind) stage world.Tick world.Annals.Length
override this.Update(gameTime: GameTime) =
+ if frameLogEnabled && not splashActive then
+ let allocatedNow = System.GC.GetAllocatedBytesForCurrentThread()
+ if frameLogIndex = 0L then
+ frameLogWatch.Start()
+ frameLogAllocStart <- allocatedNow
+ else
+ let frameMs = frameLogWatch.Elapsed.TotalMilliseconds
+ let allocKb = float (allocatedNow - frameLogAllocStart) / 1024.0
+ printfn
+ "p70-frame index=%d ms=%.3f alloc_kb=%.1f tick=%d panel=%s"
+ frameLogIndex frameMs allocKb world.Tick (M5Interaction.panelName m5View)
+ frameLogWatch.Restart()
+ frameLogAllocStart <- allocatedNow
+ frameLogIndex <- frameLogIndex + 1L
let kb = Keyboard.GetState()
let pressed (key: Keys) = kb.IsKeyDown(key) && not (prevKb.IsKeyDown(key))
let pressedAny (keys: Keys list) = keys |> List.exists pressed