forked from FuelLabs/sway
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Benchmark / performance tracking (FuelLabs#4564)
## Description Adds an initial benchmarking setup to CI, where a collection of libraries from https://github.com/FuelLabs/sway-libs are compiled, performance metrics generated and later pushed into a new repo: https://github.com/FuelLabs/sway-performance-data Closes FuelLabs#318. ## Checklist - [x] I have linked to any relevant issues. - [x] I have commented my code, particularly in hard-to-understand areas. - [x] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [x] I have added tests that prove my fix is effective or that my feature works. - [x] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers.
- Loading branch information
Showing
23 changed files
with
347 additions
and
34 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,6 @@ sway-lib-std/Forc.lock | |
|
||
# Forc's build directory | ||
out | ||
|
||
# Benchmarks data output directory | ||
benchmarks/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
#!/usr/bin/env bash | ||
|
||
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) | ||
|
||
PREPARE_FOR_COMMIT=false | ||
while [[ $# -gt 0 ]] | ||
do | ||
key="$1" | ||
case $key in | ||
--prepare-for-commit) | ||
PREPARE_FOR_COMMIT=true | ||
shift # past argument | ||
;; | ||
*) | ||
shift # past argument | ||
;; | ||
esac | ||
done | ||
|
||
benchmarks_dir="benchmarks" | ||
if [ ! -d "$benchmarks_dir" ]; then | ||
mkdir -p "$benchmarks_dir" | ||
fi | ||
|
||
if [ -d "$SCRIPT_DIR/target/release" ]; then | ||
build_type="release" | ||
elif [ -d "$SCRIPT_DIR/target/debug" ]; then | ||
build_type="debug" | ||
else | ||
echo "Neither target/release nor target/debug directories found. Exiting..." | ||
exit 1 | ||
fi | ||
|
||
forc_path="$SCRIPT_DIR/target/$build_type/forc" | ||
|
||
# prepare the benchmark data for commit if requested | ||
if $PREPARE_FOR_COMMIT; then | ||
sway_peformance_data_dir=performance-data | ||
[email protected]:FuelLabs/sway-performance-data.git | ||
|
||
if [ ! -d "$SCRIPT_DIR/$sway_peformance_data_dir" ]; then | ||
echo "Directory $sway_peformance_data_dir not found. Cloning the repository..." | ||
git clone "$sway_performance_data_repo_url" "$sway_peformance_data_dir" | ||
echo "Repository cloned into $sway_peformance_data_dir." | ||
else | ||
echo "Updating sway-performance-data repository..." | ||
git -C "$SCRIPT_DIR/$sway_peformance_data_dir" pull | ||
fi | ||
|
||
mkdir -p "$SCRIPT_DIR/$sway_peformance_data_dir/$GITHUB_SHA" | ||
cp -r $benchmarks_dir/* "$SCRIPT_DIR/$sway_peformance_data_dir/$GITHUB_SHA" | ||
else | ||
sway_libs_dir=sway-libs | ||
sway_libs_repo_url=https://github.com/FuelLabs/sway-libs.git | ||
sway_libs_branch_name="benchmarks" | ||
|
||
if [ ! -d "$SCRIPT_DIR/$sway_libs_dir" ]; then | ||
echo "Directory $sway_libs_dir not found. Cloning the repository..." | ||
git clone -b "$sway_libs_branch_name" "$sway_libs_repo_url" "$sway_libs_dir" | ||
echo "Repository cloned with branch $sway_libs_branch_name into $sway_libs_dir." | ||
fi | ||
|
||
libs=( | ||
"fixed_point" | ||
"merkle_proof" | ||
"nft" | ||
"ownership" | ||
"reentrancy" | ||
"signed_integers" | ||
"storagemapvec" | ||
"strings/storage_string" | ||
"strings/string" | ||
) | ||
|
||
sway_apps_dir=sway-applications | ||
sway_apps_repo_url=https://github.com/FuelLabs/sway-applications.git | ||
sway_apps_branch_name="master" | ||
|
||
if [ ! -d "$SCRIPT_DIR/$sway_apps_dir" ]; then | ||
echo "Directory $sway_apps_dir not found. Cloning the repository..." | ||
git clone -b "$sway_apps_branch_name" "$sway_apps_repo_url" "$sway_apps_dir" | ||
echo "Repository cloned with branch $sway_apps_branch_name into $sway_apps_dir." | ||
fi | ||
|
||
sway_libs_revision=$(git -C $SCRIPT_DIR/$sway_libs_dir rev-parse HEAD) | ||
sway_apps_revision=$(git -C $SCRIPT_DIR/$sway_apps_dir rev-parse HEAD) | ||
sway_git_revision=$(git rev-parse HEAD) | ||
|
||
for lib in "${libs[@]}"; do | ||
echo "Benchmarking $lib..." | ||
project_name=$(basename "$lib") | ||
metrics_json_file="$benchmarks_dir/$project_name.json" | ||
output=$(/usr/bin/time -f '{"elapsed": "%e", "cpu_usage": "%P", "memory": "%MKB"}' \ | ||
$forc_path build --path "$SCRIPT_DIR/sway-libs/libs/$lib" \ | ||
--metrics-outfile="$metrics_json_file" 2>&1) | ||
|
||
exit_status=$? | ||
if [ $exit_status -ne 0 ]; then | ||
echo " Failed, ignoring." | ||
continue | ||
fi | ||
|
||
# filter out forc warnings by only matching on the JSON metrics data | ||
json_stats=$(echo "$output" | grep -Eo '^\s*{[^}]*}') | ||
|
||
metrics_json=$(cat "$metrics_json_file" | jq '{phases: .}') | ||
merged_json=$(jq -s '.[0] * .[1]' <(echo "$metrics_json") <(echo "$json_stats")) | ||
merged_json=$(jq --arg bt "$build_type" '. + {build_type: $bt}' <<< "$merged_json") | ||
merged_json=$(jq --arg gr "$sway_apps_revision" '. + {sway_apps_revision: $gr}' <<< "$merged_json") | ||
merged_json=$(jq --arg gr "$sway_libs_revision" '. + {sway_libs_revision: $gr}' <<< "$merged_json") | ||
merged_json=$(jq --arg gr "$sway_git_revision" '. + {sway_git_revision: $gr}' <<< "$merged_json") | ||
|
||
echo "$merged_json" > $metrics_json_file | ||
done | ||
fi |
This file contains 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
This file contains 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
Oops, something went wrong.