Skip to content

Commit

Permalink
Test
Browse files Browse the repository at this point in the history
  • Loading branch information
ByteNacked committed Aug 27, 2024
1 parent 23f2058 commit 9b16cff
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 82 deletions.
4 changes: 2 additions & 2 deletions runtime-interface/sandbox/src/detail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,8 @@ pub fn memory_new(context: &mut dyn FunctionContext, initial: u32, maximum: u32)
// they run with minimal steps and a large number of repeats, leading to significant slowdowns.
// Therefore, we have to clear it manually if the `BENCH_SANDBOX_RESET_COUNTER` exceeds the limit.
// Otherwise, the store becomes too big and will slow down the benchmarks.
#[cfg(feature = "runtime-benchmarks")]
sandboxes.borrow_mut().clear();
//#[cfg(feature = "runtime-benchmarks")]
//sandboxes.borrow_mut().clear();

sandboxes
.borrow_mut()
Expand Down
4 changes: 2 additions & 2 deletions sandbox/host/src/sandbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,8 +530,8 @@ impl<DT: Clone> SandboxComponents<DT> {
/// Create a new empty sandbox store.
pub fn new(backend: SandboxBackend) -> Self {
SandboxComponents {
instances: Vec::new(),
memories: Vec::new(),
instances: Vec::with_capacity(1000),
memories: Vec::with_capacity(1000),
backend_context: BackendContext::new(backend),
}
}
Expand Down
147 changes: 69 additions & 78 deletions scripts/benchmarking/run_all_benchmarks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,10 @@ for PALLET in "${PALLETS[@]}"; do
# Run multithreaded benchmarks (pallet_gear_builtin) on fixed 4 cores.
if [ -n "$INSTANCE_TYPE" ] && [ "$PALLET" == "pallet_gear_builtin" ]
then
PREV_TASKSET_CMD=$TASKSET_CMD
TASKSET_CMD="taskset -c 2,3,4,5"
echo "[+] Running pallet_gear_builtin benches on fixed 4 cores: 2,3,4,5"
else
TASKSET_CMD=""
fi

# Get all the extrinsics for the pallet if the pallet is "pallet_gear".
Expand Down Expand Up @@ -181,92 +182,82 @@ for PALLET in "${PALLETS[@]}"; do
fi

WEIGHT_FILE="./${WEIGHTS_OUTPUT}/${PALLET}.rs"
echo "[+] Benchmarking $PALLET with weight file $WEIGHT_FILE";

OUTPUT=$(
$TASKSET_CMD $GEAR benchmark pallet \
--chain="$chain_spec" \
--steps=$BENCHMARK_STEPS \
--repeat=$BENCHMARK_REPEAT \
--pallet="$PALLET" \
--extrinsic="$(IFS=, ; echo "${EXTRINSICS[*]}")" \
--heap-pages=4096 \
--output="$WEIGHT_FILE" \
--template=.maintain/frame-weight-template.hbs 2>&1
)

if [ $? -ne 0 ]; then
echo "$OUTPUT" >> "$ERR_FILE"
echo "[-] Failed to benchmark $PALLET. Error written to $ERR_FILE; continuing..."
fi
#echo "[+] Benchmarking $PALLET with weight file $WEIGHT_FILE";

#OUTPUT=$(
# $TASKSET_CMD $GEAR benchmark pallet \
# --chain="$chain_spec" \
# --steps=$BENCHMARK_STEPS \
# --repeat=$BENCHMARK_REPEAT \
# --pallet="$PALLET" \
# --extrinsic="$(IFS=, ; echo "${EXTRINSICS[*]}")" \
# --heap-pages=4096 \
# --output="$WEIGHT_FILE" \
# --template=.maintain/frame-weight-template.hbs 2>&1
#)

#if [ $? -ne 0 ]; then
# echo "$OUTPUT" >> "$ERR_FILE"
# echo "[-] Failed to benchmark $PALLET. Error written to $ERR_FILE; continuing..."
#fi

# If the pallet is pallet_gear, benchmark the one-time extrinsics.
if [ "$PALLET" == "pallet_gear" ]
then
echo "[+] Benchmarking $PALLET one-time syscalls with weight file ./${WEIGHTS_OUTPUT}/${PALLET}_onetime.rs";
OUTPUT=$(
$TASKSET_CMD $GEAR benchmark pallet \
--chain="$chain_spec" \
--steps=$BENCHMARK_STEPS_ONE_TIME_EXTRINSICS \
--repeat=$BENCHMARK_REPEAT_ONE_TIME_EXTRINSICS \
--pallet="$PALLET" \
--extrinsic="$(IFS=', '; echo "${ONE_TIME_EXTRINSICS[*]}")" \
--heap-pages=4096 \
--output="./${WEIGHTS_OUTPUT}/${PALLET}_onetime.rs" \
--template=.maintain/frame-weight-template.hbs 2>&1
)
echo "[+] MSquares Benchmarking $PALLET one-time syscalls with weight file ./${WEIGHTS_OUTPUT}/${PALLET}_onetime.rs";

$TASKSET_CMD $GEAR benchmark pallet \
--chain="$chain_spec" \
--steps=$BENCHMARK_STEPS_ONE_TIME_EXTRINSICS \
--repeat=$BENCHMARK_REPEAT_ONE_TIME_EXTRINSICS \
--pallet="$PALLET" \
--extrinsic="gr_exit" \
--heap-pages=4096

if [ $? -ne 0 ]; then
echo "$OUTPUT" >> "$ERR_FILE"
echo "[-] Failed to benchmark $PALLET. Error written to $ERR_FILE; continuing..."
fi
fi

# Reset the taskset command if it was changed.
if [ -n "$PREV_TASKSET_CMD" ]
then
TASKSET_CMD=$PREV_TASKSET_CMD
unset PREV_TASKSET_CMD
fi
done

if [ "$skip_machine_benchmark" != true ]
then
echo "[+] Benchmarking the machine..."
OUTPUT=$(
$TASKSET_CMD $GEAR benchmark machine --chain=$chain_spec --allow-fail 2>&1
)
# In any case don't write errors to the error file since they're not benchmarking errors.
echo "[x] Machine benchmark:\n$OUTPUT"
echo $OUTPUT >> $MACHINE_OUTPUT
fi

# If `-s` is used, run the storage benchmark.
if [ ! -z "$storage_folder" ]; then
OUTPUT=$(
$TASKSET_CMD $GEAR benchmark storage \
--chain=$chain_spec \
--state-version=1 \
--warmups=10 \
--base-path=$storage_folder \
--weight-path=./$STORAGE_OUTPUT 2>&1
)
if [ $? -ne 0 ]; then
echo "$OUTPUT" >> "$ERR_FILE"
echo "[-] Failed the storage benchmark. Error written to $ERR_FILE; continuing..."
fi
else
unset storage_folder
fi

# Merge pallet_gear weights.
./scripts/benchmarking/merge_outputs.sh

# Check if the error file exists.
if [ -f "$ERR_FILE" ]; then
echo "[-] Some benchmarks failed. See: $ERR_FILE"
exit 1
else
echo "[+] All benchmarks passed."
exit 0
fi
#if [ "$skip_machine_benchmark" != true ]
#then
# echo "[+] Benchmarking the machine..."
# OUTPUT=$(
# $TASKSET_CMD $GEAR benchmark machine --chain=$chain_spec --allow-fail 2>&1
# )
# # In any case don't write errors to the error file since they're not benchmarking errors.
# echo "[x] Machine benchmark:\n$OUTPUT"
# echo $OUTPUT >> $MACHINE_OUTPUT
#fi
#
## If `-s` is used, run the storage benchmark.
#if [ ! -z "$storage_folder" ]; then
# OUTPUT=$(
# $TASKSET_CMD $GEAR benchmark storage \
# --chain=$chain_spec \
# --state-version=1 \
# --warmups=10 \
# --base-path=$storage_folder \
# --weight-path=./$STORAGE_OUTPUT 2>&1
# )
# if [ $? -ne 0 ]; then
# echo "$OUTPUT" >> "$ERR_FILE"
# echo "[-] Failed the storage benchmark. Error written to $ERR_FILE; continuing..."
# fi
#else
# unset storage_folder
#fi
#
## Merge pallet_gear weights.
#./scripts/benchmarking/merge_outputs.sh
#
## Check if the error file exists.
#if [ -f "$ERR_FILE" ]; then
# echo "[-] Some benchmarks failed. See: $ERR_FILE"
# exit 1
#else
# echo "[+] All benchmarks passed."
# exit 0
#fi

0 comments on commit 9b16cff

Please sign in to comment.