-
Notifications
You must be signed in to change notification settings - Fork 1
feat: recursion profiling + measurement programs #726
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Oppen
wants to merge
16
commits into
pr/recursion-guest
Choose a base branch
from
pr/profiling
base: pr/recursion-guest
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
ae9e200
feat: recursion profiling + measurement programs
Oppen 1d47067
refactor(prover): drop per-address PC table from recursion profile
Oppen a395f27
refactor(prover): share setup/progress across recursion diagnostics
Oppen 66f2443
cargo fmt
Oppen acd6783
refactor(prover): unify recursion execute-only diagnostics
Oppen 1b143b3
build: enable the deserialize-only recursion guest
Oppen 35f4741
build: point profile-recursion make targets at renamed tests
Oppen 89d46dc
docs: trim recursion smoke-test doc comments
Oppen 53145fc
refactor(prover): drop test_host_verify_step_timings
Oppen da41a23
Remove the unused SP1 verifier bench program
Oppen acd2c67
fix ci bug
Oppen e52cd9d
fix ci bug
Oppen b70789a
cargo fmt
Oppen 162e281
Merge branch 'pr/profiling' of github.com:yetanotherco/lambda_vm into…
Oppen 8cb31e5
ci: gate recursion-profile comment job on profile not being skipped
Oppen cd0d615
lint
Oppen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| #!/usr/bin/env python3 | ||
| """Format the recursion-guest per-function profile as a Markdown PR comment. | ||
| `test_recursion_pc_histogram` prints a per-function summary table: the cycles | ||
| folded over each function's PCs, computed across the *full* histogram — the view | ||
| that shows where the cycles actually go. We parse that table and render it as | ||
| Markdown. | ||
| Top 25 functions by cycle count (aggregated over their PCs): | ||
| rank cycles % cum % PCs function | ||
| 1 5335072 24.95% 24.95% 72 <...>::visit_seq::<...> | ||
| Reads the test's captured output from argv[1]; writes the Markdown body to | ||
| argv[2] (or stdout). | ||
| """ | ||
|
|
||
| import re | ||
| import sys | ||
|
|
||
| # A per-function summary row: rank, cycles, pct%, cum%, pcs, function. | ||
| FN_ROW = re.compile( | ||
| r"^\s*\d+\s+(\d+)\s+([\d.]+)%\s+([\d.]+)%\s+(\d+)\s+(.*\S)\s*$" | ||
| ) | ||
| FN_TABLE_START = re.compile(r"Top \d+ functions by cycle count") | ||
| # The "====" rule the test prints right after the (now sole) function table. | ||
| TABLE_END = re.compile(r"^=+\s*$") | ||
| TOTAL_CYCLES = re.compile(r"Total cycles\s*:\s*(\d+)") | ||
| UNIQUE_PCS = re.compile(r"Unique PCs\s*:\s*(\d+)") | ||
| EXEC_TIME = re.compile(r"Exec time\s*:\s*(\S+)") | ||
|
|
||
|
|
||
| def parse(text): | ||
| total_cycles = unique_pcs = exec_time = None | ||
| rows = [] | ||
| in_fn_table = False | ||
| for line in text.splitlines(): | ||
| if total_cycles is None and (m := TOTAL_CYCLES.search(line)): | ||
| total_cycles = int(m.group(1)) | ||
| if unique_pcs is None and (m := UNIQUE_PCS.search(line)): | ||
| unique_pcs = int(m.group(1)) | ||
| if exec_time is None and (m := EXEC_TIME.search(line)): | ||
| exec_time = m.group(1) | ||
| if FN_TABLE_START.search(line): | ||
| in_fn_table = True | ||
| continue | ||
| if in_fn_table and TABLE_END.match(line): | ||
| in_fn_table = False | ||
| continue | ||
| if in_fn_table and (m := FN_ROW.match(line)): | ||
| rows.append( | ||
| { | ||
| "cycles": int(m.group(1)), | ||
| "pct": m.group(2), | ||
| "cum": m.group(3), | ||
| "pcs": int(m.group(4)), | ||
| "fn": m.group(5), | ||
| } | ||
| ) | ||
| return total_cycles, unique_pcs, exec_time, rows | ||
|
|
||
|
|
||
| def short(name, width=90): | ||
| return name if len(name) <= width else name[: width - 1] + "…" | ||
|
|
||
|
|
||
| def render(total_cycles, unique_pcs, exec_time, rows, title="Recursion guest profile"): | ||
| if not rows: | ||
| return ( | ||
| f"### {title}\n\n" | ||
| "> ⚠️ No per-function rows found in the test output — the run may " | ||
| "have failed before printing the table. Check the workflow logs.\n" | ||
| ) | ||
|
|
||
| body = f"### {title}\n\n" | ||
| if total_cycles is not None: | ||
| body += f"**Total cycles:** {total_cycles:,}" | ||
| if unique_pcs is not None: | ||
| body += f" · **Unique PCs:** {unique_pcs:,}" | ||
| if exec_time: | ||
| body += f" · **Exec time:** {exec_time}" | ||
| body += "\n\n" | ||
|
|
||
| body += f"#### Top {len(rows)} functions by cycles (folded over their PCs)\n\n" | ||
| body += "| Rank | Cycles | % | Cum % | PCs | Function |\n" | ||
| body += "|-----:|-------:|--:|------:|----:|----------|\n" | ||
| for i, r in enumerate(rows, 1): | ||
| body += ( | ||
| f"| {i} | {r['cycles']:,} | {r['pct']}% | {r['cum']}% | " | ||
| f"{r['pcs']} | `{short(r['fn'])}` |\n" | ||
| ) | ||
|
|
||
| last_cum = rows[-1]["cum"] | ||
| body += ( | ||
| f"\n<sub>Each function's cycles are summed over all its program counters " | ||
| f"across the full histogram; the top {len(rows)} cover {last_cum}% of total " | ||
| f"cycles. Percentages are of total cycles.</sub>\n" | ||
| ) | ||
| return body | ||
|
|
||
|
|
||
| def main(): | ||
| import argparse | ||
|
|
||
| ap = argparse.ArgumentParser(description=__doc__) | ||
| ap.add_argument("log", help="captured test output to parse") | ||
| ap.add_argument("-o", "--out", help="write Markdown here instead of stdout") | ||
| ap.add_argument( | ||
| "-t", | ||
| "--title", | ||
| default="Recursion guest profile", | ||
| help="section heading (e.g. the test/config name)", | ||
| ) | ||
| args = ap.parse_args() | ||
|
|
||
| with open(args.log, "r", errors="replace") as f: | ||
| text = f.read() | ||
| body = render(*parse(text), title=args.title) | ||
| if args.out: | ||
| with open(args.out, "w") as f: | ||
| f.write(body) | ||
| else: | ||
| sys.stdout.write(body) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,178 @@ | ||
| name: Profile Recursion (PR) | ||
|
|
||
| # Runs the recursion-guest PC histogram diagnostics (single-query and | ||
| # multi-query, in parallel via a matrix) and posts a combined per-function | ||
| # profile as a PR comment. Triggered by a `/profile_recursion` comment from a | ||
| # repo member, or manually via workflow_dispatch. | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| issue_comment: | ||
| types: [created] | ||
|
|
||
| permissions: | ||
| contents: read | ||
| pull-requests: write | ||
|
|
||
| concurrency: | ||
| group: profile-recursion-${{ github.event.issue.number || github.run_id }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| # One job per configuration; they run in parallel and each uploads a Markdown | ||
| # fragment artifact. The `comment` job stitches them into one PR comment. | ||
| profile: | ||
| # Skip unless: workflow_dispatch, or "/profile_recursion" comment on a PR by a member. | ||
| if: >- | ||
| github.event_name == 'workflow_dispatch' || | ||
| (github.event_name == 'issue_comment' && | ||
| github.event.issue.pull_request && | ||
| startsWith(github.event.comment.body, '/profile_recursion') && | ||
| contains(fromJSON('["MEMBER","OWNER","COLLABORATOR"]'), github.event.comment.author_association)) | ||
| runs-on: [self-hosted, bench] | ||
| timeout-minutes: 90 | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| include: | ||
| - name: single-query | ||
| test: single | ||
| title: "Single query (blowup=2, 1 query)" | ||
| - name: multi-query | ||
| test: multi | ||
| title: "Multi query (blowup=8, 128-bit)" | ||
| steps: | ||
| - name: React to comment | ||
| if: github.event_name == 'issue_comment' && matrix.name == 'single-query' | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| await github.rest.reactions.createForIssueComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| comment_id: context.payload.comment.id, | ||
| content: 'eyes' | ||
| }); | ||
|
|
||
| - name: Get PR head ref | ||
| id: pr-ref | ||
| if: github.event_name == 'issue_comment' | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| PR_NUM: ${{ github.event.issue.number }} | ||
| run: | | ||
| SHA=$(gh pr view "$PR_NUM" --repo "$GITHUB_REPOSITORY" --json headRefOid -q .headRefOid) | ||
| echo "sha=$SHA" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| ref: ${{ steps.pr-ref.outputs.sha || github.sha }} | ||
|
|
||
| - name: Setup Rust Environment | ||
| uses: ./.github/actions/setup-rust | ||
|
|
||
| - name: Add cargo to PATH | ||
| run: echo "$HOME/.cargo/bin" >> "$GITHUB_PATH" | ||
|
|
||
| - name: Run recursion PC histogram (${{ matrix.name }}) | ||
| env: | ||
| TEST: ${{ matrix.test }} | ||
| run: | | ||
| # Self-provision the RISC-V sysroot in a user-writable dir (the default | ||
| # /opt path on the bench runner is root-owned); the guest ELF build the | ||
| # test triggers picks this up via the Makefile's `SYSROOT_DIR ?=`. | ||
| export SYSROOT_DIR="$HOME/.lambda-vm-sysroot" | ||
| set -o pipefail | ||
| make test-profile-recursion-$TEST 2>&1 | tee /tmp/hist.log | ||
|
|
||
| - name: Aggregate into a per-function fragment | ||
| if: always() | ||
| env: | ||
| TITLE: ${{ matrix.title }} | ||
| run: | | ||
| python3 .github/scripts/aggregate_recursion_histogram.py \ | ||
| /tmp/hist.log --title "$TITLE" --out "/tmp/fragment-${{ matrix.name }}.md" | ||
| cat "/tmp/fragment-${{ matrix.name }}.md" >> "$GITHUB_STEP_SUMMARY" | ||
|
|
||
| - name: Upload fragment | ||
| if: always() | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: profile-fragment-${{ matrix.name }} | ||
| path: /tmp/fragment-${{ matrix.name }}.md | ||
| retention-days: 7 | ||
|
|
||
| # Stitch the matrix fragments into a single PR comment. | ||
| comment: | ||
| needs: profile | ||
| # always() so partial-matrix failures still post; skip when `profile` was | ||
| # skipped (non-/profile_recursion or non-member comment) so this job — and | ||
| # the self-hosted bench runner it spins up — doesn't fire on every comment. | ||
| if: always() && github.event_name == 'issue_comment' && needs.profile.result != 'skipped' | ||
| runs-on: [self-hosted, bench] | ||
| steps: | ||
| - name: Get PR head ref | ||
| id: pr-ref | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| PR_NUM: ${{ github.event.issue.number }} | ||
| run: | | ||
| SHA=$(gh pr view "$PR_NUM" --repo "$GITHUB_REPOSITORY" --json headRefOid -q .headRefOid) | ||
| echo "sha=$SHA" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Download fragments | ||
| uses: actions/download-artifact@v4 | ||
| with: | ||
| path: fragments | ||
| pattern: profile-fragment-* | ||
| merge-multiple: true | ||
|
|
||
| - name: Assemble comment body | ||
| env: | ||
| COMMIT_SHA: ${{ steps.pr-ref.outputs.sha }} | ||
| run: | | ||
| { | ||
| echo "## Recursion guest profile" | ||
| echo | ||
| # Single-query first, then multi-query, then any others. | ||
| for frag in fragments/fragment-single-query.md \ | ||
| fragments/fragment-multi-query.md; do | ||
| [ -f "$frag" ] && { cat "$frag"; echo; } | ||
| done | ||
| echo "<sub>Commit: ${COMMIT_SHA:0:8} · Runner: self-hosted bench</sub>" | ||
| } > /tmp/profile_comment.md | ||
| cat /tmp/profile_comment.md | ||
|
|
||
| - name: Comment on PR | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| const fs = require('fs'); | ||
| const body = fs.readFileSync('/tmp/profile_comment.md', 'utf8'); | ||
|
|
||
| const { data: comments } = await github.rest.issues.listComments({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: context.issue.number, | ||
| }); | ||
| // Reuse our own marker comment so repeated /profile_recursion runs update in place. | ||
| const existing = comments.find(c => | ||
| c.user.type === 'Bot' && | ||
| c.body.includes('Recursion guest profile') | ||
| ); | ||
| if (existing) { | ||
| await github.rest.issues.updateComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| comment_id: existing.id, | ||
| body, | ||
| }); | ||
| } else { | ||
| await github.rest.issues.createComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: context.issue.number, | ||
| body, | ||
| }); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| [target.riscv64im-lambda-vm-elf] | ||
| rustflags = [ | ||
| "-C", "link-arg=-e", | ||
| "-C", "link-arg=main", | ||
| "--cfg", "getrandom_backend=\"custom\"", | ||
| "-C", "passes=lower-atomic" | ||
| ] |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.