Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Bug: time doesn't work on builtins



> 2024/09/06 9:10, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> 
> On Wed, Sep 4, 2024 at 7:33 AM Jun. T <takimoto-j@xxxxxxxxxxxxxxxxx> wrote:
>> 
>> The followings still give no time statistics:
>> 
>> % time x=1
>> % time x=$(date)
> 
> (Hand-fuzzed patch follows)

The patch works for the above two cases, but I've fond there
are still more problems...

[1] In the patch file "time-builtin.txt":

@@ -4377,6 +4384,8 @@ execcmd_exec(Estate state, Execcmd_params eparams,
 	    errflag |= ERRFLAG_ERROR;
 	}
     }
+    if (is_cursh && (how & Z_TIMED))
+	shelltime(&shti, is_builtin ? NULL : &chti, &then, 1);

Due to "is_builtin ? NULL : &chti", child time is not reported for
the cases such as

% time eval 'external command'
% time . ./script	# script runs external command

I think it's better to pass &chti always.


[2] Time spent in prefork() is not included in the statistics.

% time echo $(x=0;for ((i=0; i<=100000; ++i)); do ((x+=i)); done; echo $x)  5000050000
shell  0.00s user 0.00s system 100% cpu 0.000 total

% time cat <(time-consuming-command)	# cat is not builtin
(the problem existed before applying "time-builtin.txt")

% time echo $(external command)
Even if the problem [1] is fixed (by always passing &chti)
the time reported would not include the time used for
the 'external command'.

Not sure this can be fixed easily.



Messages sorted by: Reverse Date, Date, Thread, Author