Skip to content

Workbench profiler — unify live and replay pipelines at the cache layer (#289) - #290

Merged
nockawa merged 2 commits into
mainfrom
feature/289-unify-profiler
Apr 28, 2026
Merged

nockawa merged 2 commits into
mainfrom
feature/289-unify-profiler

Conversation

@nockawa

@nockawa nockawa commented Apr 28, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #289.

Summary

Refactored TraceFileCacheBuilder into an incremental instance-based class driven from both file (replay) and TCP-stream (live) sources. After this PR the live (Attach) and replay (Trace) profiler pipelines share one server-side cache representation and one client-side rendering path. Mode-specific code is confined to the source side of the builder.

What's in this PR

Engine + Profiler library

  • TraceFileCacheBuilder static one-shot scanner → IncrementalCacheBuilder instance class, exposing FeedRawRecords / FlushCurrentChunk / Dispose and TickFinalized / ChunkFlushed events.
  • New ICacheChunkSink abstraction with FileCacheSink (replay) + AppendOnlyChunkSink (live) implementations.
  • ThreadKind byte added to ThreadInfo records (Main / Worker / Pool / Other) — drives the filter tree's Threads subgrouping.
  • Cache format: additive CacheHeaderFlags.IsSelfContained (bit 0) + CacheSectionId.SourceMetadata section (no version bump, fully backwards-compatible).

Workbench backend

  • AttachSessionRuntime rewritten — Init parses metadata, Block decompresses + feeds builder, Shutdown flushes + disposes. Drops LiveTickBatch / EmitTickBatch / pendingTicksRef / per-batch ring buffer.
  • New SSE delta protocol: tickSummaryAdded, chunkAdded, globalMetricsUpdated, threadInfoAdded, heartbeat, shutdown. Reconnect = full metadata snapshot replay.
  • LiveCacheTempFile owns %TEMP%/typhon-workbench/{sessionId}.cache; orphan sweep at runtime startup.
  • IChunkProvider shared by TraceSessionRuntime and AttachSessionRuntime; controller becomes one-liner.
  • New Save Live Session as .typhon-replay flow: POST /api/sessions/{id}/profiler/save-replay snapshots a live attach session into a self-contained replay file (no companion .typhon-trace needed). Bidirectional open path accepts both extensions.

Workbench frontend

  • useProfilerCache collapses to one branch — no more liveAssembled, recentTicks ring, liveTickCacheRef. chunkCache.ts / OPFS untouched.
  • TickOverview rewrite — tick-indexed wheel (plain = move ±1 tick, Shift = resize right edge, Ctrl = pan 25%), float-drift boundary clamp on tickRows.endUs, scrollbar + drag-to-pan.
  • TimeArea ruler — # prefix on tick labels, over-P95 accent color on labels + dashed boundaries, +1px font.
  • applyLiveBatch store action + rAF-coalesced SSE buffering in useProfilerLiveStream — collapses N×O(N) array spreads/frame to 1×O(N+batch)/frame; eliminates live-ingest stutter.
  • New SaveReplayDialog + File menu entry + palette command.
  • Section-filter popup (filter tree with Gauges / Threads / Systems / Engine Operations groups).
  • Top Spans panel.
  • Range stats detail in DetailPanel.

Tests

  • 6 buildTickRows clamp regression tests.
  • 7 applyLiveBatch semantics tests (multi-event batching, mid-batch metadata reset, last-wins metrics, shutdown).
  • 2 .typhon-replay round-trip tests (AttachSessionRuntimeSaveReplayTests).
  • 2 cache format tests (IsSelfContained / source-derived).
  • Filter-tree tests + selectionStats tests.

Bugs fixed: live p95 always 0, "all bars over P95", per-batch ring buffer stranding long captures, missing scrollbar, ThreadInfo replay on reconnect.

Net code: ~−250 LOC client-side aggregation deleted, ~−150 LOC AttachSessionRuntime tick-batching deleted, ~+200 LOC builder refactor + new features. Plus the new Save-as-replay feature on top.

Design doc

claude/design/observability/08-profiler-live-replay-unification.md

Test plan

  • dotnet test — engine profiler tests (374 passing)
  • dotnet test — workbench session tests (35 passing)
  • npx vitest run — client tests (246 passing)
  • npx tsc --noEmit — clean
  • Full solution build clean
  • Manual: /wb-dev start → AntHill --live 9100 → workbench attach → smooth live ingest, scrollbar + wheel work, p95 has a real value
  • Manual: live attach → File → Save Session as .typhon-replay… → reopen the saved file with no companion trace

nockawa added 2 commits April 27, 2026 18:22
- Added feature to the engine for chunk level processing
- AntHill: get the "latest" code from another repo
- Profiler: debugged live connect mode
- Workbench: live connect mode on par with replay, few UI improvements
@nockawa
nockawa merged commit 2aa0bcc into main Apr 28, 2026
6 checks passed
@nockawa
nockawa deleted the feature/289-unify-profiler branch April 28, 2026 21:26
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.

Workbench profiler — unify live and replay pipelines at the cache layer

1 participant