Alex Savatieiev | ec70369 | 2019-06-07 15:33:31 -0500 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | |
| 3 | function help_and_exit { |
| 4 | echo "simple_profile.sh <repeat_count>" |
| 5 | exit 1 |
| 6 | } |
| 7 | |
| 8 | #if [ -z ${1+x} ]; then echo "First parameter should be total count of the requests"; help_and_exit; fi |
| 9 | count=1 |
| 10 | declare all_req=() |
| 11 | declare errors=() |
| 12 | tmp_time=$(mktemp) |
| 13 | tmp_out=$(mktemp) |
| 14 | |
| 15 | function profiled_run { |
| 16 | if [ -z ${2+x} ]; then |
| 17 | /usr/bin/time --quiet -f'%e %x' -o ${tmp_time} ${1} 1>/dev/null 2>${tmp_out} |
| 18 | real=$(cat ${tmp_time} | awk '{print $1}') |
| 19 | errlevel=$(cat ${tmp_time} | awk '{print $2}') |
| 20 | if [ 0 -eq ${errlevel} ]; then |
| 21 | echo "#${count}(${real}s), '${1}'"; |
| 22 | all_req+=("#${count}, ${real}, '${1}'"); |
| 23 | else |
| 24 | echo "#${count}, ERROR(${errlevel}): '${1}'" |
| 25 | errors+=("#${count}: $(cat ${tmp_out})") |
| 26 | fi |
| 27 | ((count++)) |
| 28 | else |
| 29 | echo "### Running '${1}' ${2} times" |
| 30 | for (( idx=1; idx<=${2}; idx++ )) |
| 31 | do |
| 32 | /usr/bin/time --quiet -f'%e %x' -o ${tmp_time} ${1} 1>/dev/null 2>${tmp_out} |
| 33 | real=$(cat ${tmp_time} | awk '{print $1}') |
| 34 | errlevel=$(cat ${tmp_time} | awk '{print $2}') |
| 35 | if [ 0 -eq ${errlevel} ]; then |
| 36 | echo "#${count}/${idx}, ${real}s"; |
| 37 | all_req+=("#${count}/${idx}, ${real}, '${1}'"); |
| 38 | else |
| 39 | echo "#${count}/${idx}, ERROR(${errlevel}): '${1}'" |
| 40 | errors+=("#${count}: $(cat ${tmp_out})") |
| 41 | fi |
| 42 | ((count++)) |
| 43 | done |
| 44 | fi |
| 45 | } |
| 46 | |
| 47 | function errors { |
| 48 | echo "==== Errors" |
| 49 | for i in "${!errors[@]}"; do |
| 50 | printf "#%s\n\n" "${errors[$i]}" |
| 51 | done |
| 52 | } |
| 53 | |
| 54 | function stats { |
| 55 | echo "==== Stats" |
| 56 | printf '%s\n' "${all_req[@]}" | awk 'BEGIN{min=999;avg=0} |
| 57 | {if($2<min){min=$2;}if($2>max){max=$2;}avg+=$2;} |
| 58 | END { print "Total requests: "NR", Timings: "min" <-- "avg/NR" --> "max;}' |
| 59 | } |
| 60 | |
| 61 | function clean { |
| 62 | rm ${tmp_time} |
| 63 | rm ${tmp_out} |
| 64 | } |
| 65 | |
| 66 | echo "===== Totals" |
| 67 | echo "Total projects = $(openstack project list -f value -c ID | wc -l)" |
| 68 | echo "Total networks = $(openstack network list -f value -c ID | wc -l)" |
| 69 | echo "Total subnets = $(openstack subnet list -f value -c ID | wc -l)" |
| 70 | echo "Total ports = $(openstack port list -f value -c ID | wc -l)" |
| 71 | echo "Total servers = $(openstack server list --all-projects --limit -1 -f value -c ID | wc -l)" |
| 72 | echo "Total images = $(openstack image list -f value -c ID | wc -l)" |
| 73 | echo "===== Timings" |
| 74 | openstack --timing project list |
| 75 | openstack --timing network list |
| 76 | openstack --timing subnet list |
| 77 | openstack --timing port list |
| 78 | openstack --timing server list |
| 79 | openstack --timing image list |
| 80 | |
| 81 | echo "********" |
| 82 | profiled_run "openstack network list" 10 |
| 83 | stats |
| 84 | declare all_req=() |
| 85 | echo "********" |
| 86 | profiled_run "openstack project list" 10 |
| 87 | stats |
| 88 | declare all_req=() |
| 89 | echo "********" |
| 90 | profiled_run "openstack server list --limit -1" 10 |
| 91 | stats |
| 92 | declare all_req=() |
| 93 | profiled_run "heat stack-list" 10 |
| 94 | stats |
| 95 | declare all_req=() |
| 96 | echo "********" |
| 97 | profiled_run "heat resource-type-list" 10 |
| 98 | stats |
| 99 | declare all_req=() |
| 100 | echo "********" |
| 101 | profiled_run "nova list --limit -1" 10 |
| 102 | stats |
| 103 | declare all_req=() |
| 104 | echo "********" |
| 105 | profiled_run "glance image-list" 10 |
| 106 | echo "====================================" |
| 107 | errors |
| 108 | clean |