From 7a8e12b8f467ebb7c1ff917189f1c7a59b7472a3 Mon Sep 17 00:00:00 2001 From: Jakub Nabaglo Date: Sat, 23 Oct 2021 11:55:49 -0700 Subject: [PATCH] Profile-guided optimization script (#321) --- .gitignore | 2 ++ pgo-profile.sh | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100755 pgo-profile.sh diff --git a/.gitignore b/.gitignore index 96ef6c0b..3a09fb6a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ /target Cargo.lock +/tmp +pgo-data.profdata diff --git a/pgo-profile.sh b/pgo-profile.sh new file mode 100755 index 00000000..48be564a --- /dev/null +++ b/pgo-profile.sh @@ -0,0 +1,31 @@ +#!/bin/sh + +rm -rf tmp/pgo + +if !(rustup help >/dev/null); then + echo "Rustup not found; ensure rustup is on PATH" 1>&2 + exit 1 +fi + +if !(rustup component add llvm-tools-preview); then + echo "Could not install llvm-tools-preview" 1>&2 + exit 1 +fi + +TOOLCHAIN_BASE=$(dirname $(dirname $(rustup which cargo))) +TOOLCHAIN_NAME=$(basename $TOOLCHAIN_BASE) +TARGET_TRIPLE=${TOOLCHAIN_NAME#*"-"} # e.g. nightly-x86_64-apple-darwin -> x86_64-apple-darwin +PROFDATA_PATH=$TOOLCHAIN_BASE/lib/rustlib/$TARGET_TRIPLE/bin/llvm-profdata + +if !(RUSTFLAGS="$RUSTFLAGS -Cprofile-generate=$(pwd)/tmp/pgo/data -Ctarget-cpu=native" cargo test --target-dir tmp/pgo/target --release test_recursive_recursive_verifier -- --ignored); then + echo "Build failed" 1>&2 + exit 1 +fi +if !($PROFDATA_PATH merge -o pgo-data.profdata tmp/pgo/data); then + echo "Could not create .profdata file" 1>&2 + exit 1 +fi + +rm -rf tmp/pgo + +echo '.profdata file successfully created. Add "-Cprofile-use=$(pwd)/pgo-data.profdata" to RUSTFLAGS to use it.' 1>&2