diff options
Diffstat (limited to 'src/LivingVillage.Desktop/Game.fs')
| -rw-r--r-- | src/LivingVillage.Desktop/Game.fs | 22 |
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 |
