feat(core): add --trace flag to dump Perfetto-compatible profile#1226
Conversation
Deploying rstest with
|
| Latest commit: |
261635c
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://b9a9bd82.rstest.pages.dev |
| Branch Preview URL: | https://feat-phase-profiling.rstest.pages.dev |
Rsdoctor Bundle Diff AnalysisFound 12 projects in monorepo, 3 projects with changes. 📊 Quick Summary
📋 Detailed Reports (Click to expand)📁 browserPath:
📦 Download Diff Report: browser Bundle Diff 📁 core/browserPath:
📦 Download Diff Report: core/browser Bundle Diff 📁 core/mainPath:
📦 Download Diff Report: core/main Bundle Diff Generated by Rsdoctor GitHub Action |
61e6b96 to
74f8d27
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c998179da6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
8d8fb1c to
8e28f71
Compare
8e28f71 to
bceeeef
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bceeeef19d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
bceeeef to
08133d2
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 08133d2200
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fe2a847b7d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 64482c2285
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Add a `--trace` CLI flag that records per-phase, per-suite, and per-case timing spans plus heap counters for each test file and writes them to a Perfetto-compatible JSON file. On interactive TTYs the dump is served over a localhost HTTP server so users can click a one-shot link that auto-loads the trace in https://ui.perfetto.dev. Implementation: * `runtime/worker/phaseTracker.ts` records phase spans, suite/case slices, and `process.memoryUsage()` counter samples per file. Each tracker gets its own `tid` so files share one `pid` cleanly under `isolate: false`. * `utils/trace.ts` exposes `createTraceController`, which buffers events per run (`beginRun`), writes the trace JSON on `finalize`, manages the optional Perfetto helper HTTP server, and provides `shutdown` / `waitForExit` / `close` lifecycle hooks. * `core/runTests.ts` wires the controller across node and browser modes. Pre-allocates the per-run buffer so events emitted before the first `run()` call — or in mixed runs where `run()` is never invoked because all node tests are filtered out — are not dropped through the `activeTraceRun?.` optional chain. Watch cleanup paths (`SIGINT`/restart/CLI close) flush the active buffer before closing the controller so events accumulated between reruns make it to disk. * Browser mode: `@rstest/browser` host instantiates one `PhaseTracker` per test file and forwards events through `BrowserTestRunOptions.onTraceEvents`. Each file is assigned a synthetic per-file `pid` (base `1_000_000_000`) so Perfetto labels every track with the file path instead of collapsing every file under the shared host process. User impact: opt-in profiling via `rstest run --trace`. Without the flag, behavior is unchanged; `beginRun()` returns a no-op handle so the hot path is free of branching overhead.
8361db6 to
88ce86c
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 88ce86ccb5
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Summary
Adds a
--traceCLI flag that dumps a Perfetto-compatible profile of a single rstest run.Background
Issue #1195. The single
Durationnumber bundles worker startup, asset transfer, env setup, test evaluation, execution, coverage, and teardown — "tests feel slow" reports are un-triageable from a paste.Implementation
--traceCLI flag (CLI-only, not a config option). Writes Perfetto JSON to<rootPath>/.rstest/trace-<ts>.json:prepare,envSetup,load,setupFiles,collect,tests,coverage,teardownstatus+retryCount(via runner lifecycle hooks — zero intrusion intorunner.ts)heapUsedMB/heapTotalMB/rssMB) sampled at each phase boundaryisolate: true, the Perfetto row is labeled with the test file path directly; withisolate: false(shared worker), the row showsworker <pid>and each file shows up as a distinct thread track inside.127.0.0.1:9001(the only port Perfetto UI's CSP allows) so the printed link auto-loads; non-TTY (CI) runs write the file and exit cleanly.User Impact
Opt-in only; no behavior change without
--trace.Durationoutput is unchanged.Related Links
Checklist