Skip to content

Register diagnostics last so they do not change when the app's services are created - #616

Merged
stanoddly merged 3 commits into
mainfrom
diagnostics-registration-order
Oct 5, 2026
Merged

stanoddly merged 3 commits into
mainfrom
diagnostics-registration-order

Conversation

@botoddly

@botoddly botoddly commented Oct 5, 2026 •

Copy link
Copy Markdown
Collaborator

Follow-up to #613, from its second review.

Change

  • Creation order. Add PIXELY_DIAGNOSTICS to log frame timing, the GPU device and GPU memory #613 registered the diagnostics in the PixelyAppBuilder constructor, and the PerformanceReport factory resolved ILoggerFactory and GpuDevice before checking whether diagnostics were on. Singletons are created in the order their types were first registered, so the logger factory, SDL initialization and the GPU device were created ahead of every service the app registered, even with diagnostics off. An app registration that sets SDL state before the device exists would silently stop working.
    • Build() now registers FrameTimings, IFrameTimingRecorder and PerformanceReport last, with Func<ServiceProvider, T?> factories. The report resolves the logger factory and the GPU device only while diagnostics are on.
    • UseWindowRendering falls back to NullFrameTimingRecorder for a provider built without Build(), since the constructor no longer registers a recorder.
    • Because the report is now created last, the root provider disposes it before its own services. The final report on dispose therefore includes GPU memory again, which Add PIXELY_DIAGNOSTICS to log frame timing, the GPU device and GPU memory #613 left out; only stages, disposed before it, have released theirs.
  • Gen0 baseline. PerformanceReport takes it on its first update instead of at construction, so collections from building the app and loading content no longer count against the first period.
  • Container docs. docs/class-registration.md now states the singleton creation order this relies on: type by type, in the order each service type was first registered, with dependencies created first when needed.
  • Docs. docs/diagnostics.md and DECISIONS.md no longer say that nothing is registered or that the frame pays only null checks while diagnostics are off: the frame calls a recorder that does nothing, and no report is created.

Verification

  • New PixelyAppDiagnosticsTests, which clear the PIXELY_* variables for each test and restore them after:
    • With diagnostics off and on, an app service registered first is created before the logger factory and the GPU device. The device factory returns no device, so no GPU is needed, but it records when it runs. Both cases fail against main's builder.
    • Build() registers the null recorder and no report while diagnostics are off, and FrameTimings and one report while they are on (moved from PerformanceReportTests).
    • Two real RunFrame calls on a fake clock record the update between the frame start and the render, and disposing the app logs the final report. The test logger records only the report's category, so SDL's messages on quit cannot come after the report, and it throws if anything is logged after its factory is disposed.
  • InputAutomationConsoleTests: the console's reads are recorded as input wait, so they count toward neither the frame nor the update.
  • All test projects pass, and PixelyAppDiagnosticsTests also pass with PIXELY_DIAGNOSTICS=1 PIXELY_HEADLESS=1 set.
  • The Instancing tutorial reports as before, headless and windowed, and prints nothing with diagnostics off. Headless, the final report now shows the offscreen texture: GPU memory 1.83 MB, textures 1.83 MB.

…r factory and GPU device ahead of the app's services, and test the frame loop, console and dispose wiring
…GPU device position, fail on logging after the logger factory is disposed, and report GPU memory on dispose
@stanoddly
stanoddly force-pushed the diagnostics-registration-order branch from 6fd9b5b to 6ea9bc0 Compare October 5, 2026 13:33
@stanoddly
stanoddly enabled auto-merge (squash) October 5, 2026 13:34
@stanoddly
stanoddly merged commit 7149d0e into main Oct 5, 2026
2 checks passed
@stanoddly
stanoddly deleted the diagnostics-registration-order branch October 5, 2026 13:39
@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown

📦 Development package Pixely 0.0.113 is available.

Workflow run (attempt 1)

@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown

✅ Development package validation passed on all platforms.

Workflow run (attempt 1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants