github.com/kata-containers/tests@v0.0.0-20240307153542-772105b56064/metrics/storage/blogbench.sh (about)

     1  #!/bin/bash
     2  #
     3  # Copyright (c) 2018-2021 Intel Corporation
     4  #
     5  # SPDX-License-Identifier: Apache-2.0
     6  
     7  # Description of the test:
     8  # This test runs the 'blogbench', and extracts the 'scores' for reads
     9  # and writes
    10  # Note - the scores are *not* normalised for the number of iterations run,
    11  # they are total scores for all iterations (this is the blogbench default output)
    12  
    13  set -e
    14  
    15  # General env
    16  SCRIPT_PATH=$(dirname "$(readlink -f "$0")")
    17  source "${SCRIPT_PATH}/../lib/common.bash"
    18  
    19  TEST_NAME="blogbench"
    20  IMAGE="docker.io/library/local-blogbench:latest"
    21  DOCKERFILE="${SCRIPT_PATH}/blogbench_dockerfile/Dockerfile"
    22  
    23  # Number of iterations for blogbench to run - note, results are not
    24  # scaled to iterations - more iterations results in bigger results
    25  ITERATIONS="${ITERATIONS:-30}"
    26  
    27  # Directory to run the test on
    28  # This is run inside of the container
    29  TESTDIR="${TESTDIR:-/tmp}"
    30  CMD="blogbench -i ${ITERATIONS} -d ${TESTDIR}"
    31  
    32  function main() {
    33  	# Check tools/commands dependencies
    34  	cmds=("awk" "docker")
    35  
    36  	init_env
    37  	check_cmds "${cmds[@]}"
    38  	check_ctr_images "$IMAGE" "$DOCKERFILE"
    39  
    40  	metrics_json_init
    41  
    42  	local output=$(sudo -E ${CTR_EXE} run --rm --runtime=${CTR_RUNTIME} $IMAGE test $CMD)
    43  
    44  	# Save configuration
    45  	metrics_json_start_array
    46  
    47  	local frequency=$(echo "$output" | grep "Frequency" | cut -d "=" -f2 | cut -d ' ' -f2)
    48  	local iterations=$(echo "$output" | grep -w "iterations" | cut -d ' ' -f3)
    49  	local spawing_writers=$(echo "$output" | grep -w "writers" | cut -d ' ' -f2)
    50  	local spawing_rewriters=$(echo "$output" | grep -w "rewriters" | cut -d ' ' -f2)
    51  	local spawing_commenters=$(echo "$output" | grep -w "commenters" | cut -d ' ' -f2)
    52  	local spawing_readers=$(echo "$output" | grep -w "readers" | cut -d ' ' -f2)
    53  
    54  	local json="$(cat << EOF
    55  	{
    56  		"Frequency" : $frequency,
    57  		"Iterations" : $iterations,
    58  		"Number of spawing writers" : $spawing_writers,
    59  		"Number of spawing rewriters" : $spawing_rewriters,
    60  		"Number of spawing commenters" : $spawing_commenters,
    61  		"Number of spawing readers" : $spawing_readers
    62  	}
    63  EOF
    64  )"
    65  	metrics_json_add_array_element "$json"
    66  	metrics_json_end_array "Config"
    67  
    68  	# Save results
    69  	metrics_json_start_array
    70  
    71  	local writes=$(tail -2 <<< "$output" | head -1 | awk '{print $5}')
    72  	local reads=$(tail -1 <<< "$output" | awk '{print $6}')
    73  
    74  	# Obtaining other Blogbench results
    75  	local -r data=$(echo "$output" | tail -n +12 | head -n -3)
    76  	local nb_blogs=$(echo "$data" | awk ' BEGIN {ORS="\t"} {print $1} ' | tr '\t' ',' | sed '$ s/.$//')
    77  	local r_articles=$(echo "$data" | awk ' BEGIN {ORS="\t"} {print $2} ' | tr '\t' ',' | sed '$ s/.$//')
    78  	local w_articles=$(echo "$data" | awk ' BEGIN {ORS="\t"} {print $3} ' | tr '\t' ',' | sed '$ s/.$//')
    79  	local r_pictures=$(echo "$data" | awk ' BEGIN {ORS="\t"} {print $4} ' | tr '\t' ',' | sed '$ s/.$//')
    80  	local w_pictures=$(echo "$data" | awk ' BEGIN {ORS="\t"} {print $5} ' | tr '\t' ',' | sed '$ s/.$//')
    81  	local r_comments=$(echo "$data" | awk ' BEGIN {ORS="\t"} {print $6} ' | tr '\t' ',' | sed '$ s/.$//')
    82  	local w_comments=$(echo "$data" | awk ' BEGIN {ORS="\t"} {print $7} ' | tr '\t' ',' | sed '$ s/.$//')
    83  
    84  	local json="$(cat << EOF
    85  	{
    86  		"write": {
    87  			"Result" : $writes,
    88  			"Units"  : "items"
    89  		},
    90  		"read": {
    91  			"Result" : $reads,
    92  			"Units"  : "items"
    93  		},
    94  		"Nb blogs": {
    95  			"Result" : "$nb_blogs"
    96  		},
    97  		"R articles": {
    98  			"Result" : "$r_articles"
    99  		},
   100  		"W articles": {
   101  			"Result" : "$w_articles"
   102  		},
   103  		"R pictures": {
   104  			"Result" : "$r_pictures"
   105  		},
   106  		"W pictures": {
   107  			"Result" : "$w_pictures"
   108  		},
   109  		"R comments": {
   110  			"Result" : "$r_comments"
   111  		},
   112  		"W comments": {
   113  			"Result" : "$w_comments"
   114  		}
   115  	}
   116  EOF
   117  )"
   118  
   119  	metrics_json_add_array_element "$json"
   120  	metrics_json_end_array "Results"
   121  	metrics_json_save
   122  	clean_env_ctr
   123  }
   124  
   125  main "$@"