-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathzsh_preformance_tracer.sh
More file actions
30 lines (27 loc) · 1.03 KB
/
zsh_preformance_tracer.sh
File metadata and controls
30 lines (27 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
export WEAPON_TRACE_LOG=/tmp/weapon_trace_log.$$
zsh_trace_start() {
echo "starting zsh tracing"
# set the trace prompt to include seconds, nanoseconds, script name and line number
# This is GNU date syntax; by default Macs ship with the BSD date program, which isn't compatible
if [[ $ZSH_VERSION > 4.3.11 ]]; then
zmodload zsh/datetime
setopt promptsubst
export PS4='+$EPOCHREALTIME %N:%i> '
else
export PS4='+$(date "+%s:%N") %N:%i> '
fi
# save file stderr to file descriptor 3 and redirect stderr (including trace
# output) to a file with the script's PID as an extension
exec 3>&2 2>$WEAPON_TRACE_LOG
# set options to turn on tracing and expansion of commands contained in the prompt
setopt xtrace prompt_subst
trap 'setopt xtrace' EXIT
}
zsh_trace_end() {
# turn off tracing
unsetopt xtrace
# restore stderr to the value saved in FD 3
exec 2>&3 3>&-
echo "zsh tracing done. See $WEAPON_TRACE_LOG for details."
trap 'unsetopt xtrace' EXIT
}