Add elapsed time function 74/74474/3
authorSam Hague <shague@redhat.com>
Wed, 25 Jul 2018 18:42:15 +0000 (14:42 -0400)
committerSam Hague <shague@redhat.com>
Wed, 25 Jul 2018 19:20:00 +0000 (15:20 -0400)
Change-Id: I3b5c59bcd2a1ffe38cc9e70356d0b4fc6f6ace68
Signed-off-by: Sam Hague <shague@redhat.com>
jjb/integration/common-functions.sh
jjb/integration/integration-deploy-openstack-run-test.sh

index 20e541c60e3ac5dac2bfc4b7c8d10006be694694..9bb051d494d99a534f69a67d309aa6d287c668de 100644 (file)
@@ -152,6 +152,31 @@ function run_plan() {
     printf "Finished running ${type} plans\n"
 } # function run_plan()
 
+# Return elapsed time. Usage:
+# - Call first time with no arguments and a new timer is returned.
+# - Next call with the first argument as the timer and the elapsed time is returned.
+function timer()
+{
+    if [ $# -eq 0 ]; then
+        # return the current time
+        printf "$(date "+%s")"
+    else
+        local start_time=$1
+        end_time=$(date "+%s")
+
+        if [ -z "$start_time" ]; then
+            start_time=$end_time;
+        fi
+
+        delta_time=$((end_time - start_time))
+        ds=$((delta_time % 60))
+        dm=$(((delta_time / 60) % 60))
+        dh=$((delta_time / 3600))
+        # return the elapsed time
+        printf "%d:%02d:%02d" $dh $dm $ds
+    fi
+}
+
 # convert commas in csv strings to spaces (ssv)
 function csv2ssv() {
     local csv=$1
index 8556e8027114f912a32e20dc36b176299a440530..0ae985307971ca50747debeceaf33ad9ab3fa32c 100644 (file)
@@ -5,7 +5,7 @@
 # shellcheck source=${ROBOT_VENV}/bin/activate disable=SC1091
 source ${ROBOT_VENV}/bin/activate
 source /tmp/common-functions.sh ${BUNDLEFOLDER}
-
+totaltmr=$(timer)
 # Ensure we fail the job if any steps fail.
 set -ex -o pipefail
 
@@ -1068,6 +1068,9 @@ echo "neutron --version"
 which neutron
 neutron --version
 
+stacktime=$(timer $totaltmr)
+printf "Stacking elapsed time: %s\n" "${stacktime}"
+
 echo "Starting Robot test suites ${SUITES} ..."
 # please add pybot -v arguments on a single line and alphabetized
 suite_num=0
@@ -1144,6 +1147,6 @@ ssh ${ODL_SYSTEM_IP} "ls -altr /tmp/${BUNDLEFOLDER}/data/log/"
 ssh ${ODL_SYSTEM_IP} "du -hs /tmp/${BUNDLEFOLDER}/data/log/*"
 
 echo "Tests Executed"
-
+printf "Total elapsed time: %s, stacking time: %s\n" "$(timer $totaltmr)" "${stacktime}"
 true  # perhaps Jenkins is testing last exit code
 # vim: ts=4 sw=4 sts=4 et ft=sh :