Stream: t-compiler/wg-profile-guided-optimization

Topic: Documenting usage through Cargo


Alex Crichton (May 23 2019 at 15:17, on Zulip):

Nice work on the PGO docs @mw! One thing I was noticing and when testing out locally is that we may want to have more full docs on how to use it with Cargo?

Alex Crichton (May 23 2019 at 15:17, on Zulip):

some questions I was left with were:

Alex Crichton (May 23 2019 at 15:17, on Zulip):

1. You compile the instrumented binary with -O, right? Like RUSTFLAGS=-Zpgo-gen cargo build --release

Alex Crichton (May 23 2019 at 15:18, on Zulip):

2. We'll want to recommend that you use --target with pgo-gen because otherwise if you use RUSTFLAGS then everyone's build script will start spewing profiling data everywhere

Alex Crichton (May 23 2019 at 15:18, on Zulip):

3. The argument of -Z pgo-gen may want to be documented a bit more? I found that it appeared to be the directory in which all profiling data was placed

Alex Crichton (May 23 2019 at 15:18, on Zulip):

4. We probably also want to document smoke-test usage of llvm-profdata

Alex Crichton (May 23 2019 at 15:19, on Zulip):

5. I think we will want to recommend rustup component add llvm-tools-preview to get the llvm-profdata binary (and how to execute it)

Alex Crichton (May 23 2019 at 15:19, on Zulip):

6. What's the use case of multiple *.profraw files? Is the idea that each execution of a binary generates one such file, and then they're all merged into one?

Alex Crichton (May 23 2019 at 15:19, on Zulip):

7. We support this on all tier 1 platforms, right? (aka windows/mac/linux)

Alex Crichton (May 23 2019 at 15:20, on Zulip):

I also didn't really know how to get confirmation that PGO data was succesfully used, but I was also PGO'ing Cargo itself which is typically I/O bound rather than CPU bound so I wasn't entirely surprised about that

Alex Crichton (May 23 2019 at 15:20, on Zulip):

just a minor thing!

mw (May 24 2019 at 09:49, on Zulip):

so, I was planning on adding documentation to the rustc book

mw (May 24 2019 at 09:49, on Zulip):

but that's pretty specific to rustc

mw (May 24 2019 at 09:50, on Zulip):

I agree that it would make sense to document how to use this with Cargo

mw (May 24 2019 at 09:50, on Zulip):

do you have a suggestion on where to put that?

mw (May 24 2019 at 09:51, on Zulip):

the cargo book maybe?

mw (May 24 2019 at 09:56, on Zulip):

6. What's the use case of multiple *.profraw files? Is the idea that each execution of a binary generates one such file, and then they're all merged into one?

Each binary and each shared library create their own .profraw file, so you might get multiple profraw files from a single program invocation.

mw (May 24 2019 at 09:57, on Zulip):

otoh, if I understand things correctly, multiple invocations of the same program will keep updating the same profraw files.

mw (May 24 2019 at 10:02, on Zulip):

2. We'll want to recommend that you use --target with pgo-gen because otherwise if you use RUSTFLAGS then everyone's build script will start spewing profiling data everywhere

Can you tell me more about that? How does this work exactly?

mw (May 24 2019 at 14:41, on Zulip):

@Alex Crichton this is something I also just come across with -Zself-profile where I also don't want the flag to be added for build scripts.

Alex Crichton (May 24 2019 at 14:49, on Zulip):

@mw eh I don't mind too much where this goes, I just figure it should go somewhere :)

Alex Crichton (May 24 2019 at 14:49, on Zulip):

so this is where Cargo is a bit wonky

Alex Crichton (May 24 2019 at 14:50, on Zulip):

but if you pass --target $YOUR_HOST it's actually different than not passing --target

Alex Crichton (May 24 2019 at 14:50, on Zulip):

even though it produces the same binary

Alex Crichton (May 24 2019 at 14:50, on Zulip):

it triggers effectively cross compilation logic in Cargo

Alex Crichton (May 24 2019 at 14:50, on Zulip):

so RUSTFLAGS is only passed to the target, not the target + host

mw (May 24 2019 at 14:56, on Zulip):

I wanna write "makes sense", but ... :P

mw (May 24 2019 at 14:56, on Zulip):

a very interesting piece of information though

mw (May 24 2019 at 14:56, on Zulip):

I did not know that

Alex Crichton (May 24 2019 at 15:01, on Zulip):

rest assured you're not the only person who's been tripped up by it

mw (May 27 2019 at 15:37, on Zulip):

@Alex Crichton rustup component add llvm-tools-preview seems to install llvm-profdata in a kind of obscure path. For example ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin.

mw (May 27 2019 at 15:38, on Zulip):

Is there a way to call the tool ergonomically?

mw (May 27 2019 at 15:38, on Zulip):

rustup which does not seem to work

mw (May 27 2019 at 15:39, on Zulip):

rustup run nightly llvm-profdata seems work

mw (May 27 2019 at 15:40, on Zulip):

would be great if rustup run could just the default toolchain for a given path

mw (May 27 2019 at 15:42, on Zulip):

oh, it does not work. It calls whatever is on PATH

Alex Crichton (May 28 2019 at 13:19, on Zulip):

Yeah we've never really "stabilized" this in one form or another

Alex Crichton (May 28 2019 at 13:20, on Zulip):

currently the tools were added mostly for the embedded WG where the idea is that there's otherwise existing tooling which reaches into the sysroot to use these executables

Alex Crichton (May 28 2019 at 13:20, on Zulip):

we have historically not wanted to commit to the stability of their location or availability

Alex Crichton (May 28 2019 at 13:21, on Zulip):

in that sense it's intentional that they're not the easiest to use, but that's sort of the same for PGO in that it's not really the easiest to use so it may just want to be documented where to find them

mw (May 28 2019 at 13:22, on Zulip):

OK

mw (May 28 2019 at 13:23, on Zulip):

I also found out that all versions of llvm-profdata since LLVM 3.9 seem to work just fine what rustc is currently producing

mw (May 28 2019 at 13:24, on Zulip):

so I'm just going to recommend using llvm-profdata from "a recent LLVM installation" as a fallback

Alex Crichton (May 28 2019 at 14:13, on Zulip):

@mw sounds good, it sounds like they've probably put effort into stabilizing it themselves maybe?

mw (May 28 2019 at 14:16, on Zulip):

maybe. At least I think they are trying to only change it with good reason

Last update: Nov 15 2019 at 11:05UTC