Skip to content

Commit 418bbdd

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Provide timings for OSC during devstack run"
2 parents b24bfac + 85cf293 commit 418bbdd

2 files changed

Lines changed: 58 additions & 2 deletions

File tree

functions-common

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2502,7 +2502,7 @@ function time_start {
25022502
if [[ -n "$start_time" ]]; then
25032503
die $LINENO "Trying to start the clock on $name, but it's already been started"
25042504
fi
2505-
_TIME_START[$name]=$(date +%s)
2505+
_TIME_START[$name]=$(date +%s%3N)
25062506
}
25072507

25082508
# time_stop $name
@@ -2523,14 +2523,57 @@ function time_stop {
25232523
if [[ -z "$start_time" ]]; then
25242524
die $LINENO "Trying to stop the clock on $name, but it was never started"
25252525
fi
2526-
end_time=$(date +%s)
2526+
end_time=$(date +%s%3N)
25272527
elapsed_time=$(($end_time - $start_time))
25282528
total=${_TIME_TOTAL[$name]:-0}
25292529
# reset the clock so we can start it in the future
25302530
_TIME_START[$name]=""
25312531
_TIME_TOTAL[$name]=$(($total + $elapsed_time))
25322532
}
25332533

2534+
function oscwrap {
2535+
local out
2536+
local rc
2537+
local start
2538+
local end
2539+
# Cannot use timer_start and timer_stop as we run in subshells
2540+
# and those rely on modifying vars in the same process (which cannot
2541+
# happen from a subshell.
2542+
start=$(date +%s%3N)
2543+
out=$(command openstack "$@")
2544+
rc=$?
2545+
end=$(date +%s%3N)
2546+
echo $((end - start)) >> $OSCWRAP_TIMER_FILE
2547+
2548+
echo "$out"
2549+
return $rc
2550+
}
2551+
2552+
function install_oscwrap {
2553+
# File to accumulate our timing data
2554+
OSCWRAP_TIMER_FILE=$(mktemp)
2555+
# Bash by default doesn't expand aliases, allow it for the aliases
2556+
# we want to whitelist.
2557+
shopt -s expand_aliases
2558+
# Remove all aliases that might be expanded to preserve old unexpanded
2559+
# behavior
2560+
unalias -a
2561+
# Add only the alias we want for openstack
2562+
alias openstack=oscwrap
2563+
}
2564+
2565+
function cleanup_oscwrap {
2566+
local total=0
2567+
if python3_enabled ; then
2568+
local python=python3
2569+
else
2570+
local python=python
2571+
fi
2572+
total=$(cat $OSCWRAP_TIMER_FILE | $python -c "import sys; print(sum(int(l) for l in sys.stdin))")
2573+
_TIME_TOTAL["osc"]=$total
2574+
rm $OSCWRAP_TIMER_FILE
2575+
}
2576+
25342577
# time_totals
25352578
# Print out total time summary
25362579
function time_totals {
@@ -2549,6 +2592,8 @@ function time_totals {
25492592
fi
25502593
done
25512594

2595+
cleanup_oscwrap
2596+
25522597
xtrace=$(set +o | grep xtrace)
25532598
set +o xtrace
25542599

@@ -2560,6 +2605,8 @@ function time_totals {
25602605
echo
25612606
for t in ${!_TIME_TOTAL[*]}; do
25622607
local v=${_TIME_TOTAL[$t]}
2608+
# because we're recording in milliseconds
2609+
v=$(($v / 1000))
25632610
printf "%-${len}s %3d\n" "$t" "$v"
25642611
done
25652612
echo "========================="

stack.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,11 @@ function exit_trap {
524524
kill 2>&1 $jobs
525525
fi
526526

527+
#Remove timing data file
528+
if [ -f "$OSCWRAP_TIMER_FILE" ] ; then
529+
rm "$OSCWRAP_TIMER_FILE"
530+
fi
531+
527532
# Kill the last spinner process
528533
kill_spinner
529534

@@ -939,6 +944,10 @@ else
939944
pip_install_gr python-openstackclient
940945
fi
941946

947+
# Installs alias for osc so that we can collect timing for all
948+
# osc commands. Alias dies with stack.sh.
949+
install_oscwrap
950+
942951
if [[ $TRACK_DEPENDS = True ]]; then
943952
$DEST/.venv/bin/pip freeze > $DEST/requires-post-pip
944953
if ! diff -Nru $DEST/requires-pre-pip $DEST/requires-post-pip > $DEST/requires.diff; then

0 commit comments

Comments
 (0)