From 99f624011b3ae0e6088ffcb86dc414e3750ad5c9 Mon Sep 17 00:00:00 2001 From: Christopher Vogt Date: Tue, 26 Apr 2016 10:57:09 -0400 Subject: compute logged times during startup as delta from beginning --- cbt | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'cbt') diff --git a/cbt b/cbt index 867276a..a893dff 100755 --- a/cbt +++ b/cbt @@ -8,6 +8,19 @@ # - reduction of dependencies # - performance improvements +start_seconds=$(gdate +"%s") +start_nanos=1$(gdate +"%N") + +time_taken() { + i=$(( $(gdate +"%s") - start_seconds )) + n=$(( $(( 1$(gdate +"%N") - start_nanos )) / 1000000 )) + if [[ ( "$n" < 0 ) ]]; then + i=$(( i-1 )) + n=$(( n+1000 )) + fi + echo "$i.$n" +} + # utility function to log message to stderr with stating the time log () { msg=$1 @@ -23,8 +36,8 @@ log () { which gdate 2>&1 > /dev/null gdate_installed=$? if [ $gdate_installed -eq 0 ]; then - i=`gdate +"%S.%N"` - echo "[$i] $msg" 1>&2 + delta=$(time_taken) + echo "[$delta] $msg" 1>&2 fi fi } -- cgit v1.2.3