trace-analysis — the "why is this slow?" investigation harness
Someone who has never opened a profiler types one line — *"why is my plugin
slow to open?"* — and gets a real, plain-English answer with a suggested fix.
This skill is the protocol that makes that happen: you load it, capture or
accept a .pftrace, and run a disciplined investigation over it, returning a
narrated root cause and a chain of evidence — never raw SQL. **You are reading
this because a tracing question fired (L1 explain) or an expert is driving an
iterative investigation (L2).**
This skill is provider-agnostic by construction: it is a plain SKILL.md read
identically by Claude Code and Codex from .agents/skills/. The whole
"why is this slow?" experience works under any agent because it is a shipped
skill + CLI/MCP surface, not a vendor API.
Its companion is trace-sql — the SQL discipline and the Pulp trace-stdlib of
named query primitives. This harness decides what to ask; trace-sql is
how to ask it. Load both for an L2 session.
Attribution. The investigation methodology below — the chain-of-evidence
scratchpad, the hypothesis→query→drill-down loop, the wall-time-vs-CPU-time
rule, follow-the-blocker, exhaustive global verification, and p95/p99
discipline — is **adapted from Google's
android/skills
perfetto-trace-analysis(Apache-2.0)**. The methodology is reused; the
Android domain content (SurfaceFlinger, binder, RenderThread, ftrace, cpu
governor) is not — the Pulp domain hints in
references/are authored fresh
against Pulp's own seams. See NOTICE.md.
Measurement mistakes that produce confident wrong answers
Read this before quoting any number. Every row happened on one live-editor
investigation (a spectrum analyzer with modulation, audio playing, pointer
drawing). None of them errored. Each produced a clean, plausible result that
was wrong — and several survived several rounds of "fixes" measured against
them. A run that fails any Detect check is discarded, not averaged in.
| Mistake | What it produced | How to detect it | Rule |
|---|---|---|---|
| Trace ring wrapped | A 512 MB ring over 60 s with audio (~715 MB written) silently dropped the main-thread sequence: 14 of 15 runs read as "no frames". | stats: traced_buf_incremental_sequences_dropped > 0 or any wrap; file size ≈ ring size; trace_processor prints "Trace health issues: Data losses". | Size PULP_TRACE_RING_KB so the whole run fits (1572864 = 1.5 GB for 60 s with audio). Run the health query on every capture, first. |
| No audio flowing | Silence / a test fixture left the analyzer path idle; the real cost (audio through the plugin) was invisible. | Data-delivery slice or counter near zero; meters flat in the screenshot. | Always drive PULP_TEST_SIGNAL=noise (or sine). Do not treat "no input" as "analyzer idle" either — silence still sends analyzer frames. |
| Wrong window driven | A global CGEvent mouse mover ran while the app was not frontmost and dragged the user's terminal instead. | Frontmost pid ≠ app pid at any point during the run. | Use in-window stimulus (PULP_TEST_POINTER_DRAG='rect:…'); gate every run on frontmost pid == app pid. |
| App never actually loaded | Launched from a sandboxed agent shell, the GUI app never attached to the window server (no window, not registered with LaunchServices) — yet the trace still had frame slices from a non-window source. | No window id; screenshot empty; paint/gpu_acquire counts ≪ frame count. | Per-run validity gates: frontmost pid, a window id plus a screenshot someone looks at, and a trace containing editor paint and data-delivery activity. |
| Screen locked | The display link stops: zero or near-zero editor frames, a well-formed "idle" trace. | Check lock state before and after each run. | Discard the run. |
| Degraded OS audio | CoreAudio held 4,096 com.apple.AirPlayXPCHelper plug-in objects; every audio app spent 19–75 s in device init, so runs started with no window. | Time a kAudioHardwarePropertyDevices query; count the system object's kAudioObjectPropertyOwnedObjects by class (thousands of one class). | A human restarts AirPlayXPCHelper then coreaudiod (-9), or reboots; let the load settle before measuring again. |
| Harness measures itself | Scenario/menu-step harness snapshots added 100–800 ms stalls that read as app jank. | Stalls line up with harness actions; any snapshot/eval the script runs lands in-app. | Nothing the measurement script does may run inside the app during the capture window. |
| Shared-host load | Load average 7 vs 30–130 moved frame times more than most fixes did. | Record load average at the start and end of every run. | Interleave old/new runs (A, B, A, B, …) in one session; never compare against a number from another session. |
| Automation instead of the gesture | Setting host params (param_set) to simulate zoom/shape changes exercised the host-automation projection path (22–127 ms per change), not the user's wheel/click path. | The slices in the window are host-sync/projection, not dom_event_*. | Measure both paths, labelled separately; the user's gesture is the one that decides feel. |
| Averages hide the feel | avg 16.7 ms with max 145 ms still felt sluggish. | — | Report p50/p95/max and counts over 50 / 100 ms per phase: mid-stroke, the 2 s after release, steady modulation, zoom. |
| Frame rate ≠ content smoothness | A steady 60 fps drew a spectrum that updated ~23 Hz (the analysis hop). | — | Measure content cadence separately: deliveries/s, max gap, gaps > 150 ms, resets. |
| Tracing build ≠ shipping build | Tracing wraps every JS→native call in a slice, inflating absolute costs. | — | Compare deltas between tracing builds; judge feel on a release build. |
| Tooling returned a silent wrong answer | /usr/bin/grep is ugrep (backreferences error out → every run marked INVALID); a zsh rm with a no-match glob aborted an && chain, so a batch "finished" instantly with RC=1; a pipeline's exit status is its last command's. | A batch that finishes too fast; every run failing the same way; a zero with no control. | Pair every negative finding with a positive control that must be non-zero on the same instrument (CLAUDE.md, "Pair every NEGATIVE finding…"). |
The copy-pasteable capture → validity → per-phase → worst-frame workflow that