Repository navigation
Document profiling rustc with Valgrind and Cachegrind - #3073
Closed
isHeSatoshi wants to merge 1 commit into
Closed
isHeSatoshi wants to merge 1 commit into
isHeSatoshi wants to merge 1 commit into
Conversation
The profiling chapter lists perf, Tracy and WPA, but not Valgrind, whose Callgrind and Cachegrind tools measure something the sampling profilers cannot: exact instruction counts, and simulated cache and branch behaviour. Add a page alongside the perf one. The interesting part is not running Valgrind, it is getting it to profile the compiler: cargo runs rustc as a subprocess, so `valgrind cargo build` profiles cargo, and the rustc in PATH is usually the rustup shim rather than the compiler itself. Both traps are covered, together with the fact that RUSTC names a program rather than a command line.
This comment was marked as low quality.
This comment was marked as low quality.
Collaborator
|
Thanks for the PR. If you have write access, feel free to merge this PR if it does not need reviews. You can request a review using |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #1166.
The profiling chapter lists perf, Tracy and WPA, but nothing about Valgrind. Callgrind and Cachegrind measure something the sampling profilers do not: exact instruction counts, and simulated cache and branch behaviour.
The part worth writing down is not how to run Valgrind, it is how to get it to profile the compiler, which is the caveat the issue points at. There are two traps:
cargorunsrustcas a subprocess, sovalgrind cargo buildprofilescargo. Valgrind has to be the parent ofrustc.rustcinPATHis usually the rustup shim, not the compiler, so you would profile the shim.The page covers both, plus the fact that
RUSTCnames a program rather than a command line, and the two ways to slot Valgrind in (RUSTCpointing at a wrapper script, orRUSTC_WRAPPER).What I verified, and how
I checked the cargo side rather than assuming it, since that is the part that is easy to get wrong:
cargohonoursRUSTC: withRUSTCset to a wrapper script that logs its arguments and then execs the real compiler, acargo buildrouted all four of its compiler invocations through the wrapper, and the build succeeded.RUSTCis a program path, not a command line: withRUSTC="<tool> <path-to-rustc>", cargo failed withcould not execute process ... never executed, i.e. it looked for a program with that whole string as its name. So the form suggested in the issue,env RUSTC="valgrind $(rustup which rustc)", does not work as written, which is why the page uses a wrapper script.RUSTC_WRAPPERbehaves the same way: it too rejects a value with arguments.RUSTC_WRAPPERreceives the path torustcas its first argument: logging the wrapper's arguments showedARG1=[...\bin\rustc.exe] ARG2=[-vV].rustconPATHis not the same file asrustup which rustc(...\.cargo\bin\rustc.exeversus...\.rustup\toolchains\...\bin\rustc.exe), which is the second trap.The Valgrind-side facts are from its manuals, which I read rather than recalled:
callgrind.out.<pid>andcallgrind_annotate,cachegrind.out.<pid>andcg_annotate, and the Callgrind manual's recommendation of KCachegrind. All five links added return HTTP 200.One thing I could not verify: I am on Windows, where Valgrind does not run, so I could not produce an actual profile. The wrapper and
RUSTC_WRAPPERmechanics above are observed, but the claim that the resulting file is a useful Callgrind profile rests on Valgrind's documentation. If a reviewer has a Linux machine, that is the step worth double-checking.Checks
RUSTC_BOOTSTRAP=1 cargo run --release --manifest-path ci/sembr/Cargo.toml srcreportssrc/profiling/with-valgrind.mdas compliant, as it does for the two edited files..htmllinks; the only one in the touched files is the pre-existing external cargo--timingsURL.SUMMARY.mdand linked from the profiling chapter's list.