首页 > 解决方案 > 如何分析 Fish shell init?

问题描述

当我启动一个新的 shell 时,有没有办法查看每件事花费了多少时间(例如,一些正在运行的函数等)。

是否可以?

我能想到的唯一帮助就是做以下事情:

~
λ time fish -i -c exit

________________________________________________________
Executed in  142.29 millis    fish           external
   usr time   76.19 millis   68.00 micros   76.12 millis
   sys time   61.52 millis  469.00 micros   61.05 millis

然后试图把东西拿出来重新测量……虽然不理想。

标签: profilingfish

解决方案


Fish 有一个内置的分析功能。

从 fish 3.2 开始,它必须--profile只分析您给出的命令并--profile-startup分析启动时间,然后才能--profile将两者一起分析。

使用喜欢

fish --profile-startup /tmp/fish.profile -i -c exit

这将创建一个名为“/tmp/fish.profile”的文件,看起来像

Time    Sum Command
415 2505    > builtin source /usr/share/fish/config.fish
15  15  -> set -g IFS \n\ \t
6   6   -> set -qg __fish_added_user_paths
4   4   -> set -g __fish_added_user_paths
1   4   -> if not set -q __fish_initialized...
3   3   --> not set -q __fish_initialized
3   3   -> function __fish_default_command_not_found_handler...
4   72  -> if status --is-interactive...

第一列是命令本身所用的时间(以微秒为单位,因此 1000000 是 1s),第二列是它及其所有部分(包括函数调用和命令替换)所用的时间,第三列是命令加上指示如何这是在调用堆栈的深处。

要查看最大的时间投资sort -nk2 /tmp/fish.profile是有用的 - 这按第二列排序,因此它将最后显示大票项目(即最接近下一个提示)。

请注意,这也显示了 fish 的内部启动 -set -g IFS例如,它是 fish 内部的东西,但它往往很快,所以它不会很突出。


推荐阅读