diff options
author | Julien Duraj <julien.duraj@linaro.org> | 2016-08-24 17:13:18 +0100 |
---|---|---|
committer | Julien Duraj <julien.duraj@linaro.org> | 2016-09-14 13:13:12 +0100 |
commit | 7afb6be24276ef8d24fa14afad0cb701b7c61ff3 (patch) | |
tree | 16bca790868aec8855f8de6151eb8545b84cefa8 | |
parent | c591c7d28bd1fd0ca8f12fe3d8a988916e504b98 (diff) | |
download | art-build-scripts-7afb6be24276ef8d24fa14afad0cb701b7c61ff3.tar.gz |
Add new script for boot.oat measurements (host)
This script include time measurements (time it takes for a successful
compilation of boot.oat image)
total size and metadata measurements
Change-Id: Ida548affb166dc843780177735605fb0e7c1f480
-rwxr-xr-x | benchmarks/boot_oat_measurements_host.sh | 241 |
1 files changed, 241 insertions, 0 deletions
diff --git a/benchmarks/boot_oat_measurements_host.sh b/benchmarks/boot_oat_measurements_host.sh new file mode 100755 index 00000000..a82f91fa --- /dev/null +++ b/benchmarks/boot_oat_measurements_host.sh @@ -0,0 +1,241 @@ +#!/bin/bash + +readonly local_path=$(dirname "$0") +source "${local_path}/../utils/utils.sh" +source "${local_path}/../utils/utils_android.sh" + +instruction_sets=("arm" "arm64" "x86" "x86_64" "mips" "mips64") +declare -A options +readonly default_iterations=5 +readonly log_directory="$(get_workspace)" +readonly image_build_log="build_boot_image.txt" +readonly boot_size_measurements_file="boot_size_measurements.csv" +readonly boot_time_measurements_file="boot_time_measurements.csv" +readonly metadata_fields="^(\.rodata |\.text |\.gnu_debugdata |Total )" +build_status=0 +exit_code=0 + +init_options() { + options["iterations"]=$default_iterations + options["instruction_set"]="all" +} + +validate_options() { + local -r iterations="${options["iterations"]}" + if [[ ! ${iterations} =~ ^[0-9]+$ ]]; then + log E "Invalid number of iterations: ${iterations}" + exit 1 + fi + + local -r instruction_set="${options["instruction_set"]}" + if [[ "${instruction_set}" == "all" ]]; then + return + fi + local is + for is in "${instruction_sets[@]}"; do + [[ ${is} == "${instruction_set}" ]] && break + done + if [[ ${is} == "${instruction_set}" ]]; then + instruction_sets=(${instruction_set}) + else + log E "Invalid instruction_set" + exit 1 + fi +} + +usage() { + log I "$0" + log I "Take time, size, and metadata size measurements for boot.oat images" + log I "on host." + log I "Runs the provided number of iterations for each architecture." + log I " -h|--help - help" + log I " -v|--verbose - verbose" + log I "-------------------------------------------" + log I " --instruction-set <${instruction_sets[*]}>" + log I " - Can be used to run measurements for the" + log I " specified instruction set." + log I " (default: all)" + log I " --iterations <n> - The number of times we compile boot.oat" + log I " for each architecture." + log I " (default: ${default_iterations})" + log I "-------------------------------------------" +} + +arguments_parser() { + init_options + while [[ $# -gt 0 ]]; do + case "$1" in + -v|--verbose) + enable_verbose + ;; + -h|--help) + usage + exit 0 + ;; + --instruction-set) + shift + options["instruction_set"]=$1 + ;; + --iterations) + shift + options["iterations"]=$1 + ;; + *) + log E "Invalid option: $1" + exit 1 + ;; + esac + shift + done + readonly options + validate_options +} + +init_and_build() { + # Remove old files used by automation + rm -f "${log_directory}/${boot_size_measurements_file}" \ + "${log_directory}/${boot_time_measurements_file}" + + setup_android_target aosp_arm-eng + safe_make_build "" "" "dump-oat-boot" "dex2oat" +} + +dex2oat_optargs() { + local instruction_set="$1" + grep -m 1 "dex2oat-cmdline" "${log_directory}/out/boot.arm.oatdump.txt" | + sed "s/dex2oat-cmdline = //" | + sed -E "s/--instruction-set=[[:alnum:]]+/--instruction-set=${instruction_set}/" +} + +get_image_location() { + grep -m 1 "dex2oat-cmdline" "${log_directory}/out/boot.arm.oatdump.txt" | + sed "s/.*--oat-file=//" | + sed "s/ .*//" +} + +dex2oat_cmdline() { + local instruction_set="$1" + echo "dex2oat -j1 $(dex2oat_optargs "${instruction_set}")" +} + +get_build_time() { + local instruction_set="$1" + # shellcheck disable=SC2091 + $(dex2oat_cmdline "${instruction_set}") > "${image_build_log}" 2>&1 + if [[ "$?" -ne 0 ]]; then + echo 0 + return + fi + grep -i "dex2oat took" "${image_build_log}" | + sed "s/.*took //g" | + sed "s/s.*$//g" +} + +get_build_time_csv() { + local instruction_set="$1" + local iterations="$2" + local dex2oat_time=0 + local dex2oat_time_csv= + + local i + for ((i = 0; i < iterations; i++)); do + current_oat_time=$(get_build_time "${instruction_set}") + dex2oat_time_csv+="${current_oat_time}," + dex2oat_time=$(echo "${dex2oat_time} + ${current_oat_time}" | bc) + done + + echo "${dex2oat_time_csv/%,/}" +} + +get_csv_average() { + local csv="$1" + local count_values_in_csv + + sum=$(echo "${csv//,/+}" | bc) + # shellcheck disable=SC2126 + count_values_in_csv="$(($(echo "${csv}" | grep -o "," | wc -l) + 1))" + + echo "scale=8; ${sum} / ${count_values_in_csv}" | bc -l +} + +get_size_boot_oat() { + stat -c '%s' "$(get_image_location)" +} + +get_metadata_size_boot_oat() { + size -A -d "$(get_image_location)" +} + +get_metadata_column_csv() { + get_metadata_size_boot_oat | + tail -n+3 | + grep -E "${metadata_fields}" | + awk "{print \$$1}" | + tr '\n' ',' | + sed 's/,$/\n/' +} + +get_metadata_size_boot_oat_csv_header() { + get_metadata_column_csv 1 +} + +get_metadata_size_boot_oat_csv_values() { + get_metadata_column_csv 2 +} + +log_all_boot_oat_measurements() { + local instruction_set="$1" + local iterations="$2" + local dex2oat_time_csv + local boot_oat_size + local csv + local csv_header + local time_csv_header + + build_status=0 + + dex2oat_time_csv=$(get_build_time_csv "${instruction_set}" "${iterations}") + boot_oat_size=$(get_size_boot_oat) + + [[ $(get_csv_average "${dex2oat_time_csv}") == "0" ]] && build_status=1 && exit_code=1 + + if [[ ! -f ${boot_size_measurements_file} ]]; then + csv_header="InstructionSet,FileSize,$(get_metadata_size_boot_oat_csv_header)" + echo "${csv_header}" >> "${boot_size_measurements_file}" + time_csv_header="InstructionSet,Time(s)" + echo "${time_csv_header}" >> "${boot_time_measurements_file}" + fi + + echo "${instruction_set},${dex2oat_time_csv}" >> "${boot_time_measurements_file}" + + csv="${instruction_set},${boot_oat_size},$(get_metadata_size_boot_oat_csv_values)" + echo "${csv}" >> "${boot_size_measurements_file}" +} + +get_average_dex2oat_column() { + echo "TimeAvg" + tail -n+2 "${boot_time_measurements_file}" | cut -d "," -f2- | + while read line; do + get_csv_average "${line}" + done +} + +output_results() { + paste -d "," "${boot_size_measurements_file}" <(get_average_dex2oat_column) | + column -s "," -t +} + +main() { + arguments_parser "$@" + init_and_build + for instruction_set in "${instruction_sets[@]}"; do + start_section "measure_boot_oat_${instruction_set}" + log_all_boot_oat_measurements "${instruction_set}" "${options["iterations"]}" + end_section "measure_boot_oat_${instruction_set}" "${build_status}" + done + log S "Time summary:\n${TESTS_SUMMARY}" + output_results + return ${exit_code} +} + +main "$@" |