Skip to content

Commit 35df59d

Browse files
committed
tools/devtool: add PGO helper scripting to devtool
Added commands to build with instrumentation, profile, merge the .profraw files, and optimize/rebuild Signed-off-by: Valerie Pieger <[email protected]>
1 parent ae078ee commit 35df59d

File tree

5 files changed

+51
-0
lines changed

5 files changed

+51
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,6 @@ test_results/*
1515
/resources/linux
1616
/resources/x86_64
1717
/resources/aarch64
18+
llvm.sh
19+
vmlinux
20+
vmlinux.bin

resources/rootfs.ext4

Whitespace-only changes.

resources/vmlinux

Whitespace-only changes.

rootfs.ext4

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Error><Code>NoSuchKey</Code><Message>The specified key does not exist.</Message><Key>img/quickstart_guide/rootfs.ext4</Key><RequestId>F23FN2VRXVEBN5NM</RequestId><HostId>RrqeuoufdOrTKnTLGPPYxjH2RiVaSJydFn55q2W4YypHv89V3TWTxzszOt7fMQTf0w86xQRdRUk=</HostId></Error>

tools/devtool

+46
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,9 @@ cmd_help() {
411411
echo " Downloads the CI artifacts used for testing from our S3 bucket. If --force is passed, purges any existing"
412412
echo " artifacts first. Useful for refreshing local artifacts after an update, or if something got messed up."
413413
echo ""
414+
echo " pgo_build [instrument|profile|merge|optimize]"
415+
echo " Build Firecracker with Profile-Guided Optimization (PGO). See README-pgo.md for more information"
416+
echo ""
414417

415418
cat <<EOF
416419
test_debug [-- [<pytest args>]]
@@ -1083,6 +1086,49 @@ cmd_build_ci_artifacts() {
10831086
cmd_fix_perms
10841087
}
10851088

1089+
cmd_pgo_build() {
1090+
# For error checking and detecting architecture type
1091+
set -e
1092+
1093+
PROFDATA_DIR=/tmp/firecracker-profdata
1094+
PROFDATA_FILE=/tmp/firecracker.profdata
1095+
1096+
arch=$(uname -m)
1097+
if [[ "$arch" != "x86_64" ]]; then
1098+
echo "Warning: Non-x86_64 architecture detected ($arch)"
1099+
echo "Some features like /dev/kvm and full microVM profiling may not work."
1100+
fi
1101+
1102+
1103+
case "$1" in
1104+
instrument)
1105+
echo "Building instrumented Firecracker binary"
1106+
RUSTFLAGS="-Cprofile-generate=/tmp/firecracker-profdata" cargo build --release
1107+
echo "Instrumentation complete."
1108+
;;
1109+
profile)
1110+
echo "Run workloads manually to generate .profraw files in /tmp/firecracker-profdata/"
1111+
echo "Please consult README-pgo.md for more information."
1112+
;;
1113+
merge)
1114+
echo "Merging .profraw files"
1115+
if ! llvm-profdata merge -output=${PROFDATA_FILE} ${PROFDATA_DIR}/*.profraw; then
1116+
echo "Error: Failed to merge profile data."
1117+
echo " Make sure .profraw files exist and are readable."
1118+
exit 1
1119+
fi
1120+
echo "Merging complete."
1121+
;;
1122+
optimize)
1123+
echo "Building optimized Firecracker with profile data"
1124+
RUSTFLAGS="-Cprofile-use=/tmp/firecracker.profdata -Cllvm-args=-pgo-warn-missing-function" cargo build --release
1125+
;;
1126+
*)
1127+
echo "Usage: $0 pgo_build [instrument|profile|merge|optimize]"
1128+
exit 1
1129+
;;
1130+
esac
1131+
}
10861132

10871133
main() {
10881134

0 commit comments

Comments
 (0)