Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(docs): add cargo-pgo to PGO documentation 馃摑 #114998

Merged
merged 4 commits into from Oct 27, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/doc/rustc/src/profile-guided-optimization.md
Expand Up @@ -145,3 +145,25 @@ in Clang's documentation is therefore an interesting read for anyone who wants
to use PGO with Rust.

[clang-pgo]: https://clang.llvm.org/docs/UsersManual.html#profile-guided-optimization

## Community Maintained Tools

As an alternative to directly using the compiler for Profile-Guided Optimization,
you may choose to go with `cargo-pgo`, which has an intuitive command-line API
and saves you the trouble of doing all the manual work. You can read more about
it in their repository accessible from this link: https://github.com/Kobzol/cargo-pgo

For the sake of completeness, here are the corresponding steps using `cargo-pgo`:

```bash
# Install the binary as usual: cargo install cargo-pgo
cargo pgo build
LLVM_PROFILE_FILE=./target/pgo-profiles/rustc-pgo_%m_%p.profraw ./target/x86_64-unknown-linux-gnu/release/myprogram
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would perhaps remove the LLVM_PROFILE_FILE env. var. It's only needed for programs that generate a lot of processes internally (which is not that common), so I think that it could be avoided in this example, to make it simpler.

cargo pgo optimize
```

These steps will do the following just as before:

1. Build an instrumented binary from the source code.
2. Use the instrumentation in the binary when running it for the first time.
meysam81 marked this conversation as resolved.
Show resolved Hide resolved
3. Use the instrumentation results from the last step to create an optimized binary.
meysam81 marked this conversation as resolved.
Show resolved Hide resolved