Skip to content

test: the v1 router's CPU profile, under samply through a nextest wrapper script (test-suites PR 5) - #272

Merged
aRustyDev merged 3 commits into
mainfrom
test/profiling-cpu
Nov 17, 2026
Merged

aRustyDev merged 3 commits into
mainfrom
test/profiling-cpu

Conversation

@aRustyDev

Copy link
Copy Markdown
Owner

PR 5 of the test-suites plan (.agents/plans/test-suites/), the last: the v1 router's CPU profile, recorded by samply through a nextest wrapper script. samply was installed with the owner's OK (cargo install samply, 0.13.1).

What

  • crates/testing/profiling/tests/cpu.rs. prof_cpu_router runs the profiled mix 20 times on fresh worlds: 6,400 requests, about 2 s in the release build. It uses the system allocator, because under dhat a CPU profile would mostly show dhat's own work.
  • scripts/samply-wrapper.sh. nextest runs it as <wrapper> <test binary> <arguments>.
    • It runs samply record --save-only --no-open --unstable-presymbolicate on the test.
    • It writes target/profiling/<test>.json.gz plus a symbols sidecar, so samply load <file> opens the flame graph without the build.
  • .config/nextest.toml:
    • experimental = ["wrapper-scripts"];
    • [scripts.wrapper.samply], relative to the workspace root;
    • [[profile.prof.scripts]], which applies the wrapper to test(/^prof_cpu_/). The heap tests run unwrapped, as before.
  • .github/scripts/tests/test-samply-wrapper.sh, run by ci-scripts. It tests the wrapper with a fake samply that behaves as measured and a fake test binary, so CI needs no samply. The plan-ci planner (plan-ci.py) gets a rule so a change to the wrapper runs ci-scripts; before, an unknown script ran everything.
  • Docs:
    • AGENTS.md's commands table gains the profiles' command.
    • The crate's description, crates/testing/README.md and performance.md describe the CPU profile.
    • The plan records PR 4 as merged and what this PR found (below).

Run it with:

cargo nextest run -p thrust-profiling --profile prof --cargo-profile release -E 'test(/^prof_cpu_/)'

Three ways the profile could pass without profiling, measured and closed

  1. samply exits 0 when the profiled process is killed by a signal. It passes on a normal exit status (0 and 3 came through). But a binary that aborts, which exits 134 when run directly, made samply exit 0. Under a plain wrapper, an aborting prof_cpu_ test passed in nextest. So the wrapper counts a 0 only when libtest also printed its pass line for exactly one test.
  2. A test selected without the wrapper, under another profile, would pass and write no profile. The wrapper exports THRUST_PROF_SAMPLY, and the test refuses to run without it.
  3. The experimental feature changing. I measured what nextest 0.9.140 does with a misspelled feature (exit 96, "unknown experimental features") and with the wrapper config but no feature (exit 95, "experimental features used but not enabled"). Both refuse the config, so neither runs the test without samply.

Evidence

Every check below has a control that makes it fail (AGENTS.md rule 8). The control rows were run against the real samply on macOS.

Check Result Control
--profile prof --cargo-profile release, CPU test passes in 2.2 s; profile 26 KB, symbols 40 KB
the profile names the workload the symbols name thrust_api_v1, thrust_adapters_memory, thrust_core and thrust_profiling an unrelated binary's profile names none of them
a prof_cpu_ test that must fail fails, exit 100: the wrapper ran the binary and passed its status on
a prof_cpu_ test that aborts fails, exit 100, through the guard ("samply exited 0, but the test printed no pass line")
the same abort, with the guard removed passes: the hazard is real under nextest
the CPU test without the wrapper (default profile, --ignore-default-filter) fails, exit 100, with the message naming the wrapper
test-samply-wrapper.sh 149 checks pass. They cover every ending (pass, fail, no test, killed), samply installed or not, a profile written or not, and three test names eight broken copies of the wrapper each fail it: no guard, any pass count, status dropped, no profile check, no marker, no name sanitising, arguments dropped, no samply check
--profile prof (dev build) the 3 prof_ tests pass; the heap tests run unwrapped
default profile the 2 workload tests pass, the 3 prof_ tests skipped
cargo nextest run --profile ci --workspace --locked, after merging today's main 4,641 passed
cargo mutants -p thrust-profiling 20 of 20 caught (src/ changed only in its doc comment)
plan-ci.py with only the wrapper changed ci-scripts test_plan_ci.py failed until the new rule had its sample (6,993 checks now)
mutate_gate.py 136 of 136 mutants killed
every command of the deps and ci-scripts jobs, shell scripts under dash, after merging today's main 59 of 59: 21 deps commands from lint.yml, 38 ci-scripts commands from ci.yml, the same total as before #269 #269 moved deps into lint.yml, where my local runner, which read ci.yml only, would have skipped it and still reported green. It now reads each job from whichever workflow holds it, and refuses if a job is missing
clippy, fmt, check-layout.sh exit 0

samply on Linux needs /proc/sys/kernel/perf_event_paranoid at 1 or lower; I measured only on macOS. No CI job runs the prof profile; the CI-split plan's phase 13 (Prof) owns that.

.config/ changed, so CI runs everything.

🤖 Generated with Claude Code

aRustyDev and others added 3 commits November 17, 2026 01:23
…pper script

PR 5 of the test-suites plan, the last.

- crates/testing/profiling/tests/cpu.rs: prof_cpu_router runs the
  profiled mix 20 times on fresh worlds (6,400 requests, about 2 s in
  the release build), with the system allocator. It refuses to run
  without THRUST_PROF_SAMPLY, which only the wrapper sets, so a
  prof_cpu_ test selected under another profile fails instead of
  passing with no profile.
- scripts/samply-wrapper.sh: nextest runs it as <wrapper> <test binary>
  <arguments>. It runs `samply record --save-only --no-open
  --unstable-presymbolicate` and writes target/profiling/<test>.json.gz,
  with a symbols sidecar so `samply load` opens it without the build.
  samply 0.13.1 exits with the test's status, but with 0 when the test
  is killed by a signal (measured): under a plain wrapper an aborting
  test PASSED. So a 0 counts only with libtest's pass line for one test.
- .config/nextest.toml: `experimental = ["wrapper-scripts"]`,
  [scripts.wrapper.samply] (relative to the workspace root), and
  [[profile.prof.scripts]] for `test(/^prof_cpu_/)`. If the feature is
  renamed or dropped, nextest refuses the config (exit 96 for an
  unknown feature, 95 for a wrapper script without it; measured on
  0.9.140), so no test runs unprofiled.
- .github/scripts/tests/test-samply-wrapper.sh, run by ci-scripts: the
  wrapper against a fake samply that behaves as measured and a fake test
  binary, over every ending (pass, fail, no test, killed), samply
  installed or not, a profile written or not, and three test names
  (149 checks). Eight broken copies of the wrapper each fail it.
- plan-ci.py: a change to the wrapper runs ci-scripts, not everything.

Controls, against the real samply: a failing prof_cpu_ test fails (exit
100); an aborting one fails through the guard, and passes with the
guard removed; the test refuses without the wrapper; the profile's
symbols name thrust_api_v1, thrust_core, thrust_adapters_memory and
thrust_profiling, and an unrelated binary's name none of them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
AGENTS.md's commands table gains the profiles' command. The crate's
description and module doc, crates/testing/README.md and
docs/src/testing/techniques/performance.md describe the CPU profile and
the wrapper. The plan: PR 4 merged in #267, PR 5 in review, and what PR
5 found (samply's exit status on a signal, the refusal without the
wrapper, how nextest reacts if the experimental feature changes).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@aRustyDev
aRustyDev merged commit e5ea637 into main Nov 17, 2026
43 checks passed
@aRustyDev
aRustyDev deleted the test/profiling-cpu branch November 17, 2026 06:50
aRustyDev added a commit that referenced this pull request Nov 17, 2026
PR 5 merged in #272, so all five pull requests are merged. The status
table says so, gives the plan's own merge (#234), and points at what the
plan left for later.

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

1 participant