我可以介绍一下我的.zshrc/.zshenv吗?

Jas*_*ker 42 profiling zsh

这似乎是我的壳正在采取的方式太长启动.有什么方法可以对它进行分析,这样我就可以弄清楚是什么让它减慢了这么多?

Pau*_*ce. 46

尝试在文件的开头添加:

# 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
PS4='+$(date "+%s:%N") %N:%i> '
# 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>/tmp/startlog.$$
# set options to turn on tracing and expansion of commands contained in the prompt
setopt xtrace prompt_subst
Run Code Online (Sandbox Code Playgroud)

最后这个:

# turn off tracing
unsetopt xtrace
# restore stderr to the value saved in FD 3
exec 2>&3 3>&-
Run Code Online (Sandbox Code Playgroud)

你应该得到一个详细的日志,显示每行执行的epoch_second.nanosecond时间.请注意,GNU date(和OS支持)需要具有纳秒输出.

编辑:

补充评论

编辑2:

如果你有zsh 4.3.12或更高版本,你应该能够PS4像这样设置而不是使用date命令:

zmodload zsh/datetime
setopt promptsubst
PS4='+$EPOCHREALTIME %N:%i> '
Run Code Online (Sandbox Code Playgroud)

它应该适用于Linux和OS X,以提供纳秒精度.