Skip to content

Commit

Permalink
test(instrumentation): add build step duration tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
basti1302 committed Jan 15, 2025
1 parent a82dcd8 commit e8854ac
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
45 changes: 45 additions & 0 deletions images/instrumentation/test/build_time_profiling
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
declare -A all_build_step_times

print_time() {
local t="$1"
printf '%02dh:%02dm:%02ds\n' $((t/3600)) $((t%3600/60)) $((t%60))
}

store_build_step_duration() {
local step_label=$1
local start=$2
local end=$(date +%s)
local duration=$(($end-$start))
all_build_step_times["$step_label"]="$duration"
}

print_build_step_duration() {
local step_label=$1
local start=$2
local end=$(date +%s)
local duration=$(($end-$start))
printf "[build time] $step_label:"'\t'"$(print_time "$duration")"'\n'
}

print_total_build_time_info() {
local total_build_end=$(date +%s)
local total_build_duration=$(($total_build_end-$start_time_build))
local accounted_for_total=0
echo
echo "**build step durations**"
for label in "${!all_build_step_times[@]}"; do
local d="${all_build_step_times[$label]}"
printf "[build time] $label:"'\t'"$(print_time "$d")"'\n'
accounted_for_total=$(($accounted_for_total+$d))
done

echo ----------------------------------------
echo "**summary**"
print_build_step_duration "**total build time**" "$start_time_build"

# check that we are actually measuring all relevant build steps:
local unaccounted=$(($total_build_duration-$accounted_for_total))
printf "[build time] build time account for by individual build steps:"'\t'"$(print_time "$accounted_for_total")"'\n'
printf "[build time] build time unaccounted for by individual build steps:"'\t'"$(print_time "$unaccounted")"'\n'
}

18 changes: 18 additions & 0 deletions images/instrumentation/test/test-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,19 @@
set -euo pipefail
shopt -s lastpipe

start_time_build=$(date +%s)

RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'

cd "$(dirname "${BASH_SOURCE[0]}")"/..

# shellcheck source=images/instrumentation/test/build_time_profiling
source ./test/build_time_profiling

trap print_total_build_time_info EXIT

# shellcheck source=images/instrumentation/injector/test/scripts/util
source injector/test/scripts/util

Expand All @@ -23,6 +30,8 @@ exit_code=0
summary=""

build_or_pull_instrumentation_image() {
# shellcheck disable=SC2155
local start_time_step=$(date +%s)
if [[ -n "${INSTRUMENTATION_IMAGE:-}" ]]; then
instrumentation_image="$INSTRUMENTATION_IMAGE"

Expand All @@ -36,6 +45,7 @@ build_or_pull_instrumentation_image() {
echo "using existing local instrumentation image: $instrumentation_image"
echo ----------------------------------------
fi
store_build_step_duration "pull instrumentation image" "$start_time_step"
else
echo ----------------------------------------
echo "building multi-arch instrumentation image for platforms ${all_docker_platforms} from local sources"
Expand All @@ -51,6 +61,8 @@ build_or_pull_instrumentation_image() {
echo "${build_output}"
exit 1
fi

store_build_step_duration "build instrumentation image" "$start_time_step"
fi
echo
}
Expand All @@ -70,6 +82,8 @@ run_tests_for_runtime() {
fi

for t in "${script_dir}"/"${runtime}"/test-cases/*/ ; do
# shellcheck disable=SC2155
local start_time_test_case=$(date +%s)
test=$(basename "$(realpath "${t}")")

case "$runtime" in
Expand Down Expand Up @@ -102,6 +116,7 @@ run_tests_for_runtime() {
exit_code=1
summary="$summary\n${runtime}/${base_image}\t- ${test}:\tfailed"
fi
store_build_step_duration "test case $image_name_test/$runtime/$test" "$start_time_test_case"
done
}

Expand Down Expand Up @@ -132,6 +147,8 @@ run_tests_for_architecture() {
echo "- base image: '${base_image}'"
image_name_test="test-${runtime}-${arch}:latest"
echo "building test image for ${arch}/${runtime}/${base_image} with instrumentation image ${instrumentation_image}"
# shellcheck disable=SC2155
local start_time_docker_build=$(date +%s)
if ! build_output=$(
docker build \
--platform "$docker_platform" \
Expand All @@ -144,6 +161,7 @@ run_tests_for_architecture() {
echo "${build_output}"
exit 1
fi
store_build_step_duration "docker build $arch/$runtime/$base_image" "$start_time_docker_build"
run_tests_for_runtime "${runtime}" "$image_name_test" "$base_image"
echo
done
Expand Down

0 comments on commit e8854ac

Please sign in to comment.