lean4 icon indicating copy to clipboard operation
lean4 copied to clipboard

feat: add `lake samply` command

Open kim-em opened this issue 9 months ago • 4 comments

This PR adds a lake samply command that records a CPU profile of a Lean executable using samply, 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.

  • [X] Depends on https://github.com/leanprover/lean4/pull/12539.

From the lean4 repo:

$ cd tests/bench/mergeSort
$ lake samply mergeSort -- -- 10
Building mergeSort
Recording profile...
Starting symbolication server...
Symbolicating and demangling...
Demangled 335 names, wrote profile-demangled.json.gz

Serving on http://127.0.0.1:3757/

Open in Firefox Profiler:
  https://profiler.firefox.com/from-url/http%3A%2F%2F127.0.0.1%3A3757%2F...%2Fprofile.json

Press Ctrl+C to stop.

Open the Firefox Profiler URL in your browser. Function names like List.MergeSort.Internal.mergeSortTR₂ appear instead of their mangled forms.

Lake-level options:

  • -o FILE — output path (default ./profile-demangled.json.gz)
  • --raw — skip symbolication and demangling
  • --no-serve — write output file and exit without starting the HTTP server

Anything after -- is forwarded verbatim to samply record; an inner -- separates samply's own flags from the profiled executable's arguments:

lake samply mergeSort                          # no samply or exe args
lake samply mergeSort -- --rate 2000           # only samply args
lake samply mergeSort -- -- 10                 # only exe args
lake samply mergeSort -- --rate 2000 -- 10     # both

There's an end-to-end test in tests/lake/tests/samply/ that builds a minimal executable, runs lake samply --raw and lake samply --no-serve, and validates the output is well-formed Firefox Profiler JSON. The test gracefully skips when samply isn't installed or when perf_event_open isn't available.

🤖 Prepared with Claude Code

kim-em avatar Feb 18 '26 04:02 kim-em

Mathlib CI status (docs):

  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase e9cc84b7c99f64220c952dee026ac0f06a031fc4 --onto 91bd6e19a7b7aca769f9720e1127c768df0cd2a7. You can force Mathlib CI using the force-mathlib-ci label. (2026-02-18 06:15:49)
  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase c948d24b6ddbb41c199c13edc9ebc04104a667bb --onto 333ab1c6f0ce11f33551d6a736054cb72812cad9. You can force Mathlib CI using the force-mathlib-ci label. (2026-03-07 01:05:08)
  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase c948d24b6ddbb41c199c13edc9ebc04104a667bb --onto 4786e082dca22873d14d2a5b9b7c8843380c6e78. You can force Mathlib CI using the force-mathlib-ci label. (2026-03-30 07:28:34)
  • ❗ Mathlib CI can not be attempted yet, as the nightly-testing-2026-04-11 tag does not exist there yet. We will retry when you push more commits. If you rebase your branch onto nightly-with-mathlib, Mathlib CI should run now. You can force Mathlib CI using the force-mathlib-ci label. (2026-04-12 02:23:02)
  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase a416b90d22990f84607168ac6c520b52c843a25d --onto 5d5642107d0433519265f155ddbfbfb98007a80b. You can force Mathlib CI using the force-mathlib-ci label. (2026-05-08 06:16:40)
  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 819f4549d9bda7c34f1ae185a3353d7dfd1f19a6 --onto 5d5642107d0433519265f155ddbfbfb98007a80b. You can force Mathlib CI using the force-mathlib-ci label. (2026-05-09 12:30:17)
  • ✅ Mathlib branch lean-pr-testing-12545 has successfully built against this PR. (2026-05-13 02:46:43) View Log
  • ✅ Mathlib branch lean-pr-testing-12545 has successfully built against this PR. (2026-05-22 10:27:06) View Log
  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 5f9b66958dbcad3d3464e223e2c227d0a8e627b6 --onto d2f48db30713019241520218d0965227bbb64eed. You can force Mathlib CI using the force-mathlib-ci label. (2026-06-10 13:58:03)
  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 5f9b66958dbcad3d3464e223e2c227d0a8e627b6 --onto 58225845d6ead86550a9371cfdcb3d9f0be3fc55. You can force Mathlib CI using the force-mathlib-ci label. (2026-06-19 00:16:31)

