Skip to content

Instantly share code, notes, and snippets.

@lexszero
Last active January 21, 2016 04:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lexszero/03b959b70ba31b3441d7 to your computer and use it in GitHub Desktop.
Save lexszero/03b959b70ba31b3441d7 to your computer and use it in GitHub Desktop.
bash_dbg.sh
#!/bin/bash
file_log=`mktemp`
file_tim=`mktemp`
cleanup_tracing_files() {
rm -f $file_log $file_tim
unset file_log file_tim crt last
}
trap cleanup_tracing_files EXIT
exec 3>&2 2> >(
tee $file_log |
sed -u 's/^.*$/now/' |
date -f - +%s.%N >$file_tim
)
set -x
#source "$@"
bash -x "$@"
set +x
exec 2>&3 3>&-
paste <(
last=0
while read tim ;do
[[ -z "$first" ]] && first=${tim//.}
crt=000000000$((${tim//.}-10#0$last))
printf "%12.9f\n" ${crt:0:${#crt}-9}.${crt:${#crt}-9}
last=${tim//.}
done < $file_tim
crt=000000000$(($last-10#0$first))
echo
printf "Total: %12.9f\n" ${crt:0:${#crt}-9}.${crt:${#crt}-9}
) $file_log
cleanup_tracing_files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment