Skip to content

feat(core): add --trace flag to dump Perfetto-compatible profile#1226

Merged
fi3ework merged 1 commit into
mainfrom
feat/phase-profiling
May 12, 2026
Merged

feat(core): add --trace flag to dump Perfetto-compatible profile#1226
fi3ework merged 1 commit into
mainfrom
feat/phase-profiling

Conversation

@fi3ework

@fi3ework fi3ework commented May 7, 2026

Copy link
Copy Markdown
Member

Summary

image image image

Adds a --trace CLI flag that dumps a Perfetto-compatible profile of a single rstest run.

Background

Issue #1195. The single Duration number bundles worker startup, asset transfer, env setup, test evaluation, execution, coverage, and teardown — "tests feel slow" reports are un-triageable from a paste.

Implementation

  • --trace CLI flag (CLI-only, not a config option). Writes Perfetto JSON to <rootPath>/.rstest/trace-<ts>.json:
    • 8 per-phase slices per file: prepare, envSetup, load, setupFiles, collect, tests, coverage, teardown
    • Per-suite and per-case slices, annotated with status + retryCount (via runner lifecycle hooks — zero intrusion into runner.ts)
    • Heap counter (heapUsedMB / heapTotalMB / rssMB) sampled at each phase boundary
  • Per-file labels. With isolate: true, the Perfetto row is labeled with the test file path directly; with isolate: false (shared worker), the row shows worker <pid> and each file shows up as a distinct thread track inside.
  • Helper server. TTY runs lazily start 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. Duration output is unchanged.

Related Links

Checklist

  • Tests pass; no test format change.
  • Docs: follow-up PR (Profiling guide + CLI flag table).

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented May 7, 2026

Copy link
Copy Markdown

Deploying rstest with  Cloudflare Pages  Cloudflare Pages

Latest commit: 261635c
Status: ✅  Deploy successful!
Preview URL: https://b9a9bd82.rstest.pages.dev
Branch Preview URL: https://feat-phase-profiling.rstest.pages.dev

View logs

@github-actions

github-actions Bot commented May 7, 2026

Copy link
Copy Markdown

Rsdoctor Bundle Diff Analysis

Found 12 projects in monorepo, 3 projects with changes.

📊 Quick Summary
Project Total Size Change
adapter-rsbuild 3.6 KB 0
adapter-rslib 24.6 KB 0
adapter-rspack 7.7 KB 0
browser 2.0 MB +1.2 KB (0.1%)
browser-react 3.7 KB 0
browser-ui 803.5 KB 0
coverage-istanbul 9.6 KB 0
core/browser 970.0 KB +21.0 B (0.0%)
core/loaders 869.0 B 0
core/main 1.6 MB +12.7 KB (0.8%)
vscode/extension 58.9 MB 0
vscode/worker 14.4 KB 0
📋 Detailed Reports (Click to expand)

📁 browser

Path: packages/browser/.rsdoctor/rsdoctor-data.json

📌 Baseline Commit: 906506a0d8 | PR: #1245

Metric Current Baseline Change
📊 Total Size 2.0 MB 2.0 MB +1.2 KB (0.1%)
📄 JavaScript 2.0 MB 2.0 MB +1.2 KB (0.1%)
🎨 CSS 11.8 KB 11.8 KB 0
🌐 HTML 765.0 B 765.0 B 0
📁 Other Assets 96.0 B 96.0 B 0

📦 Download Diff Report: browser Bundle Diff

📁 core/browser

Path: packages/core/.rsdoctor/browser/rsdoctor-data.json

📌 Baseline Commit: 906506a0d8 | PR: #1245

Metric Current Baseline Change
📊 Total Size 970.0 KB 970.0 KB +21.0 B (0.0%)
📄 JavaScript 961.9 KB 961.8 KB +21.0 B (0.0%)
🎨 CSS 0 B 0 B 0
🌐 HTML 0 B 0 B 0
📁 Other Assets 8.1 KB 8.1 KB 0

📦 Download Diff Report: core/browser Bundle Diff

📁 core/main

Path: packages/core/.rsdoctor/main/rsdoctor-data.json

📌 Baseline Commit: 906506a0d8 | PR: #1245

Metric Current Baseline Change
📊 Total Size 1.6 MB 1.6 MB +12.7 KB (0.8%)
📄 JavaScript 1.5 MB 1.5 MB +12.7 KB (0.8%)
🎨 CSS 0 B 0 B 0
🌐 HTML 0 B 0 B 0
📁 Other Assets 79.2 KB 79.2 KB 0

📦 Download Diff Report: core/main Bundle Diff

Generated by Rsdoctor GitHub Action

@fi3ework fi3ework changed the title feat(core): add phase-level profiling feat(core): add phase-level Duration breakdown May 8, 2026
@fi3ework fi3ework force-pushed the feat/phase-profiling branch 4 times, most recently from 61e6b96 to 74f8d27 Compare May 9, 2026 08:28
@fi3ework

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread packages/core/src/core/runTests.ts
Comment thread packages/core/src/utils/trace.ts Outdated
@fi3ework fi3ework marked this pull request as ready for review May 11, 2026 10:55
@fi3ework fi3ework force-pushed the feat/phase-profiling branch from 8d8fb1c to 8e28f71 Compare May 11, 2026 10:55
@fi3ework fi3ework requested a review from 9aoy May 11, 2026 11:38
@fi3ework fi3ework force-pushed the feat/phase-profiling branch from 8e28f71 to bceeeef Compare May 12, 2026 03:49
@fi3ework fi3ework changed the title feat(core): add phase-level Duration breakdown feat(core): add --trace flag to dump Perfetto-compatible profile May 12, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread packages/core/src/utils/trace.ts Outdated
@fi3ework fi3ework force-pushed the feat/phase-profiling branch from bceeeef to 08133d2 Compare May 12, 2026 06:09

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread packages/core/src/core/runTests.ts Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread packages/core/src/core/runTests.ts

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread packages/browser/src/hostController.ts
Comment thread packages/core/src/core/runTests.ts
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.
@fi3ework fi3ework force-pushed the feat/phase-profiling branch from 8361db6 to 88ce86c Compare May 12, 2026 11:01
@fi3ework fi3ework enabled auto-merge (squash) May 12, 2026 11:01

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread packages/browser/src/hostController.ts
@fi3ework fi3ework merged commit 471673b into main May 12, 2026
18 checks passed
@fi3ework fi3ework deleted the feat/phase-profiling branch May 12, 2026 12:11
@9aoy 9aoy mentioned this pull request May 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants