Conversation
f9ee312 to
bddfb42
Compare
|
Mathlib CI status (docs):
|
|
Reference manual CI status:
|
859a35a to
8510264
Compare
This PR documents the new `lake profile` command, which builds an executable target, records a CPU profile with samply, symbolicates and demangles Lean compiler names, and serves the result for Firefox Profiler. Depends on leanprover/lean4#12545 — do not merge until that PR lands. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Mathlib CI status (docs):
|
This PR adds a `lake profile` command that builds an executable target, records a CPU profile with samply, symbolicates addresses via samply's API, demangles Lean compiler names using `Lean.Name.Demangle.demangleSymbol`, and writes a Firefox Profiler JSON file. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This PR addresses several issues identified during code review: - add try/finally for temp directory cleanup and process lifecycle management - add shellQuote for safe shell argument interpolation - add percentEncode for Firefox Profiler URL construction (can't use escapeUri because it doesn't encode `/`) - check exit codes for cp, mv, gzip, and curl - detect early samply exit in waitForServer via tryWait - rewrite extractToken using modern String APIs (find?, sliceFrom, dropPrefix?, takeWhile) with structural URL prefix matching - remove redundant import of Lean.Compiler.NameDemangling from src/Lean.lean - fix help text: remove broken -o alias, stale PROFILER_README.md reference - use curl -sS for better error diagnostics - fix percentEncode correctness on non-ASCII input (byte-range checks) - reap child processes after kill to avoid zombies Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…shell script This PR updates PROFILER_README.md to reference `lake profile` as the primary profiling workflow, removes references to deleted Python scripts, and deletes `script/lean_profile.sh` which depended on those scripts. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This PR moves the demangling documentation (modifier flags, specializations, annotations) from the standalone PROFILER_README.md into the module docstring of Lean.Compiler.NameDemangling, where it belongs. The standalone README is deleted since `lake help profile` covers usage and the demangling reference is now with the source. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add a `--no-serve` flag so the full pipeline (record, symbolicate, demangle) can complete without blocking on the HTTP server. The test builds a minimal executable, runs `lake profile --raw` and `lake profile --no-serve`, and validates the output is well-formed Firefox Profiler JSON. The test gracefully skips when samply is not installed or when perf_event_open is unavailable, so it is currently a no-op in CI. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
On macOS, Apple's `zcat` expects `.Z` files and appends `.Z` to the path, so `zcat profile.json.gz` fails. `gzip -dc` works on both macOS and Linux, and is consistent with the existing `requireCmd "gzip"` check. Also include stderr in the error message for easier debugging. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
|
||
| ## Standalone CLI tool | ||
|
|
||
| `script/profiler/lean_demangle_cli.lean` is a `c++filt`-like filter: |
There was a problem hiding this comment.
You also delete this file in the PR though?
| ./clean.sh | ||
|
|
||
| # Skip if samply is not installed | ||
| if ! command -v samply &>/dev/null; then |
There was a problem hiding this comment.
This test would never be executed in our current CI environment. I guess we should modify the CI setup to also install samply?
tydeu
left a comment
There was a problem hiding this comment.
The Lake integration looks good to me. Adding this does imply a commitment by us to maintain it in the future, but I presume that has already been agreed on.
| | "--output" => do | ||
| let p ← takeOptArg "--output" "output path" | ||
| modifyThe LakeOptions ({· with profileOutput? := some p}) |
There was a problem hiding this comment.
Perhaps -o should also set this option?
| let _ ← Profile.run exeFile.toString opts.subArgs.toArray opts.profileOutput? opts.profileRate | ||
| (raw := opts.profileRaw) (serve := !opts.profileNoServe) | ||
| exit 0 |
There was a problem hiding this comment.
| let _ ← Profile.run exeFile.toString opts.subArgs.toArray opts.profileOutput? opts.profileRate | |
| (raw := opts.profileRaw) (serve := !opts.profileNoServe) | |
| exit 0 | |
| discard <| Profile.run exeFile.toString opts.subArgs.toArray opts.profileOutput? opts.profileRate | |
| (raw := opts.profileRaw) (serve := !opts.profileNoServe) |
The exit should be unnecessary.
| @@ -0,0 +1,6 @@ | |||
| name = "test" | |||
| version = "0.1.0" | |||
There was a problem hiding this comment.
| version = "0.1.0" |
A version is unnecessary in tests (that do not test versions).
This PR adds a
lake profilecommand that records a CPU profile of a Lean executable usingsamply, symbolicates addresses, demangles Lean compiler
names, and serves the result to Firefox Profiler.
This replaces the Python scripts in
script/profiler/with a single Lake command.Walkthrough
From the lean4 repo:
Open the Firefox Profiler URL in your browser. Function names like
List.MergeSort.Internal.mergeSortTR₂appear instead of their mangled forms.Options:
--rate N— sampling rate in Hz (default 1000)--output FILE— save to a specific path--raw— skip symbolication and demangling--no-serve— write output file and exit without starting the HTTP serverTest
There's an end-to-end test in
tests/lake/tests/profile/that builds a minimal executable,runs
lake profile --rawandlake profile --no-serve, and validates the output iswell-formed Firefox Profiler JSON. The test gracefully skips when samply isn't installed
or when
perf_event_openisn't available.The test is currently a no-op in CI since samply isn't in the Nix devshell. I'd appreciate
advice on the best way to make it available — adding it to
flake.nixbuildInputsseemedheavy (it pulls in the Rust toolchain), but I'm not sure what the preferred approach is.
🤖 Prepared with Claude Code