Skip to content

Workbench Profiler: off-CPU sample classification (§8.7) + Time Area / Call Tree UX #364

Closed

Description

@nockawa

Tracking issue for the current Workbench Profiler branch. Bundles a set of
already-implemented Profiler UX fixes with the off-CPU sample-classification
feature still to be built.

Design doc: claude/design/Profiler/11-cpu-sampling-integration.md §8.7
("Sample classification — on-CPU / voluntary-wait / involuntary-stall"), in the
claude/ design repo. Continuation of the #351 CPU-sampling work.


Part A — Profiler UX (implemented on this branch)

  • Time Area context menu — right-click a span bar: View in Call Tree
    (merged), Zoom to span, Open emission site in editor, Copy span name/id.
    Right-click a chunk bar: View in Call Tree (system), Zoom to chunk, Show /
    Open system source, Copy system name. Browser context menu suppressed in
    the Time Area.
  • Call Tree row selection — single-click selects + syncs Source Preview
    when open; double-click opens the editor; click-to-open underline removed.
  • Call Tree context menu — Show inline, Open in editor, Focus tree on
    this frame, Expand/Collapse subtree, Copy method name / full signature.
  • "View in Call Tree (merged)" re-rooting — scope now re-roots the tree
    at the span/system method via resolveFrameRootForSite, fixing bogus
    ancestors and percentages. (§8.2 frame-root model.)
  • Source Preview wired to the command palette + View menu toggle.
  • Source Preview shows only the enclosing method block — Roslyn-based
    FindEnclosingMethodLines in ProfilerSourceController; brace-in-string /
    comment safe; falls back to a ±context window for non-C# / non-method lines.
  • DbMap context menu z-index — portaled to document.body.
  • Darker docked-view headers — dockview theme tokens, selected tab darker.

Touched files: panels/profiler/sections/TimeArea.tsx + TimeAreaContextMenu.tsx,
panels/profiler/CallTree.tsx + CallTreeContextMenu.tsx, ProfilerDetail.tsx,
libs/profiler/resolveFrameRoot.ts, stores/useCallTreeScopeStore.ts,
shell/commands/{openSchemaBrowser,baseCommands}.ts, shell/MenuBar.tsx,
panels/DbMap/DbMapContextMenu.tsx, globals.css,
Controllers/ProfilerSourceController.cs (+ Microsoft.CodeAnalysis.CSharp ref),
ProfilerSourceControllerTests.cs, plus vitest specs.

Part B — Off-CPU sample classification (to implement) — §8.7

Microsoft-DotNETCore-SampleProfiler samples every managed thread on a wall-clock
cadence — it is thread-time, not CPU-time. A thread parked at the GC barrier
(Thread.<PollGC>g__PollGCWorker) or blocked in Monitor.Wait is sampled, tagged
Managed, and currently folds into the call tree as if it were the enclosing
method's CPU cost. §8.7 replaces the SampleType proxy with a real classifier.

Every sample → exactly one of three classes (the view, not a name filter,
decides what shows):

Class Treatment
on-CPU per-method attribution
voluntary-wait (Monitor.Wait, WaitHandle, lock, Sleep, IO, await) per-method, wall-clock view only
involuntary-stall (GC suspension, OS preemption, paging) never per-method — collapsed into a labelled aggregate node ([GC suspension], [Preempted])

Classification = interval joins on data Typhon already captures (no BCL name-matching):

  1. qpc ∈ GC-suspension interval (GCSuspendEEBegin/GCRestartEEEnd, ComputeGcSuspensions) → involuntary (GC).
  2. else qpc ∈ off-CPU context-switch slice, by OffCpuCategory: Preempted/QuantumEnd→involuntary (scheduler), Paging→involuntary (paging), SyncWait/UserWait→voluntary-wait.
  3. else → on-CPU.

Implementation across the stack:

  • Engine capture — couple the Typhon:Profiler:Runtime:ThreadScheduling
    default to CpuSampling in TelemetryConfig / profiler startup (Windows +
    elevation only). No new capture — GC-suspension events and EtwSchedulingPump
    cswitch slices already exist.
  • Wire format — no change; classification is a post-hoc Workbench join.
  • Workbench server — per-sample classifier (linear merge / binary search
    of samples vs GC-suspension intervals + ThreadContextSwitch slices);
    CallTreeFolder applies the view-mode filter and folds involuntary samples
    into synthetic [GC suspension] / [Preempted] aggregate nodes; DTO carries
    the aggregates + a classificationAvailable flag.
  • Workbench client — dynamic mode-toggle label ("On-CPU" when
    classification data present, else "Thread time"); render the aggregate nodes
    as distinct collapsed entries; update useCallTree request/response types.
  • Graceful degradation — no ETW cswitch data (non-Windows / non-elevated /
    capture off): GC samples still classified involuntary; everything else falls
    back to the SampleType proxy; classificationAvailable = false; toggle
    reads "Thread time".

Acceptance criteria

  • A GC-park / Monitor.Wait sample no longer inflates the enclosing method's %.
  • On-CPU view excludes GC pauses and voluntary waits; wall-clock view includes
    voluntary waits with full stacks.
  • Involuntary stalls appear only as labelled aggregate nodes + an always-visible %.
  • Non-Windows trace: GC still hidden, view labelled "Thread time", no crash.
  • Zero engine hot-path cost — classification is a Workbench-side join only.

Activity

  1. moved this to In Progress in Typhon devon May 19, 2026
  2. nockawa commented on May 19, 2026

    @nockawa
    CollaboratorAuthor

    Implementation plan approved — starting #364 Part B (off-CPU sample classification, §8.7).

    Approach: a post-hoc Workbench-side classifier — zero engine hot-path cost, no trace wire-format change.

    1. Engine — couple the Typhon:Profiler:Runtime:ThreadScheduling default to CpuSampling (TelemetryConfig); explicit config still wins.
    2. Server classifier — new SampleClassifier (one chunk-walk, mirrors SpanInstanceIndex): decodes GC-suspension intervals (kind 75) + ThreadContextSwitch slices (kind 254), classifies each sample on-CPU / voluntary / involuntary(GC|scheduler|paging) by interval join.
    3. Server fold — CallTreeFolder routes per class & view mode: on-CPU view folds on-CPU only; wall-clock adds voluntary; involuntary → [GC suspension]/[Preempted]/[Paging] aggregate nodes. CallTreeResponseDto gains classificationAvailable.
    4. Client — dynamic toggle label ("On-CPU" vs "Thread time"); render aggregate nodes distinctly.

    Degraded mode (no context-switch data): GC still aggregated, rest falls back to the SampleType proxy, flag false.

    Note: §8.7 says all classifier inputs are "already in the session" — verified that the kind-254 records sit in the trace chunk stream but were never decoded server-side; the plan adds that one decode pass. Design intent unchanged.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions