istio.io/istio@v0.0.0-20240520182934-d79c90f27776/prow/benchtest.sh (about)

     1  #!/bin/bash
     2  
     3  # Copyright Istio Authors
     4  #
     5  # Licensed under the Apache License, Version 2.0 (the "License");
     6  # you may not use this file except in compliance with the License.
     7  # You may obtain a copy of the License at
     8  #
     9  #    http://www.apache.org/licenses/LICENSE-2.0
    10  #
    11  # Unless required by applicable law or agreed to in writing, software
    12  # distributed under the License is distributed on an "AS IS" BASIS,
    13  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  # See the License for the specific language governing permissions and
    15  # limitations under the License.
    16  
    17  WD=$(dirname "$0")
    18  WD=$(cd "$WD"; pwd)
    19  ROOT=$(dirname "$WD")
    20  
    21  # shellcheck source=prow/lib.sh
    22  source "${ROOT}/prow/lib.sh"
    23  setup_and_export_git_sha
    24  
    25  set -eux
    26  
    27  GCS_BENCHMARK_DIR="${GCS_BENCHMARK_DIR:-istio-prow/benchmarks}"
    28  
    29  BENCHMARK_COUNT="${BENCHMARK_COUNT:-5}"
    30  BENCHMARK_CPUS="${BENCHMARK_CPUS:-8}"
    31  
    32  REPORT_JUNIT="${REPORT_JUNIT:-${ARTIFACTS}/junit_benchmarks.xml}"
    33  REPORT_PLAINTEXT="${REPORT_PLAINTEXT:-${ARTIFACTS}/benchmark-log.txt}"
    34  
    35  # Sha we should compare against. Defaults to the PULL_BASE_SHA, which is the last commit on the branch we are on.
    36  # For example, a PR on master will compare to the HEAD of master.
    37  COMPARE_GIT_SHA="${COMPARE_GIT_SHA:-${PULL_BASE_SHA:-${GIT_SHA}}}"
    38  
    39  case "${1}" in
    40    run)
    41      shift
    42      benchmarkjunit "$@" -l "${REPORT_PLAINTEXT}" --output="${REPORT_JUNIT}" \
    43        --test-arg "--benchmem" \
    44        --test-arg "--count=${BENCHMARK_COUNT}" \
    45        --test-arg "--cpu=${BENCHMARK_CPUS}" \
    46        --test-arg "--test.timeout=30m" \
    47        --test-arg "-tags=vtprotobuf"
    48      # Print out the results as well for ease of debugging, so they are in the logs instead of just output
    49      cat "${REPORT_PLAINTEXT}"
    50      ;;
    51    report)
    52      # Upload the reports to a well known path based on git SHA
    53      gsutil cp "${REPORT_JUNIT}" "gs://${GCS_BENCHMARK_DIR}/${GIT_SHA}.xml"
    54      gsutil cp "${REPORT_PLAINTEXT}" "gs://${GCS_BENCHMARK_DIR}/${GIT_SHA}.txt"
    55      ;;
    56    compare)
    57      # Fetch previous results, and compare them.
    58      curl "https://storage.googleapis.com/${GCS_BENCHMARK_DIR}/${COMPARE_GIT_SHA}.txt" > "${ARTIFACTS}/baseline-benchmark-log.txt"
    59      benchstat "${ARTIFACTS}/baseline-benchmark-log.txt" "${REPORT_PLAINTEXT}"
    60      ;;
    61    *)
    62      echo "unknown command, expect report, run, or compare."
    63      ;;
    64  esac