本文介绍了我可以分析我的 .zshrc/.zshenv 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎我的 shell 启动时间太长了方式.有什么方法可以对其进行分析,以便我可以弄清楚是什么让它如此缓慢?

It seems like my shell is taking way too long to start up. Is there any way to profile it so I can figure out what's slowing it down so much?

推荐答案

尝试在文件开头添加:

# 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

最后是:

# turn off tracing
unsetopt xtrace
# restore stderr to the value saved in FD 3
exec 2>&3 3>&-

你应该得到一个详细的日志,显示每行执行的 epoch_second.nanosecond 时间.请注意,需要 GNU date(和操作系统支持)才能获得纳秒输出.

And you should get a detailed log showing the epoch_second.nanosecond time of the execution of each line. Note that GNU date (and OS support) is required to have nanosecond output.

添加评论

编辑 2:

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

If you have zsh 4.3.12 or later, you should be able to set PS4 like this instead of using the date command:

zmodload zsh/datetime
setopt promptsubst
PS4='+$EPOCHREALTIME %N:%i> '

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

which should work on both Linux and OS X to give you nanosecond precision.

这篇关于我可以分析我的 .zshrc/.zshenv 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 15:46