Reference manual CI status:

  • ❗ Reference manual CI will not be attempted unless your PR branches off the nightly-with-manual branch. Try git rebase e9cc84b7c99f64220c952dee026ac0f06a031fc4 --onto 5c7a508e21c5ebc710b0dfe65648d5beba4e34e0. You can force reference manual CI using the force-manual-ci label. (2026-02-18 06:15:50)
  • ❗ Reference manual CI will not be attempted unless your PR branches off the nightly-with-manual branch. Try git rebase c948d24b6ddbb41c199c13edc9ebc04104a667bb --onto a165292462a973c20d3cc8c8b23a3ac2334a2a4a. You can force reference manual CI using the force-manual-ci label. (2026-03-07 01:05:10)
  • ❗ Reference manual CI will not be attempted unless your PR branches off the nightly-with-manual branch. Try git rebase c948d24b6ddbb41c199c13edc9ebc04104a667bb --onto cfa8c5a036d6990635c6ec50b02d0e806995cec3. You can force reference manual CI using the force-manual-ci label. (2026-03-30 07:28:36)
  • ❗ Reference manual CI can not be attempted yet, as the nightly-testing-2026-03-25 tag does not exist there yet. We will retry when you push more commits. If you rebase your branch onto nightly-with-manual, reference manual CI should run now. You can force reference manual CI using the force-manual-ci label. (2026-03-30 11:59:39)
  • ❗ Reference manual CI can not be attempted yet, as the nightly-testing-2026-04-11 tag does not exist there yet. We will retry when you push more commits. If you rebase your branch onto nightly-with-manual, reference manual CI should run now. You can force reference manual CI using the force-manual-ci label. (2026-04-12 02:23:04)
  • ❗ Reference manual CI will not be attempted unless your PR branches off the nightly-with-manual branch. Try git rebase a416b90d22990f84607168ac6c520b52c843a25d --onto 5d5642107d0433519265f155ddbfbfb98007a80b. You can force reference manual CI using the force-manual-ci label. (2026-05-08 06:16:42)
  • ❗ Reference manual CI will not be attempted unless your PR branches off the nightly-with-manual branch. Try git rebase 819f4549d9bda7c34f1ae185a3353d7dfd1f19a6 --onto 41ecccec6d1244c5f89be2fc76638f22ba37cbc6. You can force reference manual CI using the force-manual-ci label. (2026-05-09 12:30:18)
  • 🟡 Reference manual branch lean-pr-testing-12545 build against this PR didn't complete normally. (2026-05-13 01:54:56) View Log
  • 💥 Reference manual branch lean-pr-testing-12545 build failed against this PR. (2026-05-13 01:55:20) View Log
  • 💥 Reference manual branch lean-pr-testing-12545 build failed against this PR. (2026-05-22 09:36:32) View Log
  • 🟡 Reference manual branch lean-pr-testing-12545 build against this PR didn't complete normally. (2026-05-22 09:36:47) View Log
  • ❗ Reference manual CI will not be attempted unless your PR branches off the nightly-with-manual branch. Try git rebase 5f9b66958dbcad3d3464e223e2c227d0a8e627b6 --onto 803553a556fd82fa1060efb0c43eda542130cb16. You can force reference manual CI using the force-manual-ci label. (2026-06-10 13:58:05)

leanprover-bot avatar Feb 18 '26 06:02 leanprover-bot

Mathlib CI status (docs):

@kim-em That's a lot of code, what do you want me to review? I'm okay with the interface

Kha avatar Jun 11 '26 13:06 Kha