我可以分析我的 .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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试在文件开头添加以下内容:
并在末尾添加以下内容:
您应该会获得详细的日志,显示每行执行的 epoch_second.nanosecond 时间。请注意,GNU
date
(和操作系统支持)需要纳秒输出。编辑:
添加注释
编辑 2:
如果您有 zsh 4.3.12 或更高版本,您应该能够像这样设置
PS4
而不是使用date
命令:这应该可以工作在 Linux 和 OS X 上为您提供纳秒精度。
Try adding this at the beginning of the file:
and this at the end:
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.Edit:
added comments
Edit 2:
If you have zsh 4.3.12 or later, you should be able to set
PS4
like this instead of using thedate
command:which should work on both Linux and OS X to give you nanosecond precision.
Zsh 有一个分析模块。在
~/.zshrc
或~/.zshenv
的开头添加它,如下所示:取消注释,启动一个新的交互式 shell,然后运行命令
zprof
。您将获得一份详细的项目列表,您可以查看这些项目,以更好地了解性能瓶颈所在:以下是来自 加速 zsh 如果开始时间感觉不稳定,你会很感激:
运行该作业,你应该看到类似的输出:
利润。
Zsh has a profiling module. At the beginning of
~/.zshrc
or~/.zshenv
add it like:Uncomment it, start a new interactive shell then run the command
zprof
. You will get a detailed list of items you can review to better understand where your performance bottlenecks are:And here's a one-liner from speeding up zsh you'll appreciate if start time feels sporadic:
Run that job and you should see output like:
Profit.
您可以在
~/.zshrc
中的第一个可疑点(或开头)启动计时器:如果我看到启动太慢,这会提醒我,并将其保留为永久包装。
对于更复杂的测量,有一个名为
zprof
的 zsh 模块。就像将~/.zshrc
的内容临时包装在zmodload zsh/zprof
和zprof
中一样简单。这将转储一些易于解释的详细分析表。更多信息请参见
zshmodules(1)
联机帮助页。当我发现特别慢的东西(rbenv init、vcs_info check-for-changes、antigen、nvm、zsh-mime-setup、解释器版本检查等)时,我添加
SLOW
注释提醒,并尝试寻找解决方法。缓慢的启动可能会造成很大的痛苦,所以我倾向于避免使用我不了解其内部工作原理的 zsh 包/框架字。 compinit 是我愿意忍受的最慢的事情,大约占总启动时间的一半。You can start your timer at the first suspicious point in your
~/.zshrc
(or at the beginning):This alerts me if ever I see a too-slow startup, and I leave it in as a permanent wrapper.
For more sophisticated measurements, there is a zsh module called
zprof
. It's as simple as temporarily wrapping the contents of your~/.zshrc
in azmodload zsh/zprof
andzprof
. This will dump some verbose profiling tables that are easy enough to interpret.More info in
zshmodules(1)
manpage.When I find things that are particularly slow (rbenv init, vcs_info check-for-changes, antigen, nvm, zsh-mime-setup, interpreter version checking, etc) I add
SLOW
comments as reminders, and try to find workarounds. Slow startups can cause a lot grief, so I tend to avoid zsh packages/framewords whose inner workings I don't grok. compinit is the slowest thing I'm willing to live with and is ~half of total startup time.