github.com/kata-containers/tests@v0.0.0-20240307153542-772105b56064/metrics/report/grabdata.sh (about) 1 #!/bin/bash 2 # Copyright (c) 2018-2021 Intel Corporation 3 # 4 # SPDX-License-Identifier: Apache-2.0 5 6 # Run a set of the metrics tests to gather data to be used with the report 7 # generator. The general ideal is to have the tests configured to generate 8 # useful, meaninful and repeatable (stable, with minimised variance) results. 9 # If the tests have to be run more or longer to achieve that, then generally 10 # that is fine - this test is not intended to be quick, it is intended to 11 # be repeatable. 12 13 # Note - no 'set -e' in this file - if one of the metrics tests fails 14 # then we wish to continue to try the rest. 15 # Finally at the end, in some situations, we explicitly exit with a 16 # failure code if necessary. 17 18 SCRIPT_DIR=$(dirname "$(readlink -f "$0")") 19 source "${SCRIPT_DIR}/../lib/common.bash" 20 RESULTS_DIR=${SCRIPT_DIR}/../results 21 22 # By default we run all the tests 23 RUN_ALL=1 24 25 help() { 26 usage=$(cat << EOF 27 Usage: $0 [-h] [options] 28 Description: 29 This script gathers a number of metrics for use in the 30 report generation script. Which tests are run can be 31 configured on the commandline. Specifically enabling 32 individual tests will disable the 'all' option, unless 33 'all' is also specified last. 34 Options: 35 -a, Run all tests (default). 36 -d, Run the density tests. 37 -h, Print this help. 38 -s, Run the storage tests. 39 -t, Run the time tests. 40 EOF 41 ) 42 echo "$usage" 43 } 44 45 # Set up the initial state 46 init() { 47 metrics_onetime_init 48 49 local OPTIND 50 while getopts "adhst" opt;do 51 case ${opt} in 52 a) 53 RUN_ALL=1 54 ;; 55 d) 56 RUN_DENSITY=1 57 RUN_ALL= 58 ;; 59 h) 60 help 61 exit 0; 62 ;; 63 s) 64 RUN_STORAGE=1 65 RUN_ALL= 66 ;; 67 t) 68 RUN_TIME=1 69 RUN_ALL= 70 ;; 71 ?) 72 # parse failure 73 help 74 die "Failed to parse arguments" 75 ;; 76 esac 77 done 78 shift $((OPTIND-1)) 79 } 80 81 run_density_ksm() { 82 echo "Running KSM density tests" 83 84 # Run the memory footprint test - the main test that 85 # KSM affects. Run for a sufficient number of containers 86 # (that gives us a fair view of how memory gets shared across 87 # containers), and a large enough timeout for KSM to settle. 88 # If KSM has not settled down by then, just take the measurement. 89 # 'auto' mode should detect when KSM has settled automatically. 90 bash density/memory_usage.sh 20 300 auto 91 92 # Get a measure for the overhead we take from the container memory 93 bash density/memory_usage_inside_container.sh 94 } 95 96 run_density() { 97 echo "Running non-KSM density tests" 98 99 # Run the density tests - no KSM, so no need to wait for settle 100 # Set a token short timeout, and use enough containers to get a 101 # good average measurement. 102 bash density/memory_usage.sh 20 5 103 } 104 105 run_time() { 106 echo "Running time tests" 107 # Run the time tests - take time measures for an ubuntu image, over 108 # 100 'first and only container' launches. 109 # NOTE - whichever container you test here must support a full 'date' 110 # command - busybox based containers (including Alpine) will not work. 111 bash time/launch_times.sh -i public.ecr.aws/ubuntu/ubuntu:latest -n 100 112 } 113 114 run_storage() { 115 echo "Running storage tests" 116 117 bash storage/blogbench.sh 118 } 119 120 121 # Execute metrics scripts 122 run() { 123 pushd "$SCRIPT_DIR/.." 124 125 # If KSM is available on this platform, let's run any tests that are 126 # affected by having KSM on/off first, and then turn it off for the 127 # rest of the tests, as KSM may introduce some extra noise in the 128 # results by stealing CPU time for instance. 129 if [[ -f ${KSM_ENABLE_FILE} ]]; then 130 # No point enabling and disabling KSM if we have nothing to test. 131 if [ -n "$RUN_ALL" ] || [ -n "$RUN_DENSITY" ]; then 132 save_ksm_settings 133 trap restore_ksm_settings EXIT QUIT KILL 134 set_ksm_aggressive 135 136 run_density_ksm 137 138 # And now ensure KSM is turned off for the rest of the tests 139 disable_ksm 140 fi 141 else 142 echo "No KSM control file, skipping KSM tests" 143 fi 144 145 if [ -n "$RUN_ALL" ] || [ -n "$RUN_TIME" ]; then 146 run_time 147 fi 148 149 if [ -n "$RUN_ALL" ] || [ -n "$RUN_DENSITY" ]; then 150 run_density 151 fi 152 153 if [ -n "$RUN_ALL" ] || [ -n "$RUN_STORAGE" ]; then 154 run_storage 155 fi 156 157 popd 158 } 159 160 finish() { 161 echo "Now please create a suitably descriptively named subdirectory in" 162 echo "$RESULTS_DIR and copy the .json results files into it before running" 163 echo "this script again." 164 } 165 166 init "$@" 167 run 168 finish