diff --git a/modules/debug/functions/trace-zim b/modules/debug/functions/trace-zim index 949b627..67f9dc2 100644 --- a/modules/debug/functions/trace-zim +++ b/modules/debug/functions/trace-zim @@ -3,16 +3,12 @@ # Generates trace log to debug zim and zsh issues # -cat >&2 < /tmp/ztrace/sysinfo -print $(zsh --version) >> /tmp/ztrace/sysinfo -print "\nkernel information:" >> /tmp/ztrace/sysinfo -print $(uname -mosr) >> /tmp/ztrace/sysinfo -print "\n$fpath info:" >> /tmp/ztrace/sysinfo -print -l ${fpath} >> /tmp/ztrace/sysinfo +print "Zsh version: + $(zsh --version) +Kernel information: + $(uname -mosr) +fpath info: + ${fpath}" >! /tmp/ztrace/sysinfo cp ${ZDOTDIR:-${HOME}}/.zshrc /tmp/ztrace/.zshrc.orig cp ${ZDOTDIR:-${HOME}}/.zimrc /tmp/ztrace/.zimrc # rsync will allow us to not have to copy the .git folder; use if available -if (( $+commands[rsync] )); then - rsync -az --exclude .git "${ZDOTDIR:-$HOME}/.zim" "/tmp/ztrace/" +if (( ${+commands[rsync]} )); then + rsync -az --exclude .git ${ZDOTDIR:-${HOME}}/.zim /tmp/ztrace/ else - cp -R "${ZDOTDIR:-$HOME}/.zim" "/tmp/ztrace/" + cp -R ${ZDOTDIR:-${HOME}}/.zim /tmp/ztrace/ fi # trace code to add to modified .zshrc -if [[ "$OSTYPE" == linux-gnu ]]; then +if [[ ${OSTYPE} == linux-gnu ]]; then read -d '' tracetop << EOF || true -####################### +################### # zim trace start # -####################### +################### exec 3>&2 2> >(tee /tmp/ztrace/sample-time.\$\$.log | sed -u 's/^.*$/now/' | date -f - +%s.%N >/tmp/ztrace/sample-time.\$\$.tim) @@ -67,12 +63,12 @@ EOF # we need gnu-utils to do this, so we must check for darwin/bsd. # if these platforms, we need to call gsed and gdate explicitly. -elif [[ "$OSTYPE" == (darwin*|*bsd*) ]]; then - if (( $+commands[gdate] && $+commands[gsed] )); then +elif [[ ${OSTYPE} == (darwin*|*bsd*) ]]; then + if (( ${+commands[gdate]} && ${+commands[gsed]} )); then read -d '' tracetop << EOF || true -####################### +################### # zim trace start # -####################### +################### exec 3>&2 2> >(tee /tmp/ztrace/sample-time.\$\$.log | gsed -u 's/^.*$/now/' | gdate -f - +%s.%N >/tmp/ztrace/sample-time.\$\$.tim) @@ -80,23 +76,23 @@ zmodload zsh/zprof set -x EOF else - print "debug module requires both gnu-sed (gsed) and gnu-date (gdate)." - print "please install these with brew before attempting to trace." + print "debug module requires both gnu-sed (gsed) and gnu-date (gdate). +Please install these with brew before attempting to trace." return 1 fi else - print "your system, ${OSTYPE}, is an unknown system." - print "please create an issue at:" - print "\thttps://github.com/Eriner/zim/issues" - print "Please paste the following output in your report:" - print "\t${OSTYPE} - $(uname -mosr)" + print "your system, ${OSTYPE}, is an unknown system. +Please create an issue at: + https://github.com/Eriner/zim/issues +Include the following output in your report: + ${OSTYPE} - $(uname -mosr)" return 1 fi read -d '' tracebot << EOF || true -##################### +################# # zim trace end # -##################### +################# set +x zprof >! /tmp/ztrace/zprof @@ -109,20 +105,18 @@ EOF # create a modified .zshrc to produce a trace log origzshrc=$(! "/tmp/ztrace/.zshrc" +print "${tracetop}\n${origzshrc}\n${tracebot}" >! /tmp/ztrace/.zshrc # clean up the vars now that we are done with them. -unset origzshrc -unset tracetop -unset tracebot +unset origzshrc tracetop tracebot print "\nSpawning zsh and producing trace...\n\n" ZDOTDIR=/tmp/ztrace zsh -ic 'exit' -print "Trace complete.\n" -print "Parsing logs to a nicer format; this may take some time..." +print "Trace complete. +Parsing logs to a nicer format; this may take some time..." # this is ugly thing makes it pretty... -paste <( while read tim; do crt=000000000$((${tim//.}-10#0$last)); printf "%12.9f\n" ${crt:0:${#crt}-9}.${crt:${#crt}-9}; last=${tim//.}; done < /tmp/ztrace/sample-time.(*).tim; ) /tmp/ztrace/sample-time.(*).log > "/tmp/ztrace/ztrace.log" +paste <( while read tim; do crt=000000000$((${tim//.}-10#0$last)); printf "%12.9f\n" ${crt:0:${#crt}-9}.${crt:${#crt}-9}; last=${tim//.}; done < /tmp/ztrace/sample-time.(*).tim; ) /tmp/ztrace/sample-time.(*).log > /tmp/ztrace/ztrace.log print "Parsing complete!" # safe to remove old, unneeded environment files @@ -132,16 +126,15 @@ rm -rf /tmp/ztrace/.zim rm -f /tmp/ztrace/.zshrc mv /tmp/ztrace/.zshrc.orig /tmp/ztrace/.zshrc rm -f /tmp/ztrace/.zhistory -rm -f /tmp/ztrace/.zcompdump.zwc +rm -f /tmp/ztrace/.zcompdump* print "Archiving trace logs...\n" -tar -cf "/tmp/ztrace.tar.gz" "/tmp/ztrace/" +tar -cf /tmp/ztrace.tar.gz /tmp/ztrace/ -print "Archive complete!\n" - -print "\nTrace by with execution time available at:" -print "\t/tmp/ztrace/ztrace.log" -print "\nArchive (for sharing/help) available at:" -print "\t/tmp/ztrace.tar.gz" +print "Archive complete!\n +Trace by with execution time available at: + /tmp/ztrace/ztrace.log +Archive (for sharing/help) available at: + /tmp/ztrace.tar.gz"