Skip to content

feat(mcp): add performance readout tools matching debug overlay (#468) - #711

Merged
houko merged 5 commits into
mainfrom
feat/mcp-perf-readouts-468
Nov 24, 2026
Merged

houko merged 5 commits into
mainfrom
feat/mcp-perf-readouts-468

Conversation

@houko

@houko houko commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Implements MCP performance readout tools for #468 (parent: #460), exposing live frame timings, update/draw costs, draw statistics, per-frame allocations, GC/heap telemetry, asset memory, and profiler zones matching game/debug's on-screen overlay.

Changes

  • packages/game/mcp/perf.go & packages/game/mcp/mcp.go:
    • Added optional Overlay, Profiler, GC, Memory, DrawStatsFunc, and RenderStatsFunc fields to mcp.Config and hooked b.perfTools() into Bridge.Tools().
    • Added game_perf_readout returning exact overlay-matched fps, rolling average and latest frame_ms/update_ms/draw_ms, min/max/p50/p95/p99 frame times, draw stats (draw_calls, sprites, batches, triangles, vertices), per-frame heap allocations (allocs_per_frame, alloc_bytes_per_frame, last_frame_allocs, last_frame_alloc_bytes), heap_bytes, gc_count, GC pause/hitch metrics, optional render3d (mcp.PerfRender3DStats, convertible from render3d.RenderStats) and asset_memory (debug.MemoryTracker) summaries, and optional chronological history / profiler zones.
    • Added game_perf_zones listing named debug.Profiler zones sorted by recent cost (last_ms, avg_ms, max_ms, calls).
    • Added game_perf_reset resetting accumulated overlay frame timings, pushed draw stats, profiler zones, and GC monitor history.
    • Strict DisallowUnknownFields() decoding on all tools and graceful handling when subsystems are unconfigured.
  • packages/game/debug:
    • Extended GCMonitor to sample /gc/heap/allocs:objects and /gc/heap/allocs:bytes with zero steady-state allocations (AllocsPerFrame(), AllocBytesPerFrame(), Reset()).
    • Added DrawStats, Options.DrawStats, Overlay.SetDrawStats, Overlay.DrawStats, Overlay.HasDrawStats, Overlay.ResetStats, and Profiler.Reset with matching -tags release stubs.
  • Tests, Docs, Changelog & Note:
    • Added packages/game/mcp/perf_test.go verifying exact parity against debug.Overlay (including rendered HUD text), render3d.RenderStats, standalone providers, reset behavior, and strict argument validation.
    • Updated docs/en/mcp.md and docs/zh/mcp.md, added changelog.d/mcp-perf-readouts-468.md, and added .agents/notes/implemented/feature/2026-11-24-mcp-performance-readouts.md.

Verification

  • git ls-files -z -- '*.go' | xargs -0 -r gofmt -l (empty)
  • go run ./cmd/gameschema -check
  • go tool nsgo check -target macos,windows,linux,android,web
  • go tool nsgo test ./mcp (12 passed)
  • go tool nsgo test ./debug (30 passed, including TestGCMonitorZeroAllocsSteadyState)
  • go build -tags release ./debug ./mcp
  • go tool nsgo test -run TestStabilityTable . (1 passed)
  • go run ./tools/changelog check
  • bun run verify-notes

Closes #468

Review follow-ups

  • Rebased onto main after the loop, input, console, edit and replay tool groups landed; perf tools come last in Tools(), the package doc and ExampleNew.
  • Profiler.Reset now only zeroes each scope's timings and history: scope IDs and any active trace recording survive game_perf_reset, so a scope open across the reset is charged to its own name.
  • Config.RenderStatsFunc returns mcp.PerfRender3DStats (same fields as render3d.RenderStats, converted with mcp.PerfRender3DStats(stats)), so game/mcp no longer imports game/render3d.
  • Documented draw stats, ResetStats, GCMonitor.Reset and per-frame allocation averages in debug.md and gc-and-allocations.md (en and zh).

@github-actions github-actions Bot added enhancement New feature or request size/XL documentation Improvements or additions to documentation pkg/debug area/agents conflict Conflicts with the target branch; resolve before merging labels Nov 24, 2026
Profiler.Reset cleared the scope index and stopped any active trace recording, so game_perf_reset silently discarded a Chrome trace started from the dev console, and a scope token spanning the reset was charged to whichever new scope reused its ID. Reset now only zeroes each scope's accumulators and history.
Config.RenderStatsFunc returned render3d.RenderStats, so game/mcp imported game/render3d and every 2D game attaching the bridge linked nsgo/gpu, scene3d, particles and ktx2. It now returns mcp.PerfRender3DStats, which has the same fields as render3d.RenderStats, so a game converts with mcp.PerfRender3DStats(stats).
@houko
houko force-pushed the feat/mcp-perf-readouts-468 branch from cc5bcf5 to c234fb7 Compare November 24, 2026 19:30
@houko
houko merged commit 81152af into main Nov 24, 2026
17 of 36 checks passed
@houko
houko deleted the feat/mcp-perf-readouts-468 branch November 24, 2026 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/agents conflict Conflicts with the target branch; resolve before merging documentation Improvements or additions to documentation enhancement New feature or request pkg/debug size/XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP: performance readouts

1 participant