summaryrefslogtreecommitdiff
path: root/scripts/benchmark/run-benchmarks-ci-job.sh
blob: 835f8c7f814e4b2c1f9e2df9ead499e14c67f52b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/sh

# Run benchmakr tests for CI jobs, and optionally compare results with historic
# series.
#
# Usage Example
# -------------
#
# Run this script with the environment name as the only argument:
#
#   ./run-benchmarks-ci-job.sh environment-name
#
# This script is used in .gitlab-ci.yml to run benchmark jobs. It has been
# factored out from that file to avoid bloating it with too much information.
#
# Environment Variables
# ---------------------
#
#   RUN_BENCHMARKS:     If not set, skip this run.
#   CHECK_FOR_OUTLIERS: If set, check if results are outliers.

set -eu
set -o xtrace

ENVIRONMENT=${1}
RUN_BENCHMARKS=${RUN_BENCHMARKS:-}

if [ -z "${RUN_BENCHMARKS}" ]; then
  echo "Skipping benchmarks because RUN_BENCHMARKS is not set..."
  exit 0
fi

echo "Running tox in environment ${ENVIRONMENT}..."

#
# run benchmark tests with tox
#

tempfile=$(mktemp)
/usr/bin/unbuffer \
  tox \
    --recreate \
    -e ${ENVIRONMENT} \
    -- \
    --couch-url http://couchdb:5984 \
    --benchmark-json=${tempfile} \
    -m runme \
  | /usr/bin/ts -s

#
# check results for bad outlier detecion
#

# stop here unless environment starts with "benchmark-"
if [ -z "$(echo ${ENVIRONMENT} | grep ^benchmark-)" ]; then
  exit 0
fi

# stop here unless the CHECK_FOR_OUTLIERS environment variable is set
if [ -z "${CHECK_FOR_OUTLIERS:-}" ]; then
  exit 0
fi

# fail test for bad outliers
echo "Comparing current test results with history..."
basedir=$(dirname "${0}")
${basedir}/compare-results-with-history.py ${tempfile}