| ... | ... |
@@ -2502,7 +2502,7 @@ function time_start {
|
| 2502 | 2502 |
if [[ -n "$start_time" ]]; then |
| 2503 | 2503 |
die $LINENO "Trying to start the clock on $name, but it's already been started" |
| 2504 | 2504 |
fi |
| 2505 |
- _TIME_START[$name]=$(date +%s) |
|
| 2505 |
+ _TIME_START[$name]=$(date +%s%3N) |
|
| 2506 | 2506 |
} |
| 2507 | 2507 |
|
| 2508 | 2508 |
# time_stop $name |
| ... | ... |
@@ -2523,7 +2523,7 @@ function time_stop {
|
| 2523 | 2523 |
if [[ -z "$start_time" ]]; then |
| 2524 | 2524 |
die $LINENO "Trying to stop the clock on $name, but it was never started" |
| 2525 | 2525 |
fi |
| 2526 |
- end_time=$(date +%s) |
|
| 2526 |
+ end_time=$(date +%s%3N) |
|
| 2527 | 2527 |
elapsed_time=$(($end_time - $start_time)) |
| 2528 | 2528 |
total=${_TIME_TOTAL[$name]:-0}
|
| 2529 | 2529 |
# reset the clock so we can start it in the future |
| ... | ... |
@@ -2531,6 +2531,49 @@ function time_stop {
|
| 2531 | 2531 |
_TIME_TOTAL[$name]=$(($total + $elapsed_time)) |
| 2532 | 2532 |
} |
| 2533 | 2533 |
|
| 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 |
+ |
|
| 2534 | 2577 |
# time_totals |
| 2535 | 2578 |
# Print out total time summary |
| 2536 | 2579 |
function time_totals {
|
| ... | ... |
@@ -2549,6 +2592,8 @@ function time_totals {
|
| 2549 | 2549 |
fi |
| 2550 | 2550 |
done |
| 2551 | 2551 |
|
| 2552 |
+ cleanup_oscwrap |
|
| 2553 |
+ |
|
| 2552 | 2554 |
xtrace=$(set +o | grep xtrace) |
| 2553 | 2555 |
set +o xtrace |
| 2554 | 2556 |
|
| ... | ... |
@@ -2560,6 +2605,8 @@ function time_totals {
|
| 2560 | 2560 |
echo |
| 2561 | 2561 |
for t in ${!_TIME_TOTAL[*]}; do
|
| 2562 | 2562 |
local v=${_TIME_TOTAL[$t]}
|
| 2563 |
+ # because we're recording in milliseconds |
|
| 2564 |
+ v=$(($v / 1000)) |
|
| 2563 | 2565 |
printf "%-${len}s %3d\n" "$t" "$v"
|
| 2564 | 2566 |
done |
| 2565 | 2567 |
echo "=========================" |
| ... | ... |
@@ -524,6 +524,11 @@ function exit_trap {
|
| 524 | 524 |
kill 2>&1 $jobs |
| 525 | 525 |
fi |
| 526 | 526 |
|
| 527 |
+ #Remove timing data file |
|
| 528 |
+ if [ -f "$OSCWRAP_TIMER_FILE" ] ; then |
|
| 529 |
+ rm "$OSCWRAP_TIMER_FILE" |
|
| 530 |
+ fi |
|
| 531 |
+ |
|
| 527 | 532 |
# Kill the last spinner process |
| 528 | 533 |
kill_spinner |
| 529 | 534 |
|
| ... | ... |
@@ -939,6 +944,10 @@ else |
| 939 | 939 |
pip_install_gr python-openstackclient |
| 940 | 940 |
fi |
| 941 | 941 |
|
| 942 |
+# Installs alias for osc so that we can collect timing for all |
|
| 943 |
+# osc commands. Alias dies with stack.sh. |
|
| 944 |
+install_oscwrap |
|
| 945 |
+ |
|
| 942 | 946 |
if [[ $TRACK_DEPENDS = True ]]; then |
| 943 | 947 |
$DEST/.venv/bin/pip freeze > $DEST/requires-post-pip |
| 944 | 948 |
if ! diff -Nru $DEST/requires-pre-pip $DEST/requires-post-pip > $DEST/requires.diff; then |