Skip to content

Commit

Permalink
test: add build performance step (Azure#4843)
Browse files Browse the repository at this point in the history
Co-authored-by: Zachary Bailey <[email protected]>
  • Loading branch information
zachary-bailey and Zachary Bailey authored Aug 30, 2024
1 parent 5fa5e6f commit 522875b
Show file tree
Hide file tree
Showing 179 changed files with 1,316 additions and 4,033 deletions.
25 changes: 19 additions & 6 deletions .pipelines/templates/.builder-release-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,25 @@ steps:
${CONTAINER_IMAGE} make -f packer.mk test-scan-and-cleanup
condition: always()
displayName: Test, Scan, and Cleanup
- bash: |
SIG_IMAGE_NAME="$(cat vhdbuilder/packer/settings.json | grep "sig_image_name" | awk -F':' '{print $2}' | awk -F'"' '{print $2}')" && \
CAPTURED_SIG_VERSION="$(cat vhdbuilder/packer/settings.json | grep "captured_sig_version" | awk -F':' '{print $2}' | awk -F'"' '{print $2}')" && \
BUILD_PERF_DATA_FILE="vhd-build-performance-data.json" && \
docker run --rm \
-v ${PWD}:/go/src/github.com/Azure/AgentBaker \
-w /go/src/github.com/Azure/AgentBaker \
-e SUBSCRIPTION_ID="${SUBSCRIPTION_ID}" \
-e SIG_IMAGE_NAME=${SIG_IMAGE_NAME} \
-e CAPTURED_SIG_VERSION=${CAPTURED_SIG_VERSION} \
-e GIT_BRANCH=$(Build.SourceBranch) \
-e GIT_VERSION=$(Build.SourceVersion) \
-e BUILD_ID=$(Build.BuildId) \
-e JOB_STATUS=$(Agent.JobStatus) \
-e ARCHITECTURE=${ARCHITECTURE} \
-e BUILD_PERF_DATA_FILE=${BUILD_PERF_DATA_FILE} \
${CONTAINER_IMAGE} make -f packer.mk evaluate-build-performance
condition: always()
displayName: Check Build Performance
- task: Bash@3
inputs:
targetType: 'inline'
Expand Down Expand Up @@ -255,12 +274,6 @@ steps:
artifactName: 'vhd-image-bom-${{ parameters.artifactName }}'
targetPath: 'image-bom.json'
displayName: publish container image list
- task: PublishPipelineArtifact@1
inputs:
artifactName: 'build-performance-data-${{ parameters.artifactName }}'
targetPath: 'vhd-build-performance-data.json'
displayName: Publish Build Performance Data
condition: succeeded()
- task: CopyFiles@2
condition: and(succeeded(), eq(variables.DRY_RUN, 'False'))
inputs:
Expand Down
3 changes: 3 additions & 0 deletions packer.mk
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ scanning-vhd: az-login
test-scan-and-cleanup: az-login
@./vhdbuilder/packer/test-scan-and-cleanup.sh

evaluate-build-performance: az-login
@./vhdbuilder/packer/build-performance/evaluate-build-performance.sh

generate-prefetch-scripts:
ifeq (${MODE},linuxVhdMode)
@echo "${MODE}: Generating prefetch scripts"
Expand Down
67 changes: 14 additions & 53 deletions parts/linux/cloud-init/artifacts/cse_helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,6 @@ installJq() {
fi
}


check_array_size() {
declare -n array_name=$1
local array_size=${#array_name[@]}
Expand All @@ -429,77 +428,39 @@ capture_benchmark() {
local title="$1"
title="${title//[[:space:]]/_}"
title="${title//-/_}"
benchmarks+=($title)
check_array_size benchmarks || { echo "Benchmarks array is empty"; return; }
# use nameref variable to hold the current section's array for later reference
declare -n current_section="${benchmarks[last_index]}"
local is_final_section=${2:-false}

local current_time=$(date +%s)
local end_timestamp=$(date +%H:%M:%S)
if [[ "$is_final_section" == true ]]; then
local start_timestamp=$script_start_timestamp
local start_time=$script_start_stopwatch
else
local start_timestamp=$section_start_timestamp
local start_time=$section_start_stopwatch
fi

# calculate total time elapsed for section
local difference_in_seconds=$((current_time - start_time))
local elapsed_hours=$(($difference_in_seconds/3600))
local elapsed_minutes=$((($difference_in_seconds%3600)/60))
local elapsed_seconds=$(($difference_in_seconds%60))
printf -v total_time_elapsed "%02d:%02d:%02d" $elapsed_hours $elapsed_minutes $elapsed_seconds

# add current section benchmarks to relevant section array
current_section+=($start_timestamp)
current_section+=($end_timestamp)
current_section+=($total_time_elapsed)

unset -n current_section

total_time_elapsed=$(date -d@$((current_time - start_time)) -u +%H:%M:%S)
benchmarks[$title]=${total_time_elapsed}
benchmarks_order+=($title) # use this array to maintain order of benchmarks

# reset timers for next section
section_start_stopwatch=$(date +%s)
section_start_timestamp=$(date +%H:%M:%S)

set -x
}

process_benchmarks() {
set +x
check_array_size benchmarks || { echo "Benchmarks array is empty"; return; }
# use nameref variable to reference overall_script section
declare -n script_stats="${benchmarks[last_index]}"

# create script object from data held in the section array for the overall script
# each section object within the script will later be appended to this script object
script_object=$(jq -n --arg script_name "$(basename $0)" --arg script_start_timestamp "${script_stats[0]}" --arg end_timestamp "${script_stats[1]}" --arg total_time_elapsed "${script_stats[2]}" '{($script_name): {"overall": {"start_time": $script_start_timestamp, "end_time": $end_timestamp, "total_time_elapsed": $total_time_elapsed}}}')

unset script_stats[@]
unset -n script_stats

for ((i=0; i<${#benchmarks[@]} - 1; i+=1)); do

# iterate over the benchmarks array and assign a nameref variable to the current section array in order to operate on the data held within it
declare -n section_name="${benchmarks[i]}"

# create section object and append to script object
section_object=$(jq -n --arg section_name "${benchmarks[i]}" --arg section_start_timestamp "${section_name[0]}" --arg end_timestamp "${section_name[1]}" --arg total_time_elapsed "${section_name[2]}" '{($section_name): {"start_time": $section_start_timestamp, "end_time": $end_timestamp, "total_time_elapsed": $total_time_elapsed}}')

script_object=$(jq -n --argjson script_object "$script_object" --argjson section_object "$section_object" --arg script_name "$(basename $0)" '$script_object | .[$script_name] += $section_object')

unset section_name[@]
unset -n section_name

# create script object, then append each section object to it in the for loop
script_object=$(jq -n --arg script_name "${SCRIPT_NAME}" '{($script_name): {}}')

for ((i=0; i<${#benchmarks_order[@]}; i+=1)); do
section_name=${benchmarks_order[i]}
section_object=$(jq -n --arg section_name "${section_name}" --arg total_time_elapsed "${benchmarks[${section_name}]}" \
'{($section_name): $total_time_elapsed'})
script_object=$(jq -n --argjson script_object "$script_object" --argjson section_object "$section_object" --arg script_name "${SCRIPT_NAME}" \
'$script_object | .[$script_name] += $section_object')
done

echo "Benchmarks:"
echo "$script_object" | jq -C .

jq ". += [$script_object]" ${VHD_BUILD_PERF_DATA} > tmp.json && mv tmp.json ${VHD_BUILD_PERF_DATA}
jq ". += $script_object" ${VHD_BUILD_PERF_DATA} > temp-build-perf-file.json && mv temp-build-perf-file.json ${VHD_BUILD_PERF_DATA}
chmod 755 ${VHD_BUILD_PERF_DATA}
set -x
}

#return proper release metadata for the package based on the os and osVersion
Expand Down
Loading

0 comments on commit 522875b

Please sign in to comment.