blob: c097ae9258887b91e8cbda766cafe3a213c6fa60 [file] [log] [blame]
Alex Savatieievec703692019-06-07 15:33:31 -05001#!/bin/bash
2
3function 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
9count=1
10declare all_req=()
11declare errors=()
12tmp_time=$(mktemp)
13tmp_out=$(mktemp)
14
15function 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
47function errors {
48 echo "==== Errors"
49 for i in "${!errors[@]}"; do
50 printf "#%s\n\n" "${errors[$i]}"
51 done
52}
53
54function 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
61function clean {
62 rm ${tmp_time}
63 rm ${tmp_out}
64}
65
66echo "===== Totals"
67echo "Total projects = $(openstack project list -f value -c ID | wc -l)"
68echo "Total networks = $(openstack network list -f value -c ID | wc -l)"
69echo "Total subnets = $(openstack subnet list -f value -c ID | wc -l)"
70echo "Total ports = $(openstack port list -f value -c ID | wc -l)"
71echo "Total servers = $(openstack server list --all-projects --limit -1 -f value -c ID | wc -l)"
72echo "Total images = $(openstack image list -f value -c ID | wc -l)"
73echo "===== Timings"
74openstack --timing project list
75openstack --timing network list
76openstack --timing subnet list
77openstack --timing port list
78openstack --timing server list
79openstack --timing image list
80
81echo "********"
82profiled_run "openstack network list" 10
83stats
84declare all_req=()
85echo "********"
86profiled_run "openstack project list" 10
87stats
88declare all_req=()
89echo "********"
90profiled_run "openstack server list --limit -1" 10
91stats
92declare all_req=()
93profiled_run "heat stack-list" 10
94stats
95declare all_req=()
96echo "********"
97profiled_run "heat resource-type-list" 10
98stats
99declare all_req=()
100echo "********"
101profiled_run "nova list --limit -1" 10
102stats
103declare all_req=()
104echo "********"
105profiled_run "glance image-list" 10
106echo "===================================="
107errors
108clean