Skip to content

Commit 95c33d5

Browse files
sdagueianw
authored andcommitted
add timing infrastructure to devstack
this adds a timing infrastructure to devstack to account for time taken up by set of operations. The first instance of this is accounting the time taken up by doing apt_get calls. Change-Id: I855ffe9c7a75e9943106af0f70cf715c34ae25c5
1 parent 64be321 commit 95c33d5

2 files changed

Lines changed: 72 additions & 0 deletions

File tree

functions-common

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -976,12 +976,18 @@ function apt_get {
976976
local sudo="sudo"
977977
[[ "$(id -u)" = "0" ]] && sudo="env"
978978

979+
# time all the apt operations
980+
time_start "apt-get"
981+
979982
$xtrace
980983

981984
$sudo DEBIAN_FRONTEND=noninteractive \
982985
http_proxy=${http_proxy:-} https_proxy=${https_proxy:-} \
983986
no_proxy=${no_proxy:-} \
984987
apt-get --option "Dpkg::Options::=--force-confold" --assume-yes "$@"
988+
989+
# stop the clock
990+
time_stop "apt-get"
985991
}
986992

987993
function _parse_package_files {
@@ -2115,6 +2121,70 @@ function test_with_retry {
21152121
fi
21162122
}
21172123

2124+
# Timing infrastructure - figure out where large blocks of time are
2125+
# used in DevStack
2126+
#
2127+
# The timing infrastructure for DevStack is about collecting buckets
2128+
# of time that are spend in some subtask. For instance, that might be
2129+
# 'apt', 'pip', 'osc', even database migrations. We do this by a pair
2130+
# of functions: time_start / time_stop.
2131+
#
2132+
# These take a single parameter: $name - which specifies the name of
2133+
# the bucket to be accounted against. time_totals function spits out
2134+
# the results.
2135+
#
2136+
# Resolution is only in whole seconds, so should be used for long
2137+
# running activities.
2138+
2139+
declare -A TOTAL_TIME
2140+
declare -A START_TIME
2141+
2142+
# time_start $name
2143+
#
2144+
# starts the clock for a timer by name. Errors if that clock is
2145+
# already started.
2146+
function time_start {
2147+
local name=$1
2148+
local start_time=${START_TIME[$name]}
2149+
if [[ -n "$start_time" ]]; then
2150+
die $LINENO "Trying to start the clock on $name, but it's already been started"
2151+
fi
2152+
START_TIME[$name]=$(date +%s)
2153+
}
2154+
2155+
# time_stop $name
2156+
#
2157+
# stops the clock for a timer by name, and accumulate that time in the
2158+
# global counter for that name. Errors if that clock had not
2159+
# previously been started.
2160+
function time_stop {
2161+
local name=$1
2162+
local start_time=${START_TIME[$name]}
2163+
if [[ -z "$start_time" ]]; then
2164+
die $LINENO "Trying to stop the clock on $name, but it was never started"
2165+
fi
2166+
local end_time=$(date +%s)
2167+
local elapsed_time=$(($end_time - $start_time))
2168+
local total=${TOTAL_TIME[$name]:-0}
2169+
# reset the clock so we can start it in the future
2170+
START_TIME[$name]=""
2171+
TOTAL_TIME[$name]=$(($total + $elapsed_time))
2172+
}
2173+
2174+
# time_totals
2175+
#
2176+
# prints out total time
2177+
function time_totals {
2178+
echo
2179+
echo "========================"
2180+
echo "DevStack Components Timed"
2181+
echo "========================"
2182+
echo
2183+
for t in ${!TOTAL_TIME[*]}; do
2184+
local v=${TOTAL_TIME[$t]}
2185+
echo "$t - $v secs"
2186+
done
2187+
}
21182188

21192189
# Restore xtrace
21202190
$XTRACE

stack.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,6 +1366,8 @@ else
13661366
exec 1>&3
13671367
fi
13681368

1369+
# Dump out the time totals
1370+
time_totals
13691371

13701372
# Using the cloud
13711373
# ===============

0 commit comments

Comments
 (0)