Skip to content

Commit af98c76

Browse files
committed
update: zsh performance tracer
1 parent f0e5ccd commit af98c76

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

zsh_preformance_tracer.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
zsh_trace_start() {
2+
echo "starting zsh tracing"
3+
# set the trace prompt to include seconds, nanoseconds, script name and line number
4+
# This is GNU date syntax; by default Macs ship with the BSD date program, which isn't compatible
5+
if [[ $ZSH_VERSION > 4.3.11 ]]; then
6+
zmodload zsh/datetime
7+
setopt promptsubst
8+
export PS4='+$EPOCHREALTIME %N:%i> '
9+
else
10+
export PS4='+$(date "+%s:%N") %N:%i> '
11+
fi
12+
# save file stderr to file descriptor 3 and redirect stderr (including trace
13+
# output) to a file with the script's PID as an extension
14+
exec 3>&2 2>/tmp/startlog.$$
15+
# set options to turn on tracing and expansion of commands contained in the prompt
16+
setopt xtrace prompt_subst
17+
trap 'setopt xtrace' EXIT
18+
}
19+
20+
zsh_trace_end() {
21+
# turn off tracing
22+
unsetopt xtrace
23+
# restore stderr to the value saved in FD 3
24+
exec 2>&3 3>&-
25+
echo "zsh tracing done. See /tmp/startlog.$$"
26+
trap 'unsetopt xtrace' EXIT
27+
}
28+

0 commit comments

Comments
 (0)