gpt4 book ai didi

performance - 在 zsh 中的每个命令之后自动执行内置时间(如 tcsh 中的 `set time`)

转载 作者:行者123 更新时间:2023-12-02 18:31:37 25 4
gpt4 key购买 nike

tcsh ,有一个非常有用的功能,可以自动打印每个命令的时间统计信息。可以通过非常简单的设置时间来启用它,以通过时间的名称设置“特殊shell变量”:

tcsh$ set time
tcsh$ sleep 1
0.000u 0.015s 0:01.01 0.9% 0+0k 0+0io 2241pf+0w
tcsh$ sleep 1 && sleep 0.1
0.000u 0.000s 0:01.01 0.0% 0+0k 0+0io 2241pf+0w
0.000u 0.015s 0:00.11 9.0% 0+0k 0+0io 2243pf+0w
tcsh$
tcsh$ man tcsh | fgrep -A2 'If set to a number,'
time If set to a number, then the time builtin (q.v.) executes auto‐
matically after each command which takes more than that many
CPU seconds. If there is a second word, it is used as a format
2.257u 0.319s 0:01.52 168.4% 0+0k 0+0io 35517pf+0w
tcsh$

我尝试为 zsh 寻找类似的解决方案,但我在 zshoptions(1) 中找不到这样的选项或任何其他页面,我得到的只是更改 shell 底层功能的广泛配置设置(除了 EXTENDED_HISTORYINC_APPEND_HISTORY_TIME,它们虽然非常有用,但并不与我正在寻找的相同)。

zsh没有类似的选项吗?有没有办法打印一组命令中每个命令的执行时间?

最佳答案

该选项实际上位于 zshparam 中,不是zshoptions ,称为REPORTTIME

zsh% REPORTTIME=
% REPORTTIME=
zsh% sleep 1
sleep 1 0.02s user 0.01s system 2% cpu 1.039 total
zsh% sleep 1 && sleep 0.1
sleep 1 0.03s user 0.01s system 3% cpu 1.094 total
sleep 0.1 0.01s user 0.01s system 17% cpu 0.130 total
zsh%
% man zshparam | fgrep -B1 -A3 'If nonnegative'
REPORTMEMORY
If nonnegative, commands whose maximum resident set size
(roughly speaking, main memory usage) in kilobytes is greater
than this value have timing statistics reported. The format
used to output statistics is the value of the TIMEFMT parameter,
--
REPORTTIME
If nonnegative, commands whose combined user and system
execution times (measured in seconds) are greater than this
value have timing statistics printed for them. Output is
suppressed for commands executed within the line editor,
man zshparam 0.06s user 0.01s system 94% cpu 0.071 total
fgrep -B1 -A3 'If nonnegative' 0.02s user 0.02s system 67% cpu 0.069 total
%

关于performance - 在 zsh 中的每个命令之后自动执行内置时间(如 tcsh 中的 `set time`),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69338321/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com