【问题标题】:How can I profile the Fish shell init?如何配置 Fish shell init?
【发布时间】:2020-08-06 18:53:54
【问题描述】:

当我启动一个新的 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

然后尝试将东西取出并再次测量...虽然不理想。

【问题讨论】:

    标签: profiling fish


    【解决方案1】:

    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 内部的东西,但它往往很快,所以不会突出。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-27
      • 1970-01-01
      • 2014-03-04
      • 2015-10-26
      • 2014-08-05
      • 1970-01-01
      • 2023-01-07
      • 2021-11-17
      相关资源
      最近更新 更多