Repository navigation
Description
Summary
ProfilerSetup.BuildSessionMetadata (demo/AntHill/AntHill.Core/Engine/ProfilerSetup.cs) is host-side glue that assembles a ProfilerSessionMetadata from already-engine-side helpers. Every host reimplements the same orchestration.
Analysis (2026-05-17) confirmed: everything that glue assembles is derivable from the TyphonRuntime — systems, worker count, tick rate, phase/track hierarchy, the static-structure tables, the resource graph, and the two RuntimeConfigRecord values currently stubbed to 0. The only genuinely host-supplied input is ProfilerOptions (consumer/exporter tuning — unrelated to engine state).
Make session-metadata composition implicit. Host profiler startup collapses to: AttachExporter(...) then TyphonProfiler.Start(runtime, options?).
What is derivable (must stop being a parameter)
Old BuildSessionMetadata input |
Derived from |
|---|---|
systems |
runtime.Systems |
workerCount (AntHill hardcodes 16) |
runtime.Options.WorkerCount / scheduler |
baseTickRate (AntHill hardcodes 60f) |
runtime.Options.BaseTickRate |
TelemetryRingCapacity (stubbed 0) |
runtime.Options.TelemetryRingCapacity |
ParallelQueryMinChunkSize (stubbed 0) |
runtime.Options.ParallelQueryMinChunkSize |
engine |
runtime.Engine |
resourceGraphRoot |
runtime.Engine — the engine is the graph root (DatabaseEngine : IResource) |
parent (profiler resource node) |
resolved from the resource registry |
currentEngineTickProvider |
dead — accepted then discarded (_ = ...); delete |
| timestamps | captured internally at Start |
Corrections to the original issue
"Add— not needed.RuntimeOptions.TickRateHz"RuntimeOptions.BaseTickRatealready exists (int, default 60). Just read it.- The original proposed signature
Start(parent, runtime, engine, resourceGraphRoot, options)over-specifies:parent,engine, andresourceGraphRootare all reachable fromruntime.
Changes
Engine side (src/Typhon.Engine/)
- New internal runtime-driven
ProfilerSessionMetadatabuilder — movesProfilerSetup.BuildSessionMetadata's body into the engine. Reads systems / phases / tracks / worker count / tick rate / ring capacity / chunk size fromruntime+runtime.Options; static-structure tables and resource graph fromruntime.Engine; timestamps captured internally. - Resolve the profiler
parentnode from the resource registry. If neitherTyphonRuntimenorDatabaseEnginecurrently exposesIResourceRegistry, add a minimal accessor. - New public overload:
public static void Start(TyphonRuntime runtime, ProfilerOptions options = null);
- Remove the existing
Start(IResource parent, ProfilerSessionMetadata metadata, ProfilerOptions options)overload. No backward compat.
Host side (demo/AntHill/)
- Delete
demo/AntHill/AntHill.Core/Engine/ProfilerSetup.csentirely. AntHill.Demo/Scripts/Main.csandAntHill.Harness/Program.cs: replace theBuildSessionMetadata+Startblock with the single-call form.
Open question — CPU-sampling QPC anchor
samplingSessionStartQpc is currently host-orchestrated: ProfilerLauncher.StartCpuSampler runs before metadata is built so the QPC anchor lands in the trace header. The implicit Start(runtime, options) signature has nowhere for it. Decide before implementing:
- (a)
Startowns CPU-sampler startup (gated onProfilerLaunchConfig/ProfilerOptions), or - (b) keep an explicit
long samplingSessionStartQpc = 0parameter.
Do not drop it silently.
Acceptance
- Internal runtime-driven
ProfilerSessionMetadatabuilder implemented. -
Start(TyphonRuntime, ProfilerOptions)overload added; oldStart(parent, metadata, options)overload removed. -
WorkerCount,BaseTickRate,TelemetryRingCapacity,ParallelQueryMinChunkSizeall derived fromruntime.Options— no hardcoded16/60f, no0stubs inRuntimeConfigRecord. -
ProfilerSetup.csdeleted;Main.cs+Program.csmigrated. - CPU-sampling QPC anchor handled (open-question decision implemented).
- Test in
ProfilerLaunchConfigTests(or sibling) exercises the implicit path against a realTyphonRuntime. - Full test suite green.
Why
- Boilerplate removal — future hosts get profiler integration in one call.
- Eliminates a divergence-bug class — hardcoded
workerCount/tickRatecan disagree with the runtime's actual values; deriving fromruntime.Optionsmakes that impossible. - Fills the two
RuntimeConfigRecordfields (TelemetryRingCapacity,ParallelQueryMinChunkSize) currently rendered as "—" in the Workbench trace-session schema panels.
Related
- Analysis conversation (2026-05-17) — confirmed all metadata except
ProfilerOptionsis derivable fromTyphonRuntime(runtime.Systems,runtime.Engine,runtime.Options.{WorkerCount,BaseTickRate,TelemetryRingCapacity,ParallelQueryMinChunkSize},runtime.PhaseNames). - Profiler architecture:
claude/design/Profiler/typhon-profiler.md
Estimate
S–M (~3–4 h — straightforward once the CPU-sampling open question is decided).
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
[-]Make ProfilerSetup.BuildSessionMetadata implicit (engine-derived session metadata)[/-][+]Make profiler session metadata implicit — TyphonProfiler.Start(runtime)[/+]nockawa commentedon May 18, 2026
Completed in
384b85c("Solved #332") onfeature/small-evols-fixes.Implemented — exceeds the original "one call" target with zero host code:
ProfilerSessionMetadataBuilder(engine-internal) — replacesProfilerSetup.BuildSessionMetadata, derives everything fromTyphonRuntime.RuntimeConfigRecordfully populated fromruntime.Options(no16/60f/0stubs).ProfilerBootstrap— self-wires the profiler atTyphonRuntime.Createfrom config; a[ModuleInitializer]bakes the JIT gate. Hosts need zero profiler code.TelemetryConfigresolves the launch config fromtyphon.telemetry.json+TYPHON__PROFILER__*env vars; CLI args injected explicitly by the host via theAddTyphonProfilerDI hook.ProfilerSetup.csdeleted;Main.cs+Program.csmigrated to plainbridge.Initialize(...).ProfilerSessionMetadataBuilderTests, rewrittenProfilerLaunchConfigTests. Full suite green (3733 passed).Deviations from the issue spec (approved during implementation):
Start(TyphonRuntime, ProfilerOptions)overload — superseded byProfilerBootstrapself-wiring, which is strictly better (zero host code, not one call).Start(parent, metadata, options)madeinternal, not removed —Typhon.IOProfileRunnerand the exporter integration tests build synthetic metadata with noTyphonRuntime; they need the low-level entry point (already covered byInternalsVisibleTo).ProfilerBootstrapowns the whole start sequence internally, soStartCpuSampler-before-metadata ordering is enforced in one place; no parameter needed.Teardown note: the trace is finalized via
ManagedPagedMMF.DisposingEvent(the storage is disposed after the engine, deterministically on every host incl. Godot) — so engine-shutdown events land in the trace and the file is always properly closed.Follow-up (minor, not blocking): code-review findings still open —
ProfilerBootstrap.csnamespace casedTyphon.Engine.internalsvs the conventionInternals; deadTelemetryConfig.Configurationfield; orphanedProfilerLauncher.EnableTelemetryGateIfActive/PrintDiagnostics.Config-driven profiler startup (#332) + Workbench evolutions (#359)