答案1
的功能REPORTTIME
似乎是硬编码的,以便比较usertime+systime
。该功能的相关 zsh 源代码REPORTTIME
:
#ifdef HAVE_GETRUSAGE
reporttime -= j->procs->ti.ru_utime.tv_sec + j->procs->ti.ru_stime.tv_sec;
if (j->procs->ti.ru_utime.tv_usec +
j->procs->ti.ru_stime.tv_usec >= 1000000)
reporttime--;
return reporttime <= 0;
#else
{
clktck = get_clktck();
return ((j->procs->ti.ut + j->procs->ti.st) / clktck >= reporttime);
}
#endif
作为替代解决方案,您可以修改 zshrc 以获得与REPORTTIME
使用总运行时间类似的功能。
REPORTTIME_TOTAL=5
# Displays the execution time of the last command if set threshold was exceeded
cmd_execution_time() {
local stop=$((`date "+%s + %N / 1_000_000_000.0"`))
let local "elapsed = ${stop} - ${cmd_start_time}"
(( $elapsed > $REPORTTIME_TOTAL )) && print -P "%F{yellow}${elapsed}s%f"
}
# Get the start time of the command
preexec() {
cmd_start_time=$((`date "+%s + %N / 1.0e9"`))
}
# Output total execution
precmd() {
if (($+cmd_start_time)); then
cmd_execution_time
fi
}
不幸的是,此命令仅提供总运行时间。它没有将执行时间细分为用户时间和系统时间。