Skip to content

Runtime profiler: trace format, file/live inspectors, viewer UI - #238

Merged
nockawa merged 1 commit into
mainfrom
feature-profiler
Apr 12, 2026
Merged

nockawa merged 1 commit into
mainfrom
feature-profiler

Conversation

@nockawa

@nockawa nockawa commented Apr 12, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds a complete runtime profiling system for the Typhon engine: trace format, capture inspectors (file + live TCP stream), profiler server, and a browser-based viewer UI.

Engine-side capture

  • TraceEventCaptureBase — abstract per-thread SPSC ring buffer pipeline (~20-30 ns/event hot path, zero contention between worker threads)
  • TraceFileInspector — writes to .typhon-trace binary files with LZ4 block compression and delta-encoded timestamps
  • TcpStreamInspector — streams the same block format over TCP with non-blocking sends (Socket.Blocking = false + SocketError.WouldBlock handling), so the timer thread never blocks on I/O. Drops frames under backpressure rather than stalling the engine
  • DagScheduler instrumented at 23 points guarded by a JIT-eliminated TelemetryConfig.SchedulerDeepTrace static readonly flag
  • OTel ActivityListener integration captures spans from the Typhon.Engine ActivitySource with interned name IDs

Wire format

  • Binary .typhon-trace files: header + system definition table + span name table + LZ4-compressed event blocks
  • Live streaming uses a framed TCP protocol (INIT / TICK_EVENTS / SPAN_NAMES / SHUTDOWN) where the TICK_EVENTS payload is byte-identical to the file's block format — TraceBlockEncoder is the shared encode/decode path, so file writer and TCP inspector can never drift
  • Span name table offset is tracked at build time (not scanned for magic bytes) so a system named SpawnManager won't collide with the SPAN marker

Profiler server (ASP.NET Core)

  • LiveSessionService — BackgroundService that connects to the engine's TCP port, decompresses frames, and fans out to SSE subscribers via bounded Channel<T> (DropOldest backpressure)
  • REST endpoints for uploading/inspecting .typhon-trace files and building flame graphs from companion .nettrace files
  • SSE endpoint /api/live/events streams tick batches with 5s heartbeats
  • Malformed frames log and are dropped rather than poisoning the reconnect loop

Viewer (Preact + TypeScript + Vite)

  • Single-project layout: client source in ClientApp/, built output in wwwroot/, MSBuild targets run npm install + vite build on dotnet build
  • Canvas-based track layout (Perfetto-style): time ruler, per-worker chunks, phases, OTel spans
  • Tick timeline bar chart with P95 scaling and live follow-mode sliding window
  • Incremental processTickAndAppend for live mode with 100ms state-update batching (~10 Hz React rerender at 60 Hz engine tick rate)
  • Detail pane for selected chunks; dropped/evicted chunks auto-clear

Tests

  • New TraceBlockEncoderTests round-trip contract test: writes events through TraceFileWriter, reads back through TraceFileReader, verifies all fields preserved (6 tests)
  • Full suite: 3,216 tests passing (no regressions from pre-profiler baseline)

Test plan

  • dotnet build Typhon.slnx — clean build
  • dotnet test test/Typhon.Engine.Tests — all 3,216 tests pass
  • npx tsc --noEmit in tools/Typhon.Profiler.Server/ClientApp — zero TypeScript errors
  • npm run build in ClientApp — vite production build succeeds
  • Manually wire TcpStreamInspector into a test harness (e.g. AntHill) and verify end-to-end live streaming in the browser (follow-up — demo harness changes not in this PR)

🤖 Generated with Claude Code

@nockawa
nockawa merged commit 10ac0ae into main Apr 12, 2026
5 checks passed
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.

1 participant