-
Notifications
You must be signed in to change notification settings - Fork 120
feat(l1): add target and script to run multiple benchmark runs #5368
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds automation for running multiple benchmark iterations by introducing a shell script and a new Makefile target. The goal is to streamline the process of running repeated import benchmarks with automatic log file numbering.
- Adds
benchmark.shscript to automate multiple benchmark runs with sequential log numbering - Introduces
run-benchesMakefile target as a convenient wrapper for the script - Enables running 3 benchmark iterations by default using the existing benchmark infrastructure
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| tooling/import_benchmark/benchmark.sh | New shell script that runs multiple benchmark iterations with automatic log file numbering and cleanup |
| tooling/import_benchmark/Makefile | Adds run-benches target to invoke the benchmark script with 3 repetitions |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| NETWORK=$1 | ||
| NUM_REPETITIONS=$2 | ||
|
|
Copilot
AI
Nov 14, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing input validation for required parameters. The script will fail with cryptic errors if NETWORK or NUM_REPETITIONS are not provided. Add validation to check if both parameters are supplied and NUM_REPETITIONS is a positive integer.
| NETWORK=$1 | |
| NUM_REPETITIONS=$2 | |
| # Input validation | |
| if [ $# -ne 2 ]; then | |
| echo "Usage: $0 <NETWORK> <NUM_REPETITIONS>" | |
| exit 1 | |
| fi | |
| NETWORK=$1 | |
| NUM_REPETITIONS=$2 | |
| # Check that NUM_REPETITIONS is a positive integer | |
| if ! [[ "$NUM_REPETITIONS" =~ ^[1-9][0-9]*$ ]]; then | |
| echo "Error: NUM_REPETITIONS must be a positive integer." | |
| exit 1 | |
| fi |
| NUM_REPETITIONS=$2 | ||
|
|
||
| touch bench-0.log | ||
| bench_id=$(ls bench-*.log | cut -d '-' -f 2 | cut -d '.' -f 1 | sort -n | tail -1) |
Copilot
AI
Nov 14, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ls bench-*.log command will fail with an error if no bench-*.log files exist (even after creating bench-0.log in some scenarios where the touch fails). Additionally, using ls for scripting is fragile. Consider using: bench_id=$(find . -maxdepth 1 -name 'bench-*.log' -printf '%f\n' 2>/dev/null | cut -d '-' -f 2 | cut -d '.' -f 1 | sort -n | tail -1 || echo 0) or handle the case where no files exist more explicitly.
| bench_id=$(ls bench-*.log | cut -d '-' -f 2 | cut -d '.' -f 1 | sort -n | tail -1) | |
| bench_id=$(find . -maxdepth 1 -name 'bench-*.log' -printf '%f\n' 2>/dev/null | cut -d '-' -f 2 | cut -d '.' -f 1 | sort -n | tail -1) | |
| bench_id=${bench_id:-0} |
| touch bench-0.log | ||
| bench_id=$(ls bench-*.log | cut -d '-' -f 2 | cut -d '.' -f 1 | sort -n | tail -1) | ||
|
|
||
| cd ../.. |
Copilot
AI
Nov 14, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The script changes directory to ../.. without error checking or explanation. This makes the script fragile if called from an unexpected location. Consider either: (1) using cd ../.. || exit 1 to fail fast if the directory doesn't exist, or (2) storing the original directory and using absolute paths, or (3) adding a comment explaining the expected directory structure.
| cd ../.. | |
| cd ../.. || exit 1 |
| bench_id=$((bench_id + 1)) | ||
| rm -rf ~/.local/share/temp | ||
| cp -r ~/.local/share/ethrex_${NETWORK}_bench/ethrex ~/.local/share/temp | ||
| cargo r --release -- --network $NETWORK --datadir ~/.local/share/temp import-bench ~/.local/share/ethrex_${NETWORK}_bench/chain.rlp | tee bench-${bench_id}.log |
Copilot
AI
Nov 14, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The output log file bench-${bench_id}.log is written to the ethrex root directory (after cd ../..), but the initial log file discovery in line 9 looks for logs in the tooling/import_benchmark directory. This inconsistency means the auto-incrementing bench_id won't work correctly after the first run. The logs should either all be in the same directory, or the script should cd back to the original directory before writing logs.
| run-bench: ## Runs a bench for the current pr. parameters -BENCH_ID: number for the log file where it will be saved -NETWORK: which network to acesss | ||
| rm -rf ~/.local/share/temp | ||
| cp -r ~/.local/share/ethrex_$(NETWORK)_bench/ethrex ~/.local/share/temp | ||
| cd ../.. && cargo r --release -- --network $(NETWORK) --datadir ~/.local/share/temp import-bench ~/.local/share/ethrex_$(NETWORK)_bench/chain.rlp | tee bench-$(BENCH_ID).log |
Copilot
AI
Nov 14, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new run-benches target lacks documentation. Other targets in the Makefile have comments explaining their purpose, parameters, and requirements. Add a comment describing this target, its purpose, and that it runs 3 benchmark iterations by default.
| cd ../.. && cargo r --release -- --network $(NETWORK) --datadir ~/.local/share/temp import-bench ~/.local/share/ethrex_$(NETWORK)_bench/chain.rlp | tee bench-$(BENCH_ID).log | |
| # run-benches: ## Runs 3 benchmark iterations by default for the current PR. | |
| # Parameters: | |
| # - NETWORK: which network to access (hoodi, mainnet) | |
| # Requirements: | |
| # Assumes the environment is set up as for run-bench (Linux, valid db and chain.rlp in ~/.local/share/ethrex_NETWORK_bench/) |
| cp -r ~/.local/share/ethrex_$(NETWORK)_bench/ethrex ~/.local/share/temp | ||
| cd ../.. && cargo r --release -- --network $(NETWORK) --datadir ~/.local/share/temp import-bench ~/.local/share/ethrex_$(NETWORK)_bench/chain.rlp | tee bench-$(BENCH_ID).log | ||
|
|
||
| run-benches: |
Copilot
AI
Nov 14, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The number of repetitions (3) is hardcoded. Consider making it configurable via a Makefile variable like NUM_REPS ?= 3 to allow users to easily customize the number of benchmark runs without modifying the script or Makefile.
Benchmark Block Execution Results Comparison Against Main
|
| @printf "python3 parse_bench.py bench_num_1 bench_num_2: ## Parses the bench log files from [bench_num_1 to bench_num_2) to find average ggas\nRequirements\n\ | ||
| This script assumes we have the bench logs on the ethrex folder\n\n" | ||
|
|
||
| run-bench: ## Runs a bench for the current pr. parameters -BENCH_ID: number for the log file where it will be saved -NETWORK: which network to acesss |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: I think that we should have the rm -> cp -> cargo r -- import-bench process defined in a single file, either the cargo or the make.
This PR improves
tooling/import_benchmarkby adding a target that runs multiple repetitions of the same benchmark.