Skip to content

Commit 7124b21

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Add total timings"
2 parents 06be15a + 908a3a9 commit 7124b21

1 file changed

Lines changed: 38 additions & 16 deletions

File tree

functions-common

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2322,20 +2322,21 @@ function sudo_with_proxies {
23222322
# Resolution is only in whole seconds, so should be used for long
23232323
# running activities.
23242324

2325-
declare -A TOTAL_TIME
2326-
declare -A START_TIME
2325+
declare -A _TIME_TOTAL
2326+
declare -A _TIME_START
2327+
declare -r _TIME_BEGIN=$(date +%s)
23272328

23282329
# time_start $name
23292330
#
23302331
# starts the clock for a timer by name. Errors if that clock is
23312332
# already started.
23322333
function time_start {
23332334
local name=$1
2334-
local start_time=${START_TIME[$name]}
2335+
local start_time=${_TIME_START[$name]}
23352336
if [[ -n "$start_time" ]]; then
23362337
die $LINENO "Trying to start the clock on $name, but it's already been started"
23372338
fi
2338-
START_TIME[$name]=$(date +%s)
2339+
_TIME_START[$name]=$(date +%s)
23392340
}
23402341

23412342
# time_stop $name
@@ -2351,32 +2352,53 @@ function time_stop {
23512352
local start_time
23522353

23532354
name=$1
2354-
start_time=${START_TIME[$name]}
2355+
start_time=${_TIME_START[$name]}
23552356

23562357
if [[ -z "$start_time" ]]; then
23572358
die $LINENO "Trying to stop the clock on $name, but it was never started"
23582359
fi
23592360
end_time=$(date +%s)
23602361
elapsed_time=$(($end_time - $start_time))
2361-
total=${TOTAL_TIME[$name]:-0}
2362+
total=${_TIME_TOTAL[$name]:-0}
23622363
# reset the clock so we can start it in the future
2363-
START_TIME[$name]=""
2364-
TOTAL_TIME[$name]=$(($total + $elapsed_time))
2364+
_TIME_START[$name]=""
2365+
_TIME_TOTAL[$name]=$(($total + $elapsed_time))
23652366
}
23662367

23672368
# time_totals
2368-
#
2369-
# prints out total time
2369+
# Print out total time summary
23702370
function time_totals {
2371+
local elapsed_time
2372+
local end_time
2373+
local len=15
2374+
local xtrace
2375+
2376+
end_time=$(date +%s)
2377+
elapsed_time=$(($end_time - $_TIME_BEGIN))
2378+
2379+
# pad 1st column this far
2380+
for t in ${!_TIME_TOTAL[*]}; do
2381+
if [[ ${#t} -gt $len ]]; then
2382+
len=${#t}
2383+
fi
2384+
done
2385+
2386+
xtrace=$(set +o | grep xtrace)
2387+
set +o xtrace
2388+
23712389
echo
2372-
echo "========================"
2373-
echo "DevStack Components Timed"
2374-
echo "========================"
2390+
echo "========================="
2391+
echo "DevStack Component Timing"
2392+
echo "========================="
2393+
printf "%-${len}s %3d\n" "Total runtime" "$elapsed_time"
23752394
echo
2376-
for t in ${!TOTAL_TIME[*]}; do
2377-
local v=${TOTAL_TIME[$t]}
2378-
echo "$t - $v secs"
2395+
for t in ${!_TIME_TOTAL[*]}; do
2396+
local v=${_TIME_TOTAL[$t]}
2397+
printf "%-${len}s %3d\n" "$t" "$v"
23792398
done
2399+
echo "========================="
2400+
2401+
$xtrace
23802402
}
23812403

23822404
# Restore xtrace

0 commit comments

Comments
 (0)