Skip to content

Make profiler session metadata implicit — TyphonProfiler.Start(runtime) #332

Closed

Description

@nockawa

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 RuntimeOptions.TickRateHz" — not needed. RuntimeOptions.BaseTickRate already exists (int, default 60). Just read it.
  • The original proposed signature Start(parent, runtime, engine, resourceGraphRoot, options) over-specifies: parent, engine, and resourceGraphRoot are all reachable from runtime.

Changes

Engine side (src/Typhon.Engine/)

  • New internal runtime-driven ProfilerSessionMetadata builder — moves ProfilerSetup.BuildSessionMetadata's body into the engine. Reads systems / phases / tracks / worker count / tick rate / ring capacity / chunk size from runtime + runtime.Options; static-structure tables and resource graph from runtime.Engine; timestamps captured internally.
  • Resolve the profiler parent node from the resource registry. If neither TyphonRuntime nor DatabaseEngine currently exposes IResourceRegistry, 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.cs entirely.
  • AntHill.Demo/Scripts/Main.cs and AntHill.Harness/Program.cs: replace the BuildSessionMetadata + Start block 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) Start owns CPU-sampler startup (gated on ProfilerLaunchConfig / ProfilerOptions), or
  • (b) keep an explicit long samplingSessionStartQpc = 0 parameter.

Do not drop it silently.

Acceptance

  • Internal runtime-driven ProfilerSessionMetadata builder implemented.
  • Start(TyphonRuntime, ProfilerOptions) overload added; old Start(parent, metadata, options) overload removed.
  • WorkerCount, BaseTickRate, TelemetryRingCapacity, ParallelQueryMinChunkSize all derived from runtime.Options — no hardcoded 16/60f, no 0 stubs in RuntimeConfigRecord.
  • ProfilerSetup.cs deleted; Main.cs + Program.cs migrated.
  • CPU-sampling QPC anchor handled (open-question decision implemented).
  • Test in ProfilerLaunchConfigTests (or sibling) exercises the implicit path against a real TyphonRuntime.
  • Full test suite green.

Why

  • Boilerplate removal — future hosts get profiler integration in one call.
  • Eliminates a divergence-bug class — hardcoded workerCount / tickRate can disagree with the runtime's actual values; deriving from runtime.Options makes that impossible.
  • Fills the two RuntimeConfigRecord fields (TelemetryRingCapacity, ParallelQueryMinChunkSize) currently rendered as "—" in the Workbench trace-session schema panels.

Related

  • Analysis conversation (2026-05-17) — confirmed all metadata except ProfilerOptions is derivable from TyphonRuntime (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).

Activity

  1. self-assigned this
    on May 11, 2026
  2. added
    refactoring
    on May 11, 2026
  3. moved this to Ready in Typhon devon May 11, 2026
  4. changed the title [-]Make ProfilerSetup.BuildSessionMetadata implicit (engine-derived session metadata)[/-] [+]Make profiler session metadata implicit — TyphonProfiler.Start(runtime)[/+] on May 17, 2026
  5. moved this from Ready to In Progress in Typhon devon May 18, 2026
  6. nockawa commented on May 18, 2026

    @nockawa
    CollaboratorAuthor

    Completed in 384b85c ("Solved #332") on feature/small-evols-fixes.

    Implemented — exceeds the original "one call" target with zero host code:

    • ProfilerSessionMetadataBuilder (engine-internal) — replaces ProfilerSetup.BuildSessionMetadata, derives everything from TyphonRuntime. RuntimeConfigRecord fully populated from runtime.Options (no 16/60f/0 stubs).
    • ProfilerBootstrap — self-wires the profiler at TyphonRuntime.Create from config; a [ModuleInitializer] bakes the JIT gate. Hosts need zero profiler code.
    • Config-driven: TelemetryConfig resolves the launch config from typhon.telemetry.json + TYPHON__PROFILER__* env vars; CLI args injected explicitly by the host via the AddTyphonProfiler DI hook.
    • ProfilerSetup.cs deleted; Main.cs + Program.cs migrated to plain bridge.Initialize(...).
    • New tests: ProfilerSessionMetadataBuilderTests, rewritten ProfilerLaunchConfigTests. Full suite green (3733 passed).

    Deviations from the issue spec (approved during implementation):

    • No public Start(TyphonRuntime, ProfilerOptions) overload — superseded by ProfilerBootstrap self-wiring, which is strictly better (zero host code, not one call).
    • Start(parent, metadata, options) made internal, not removed — Typhon.IOProfileRunner and the exporter integration tests build synthetic metadata with no TyphonRuntime; they need the low-level entry point (already covered by InternalsVisibleTo).
    • CPU-sampling QPC — open question dissolved: ProfilerBootstrap owns the whole start sequence internally, so StartCpuSampler-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.cs namespace cased Typhon.Engine.internals vs the convention Internals; dead TelemetryConfig.Configuration field; orphaned ProfilerLauncher.EnableTelemetryGateIfActive/PrintDiagnostics.

  7. moved this from In Progress to Done in Typhon devon May 18, 2026
  8. added a commit that references this issue on May 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

refactoring

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions