zsh-workers
 help / color / mirror / code / Atom feed
* zsh built-in commands are removed when passing through a built-in command that spawns commands
@ 2013-05-15 14:14 Antoine Pietri
  2013-05-15 17:24 ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Antoine Pietri @ 2013-05-15 14:14 UTC (permalink / raw)
  To: zsh-workers

Hello,

An example is way simpler than long explanations:

% while true; do time cat; done
cat  0,00s user 0,00s system 0% cpu 0,363 total
cat  0,00s user 0,00s system 0% cpu 0,162 total
cat  0,00s user 0,00s system 0% cpu 0,168 total
cat  0,00s user 0,00s system 0% cpu 0,163 total
cat  0,00s user 0,00s system 0% cpu 0,157 total
^C
cat  0,00s user 0,00s system 0% cpu 0,195 total

It only displays the zsh "time" built-in. I also have a binary `time`
which displays a formatted output like this:

0.00user 0.00system 0:00.46elapsed 0%CPU (0avgtext+0avgdata 636maxresident)k
0inputs+0outputs (0major+206minor)pagefaults 0swaps

And zsh actually displays this kind of output when I try to time a
command which contains time:

 % time (while true; do time cat; done)
0.00user 0.00system 0:00.46elapsed 0%CPU (0avgtext+0avgdata 636maxresident)k
0inputs+0outputs (0major+206minor)pagefaults 0swaps
0.00user 0.00system 0:00.43elapsed 0%CPU (0avgtext+0avgdata 636maxresident)k
0inputs+0outputs (0major+206minor)pagefaults 0swaps
0.00user 0.00system 0:00.22elapsed 0%CPU (0avgtext+0avgdata 636maxresident)k
0inputs+0outputs (0major+207minor)pagefaults 0swaps
0.00user 0.00system 0:00.21elapsed 0%CPU (0avgtext+0avgdata 636maxresident)k
0inputs+0outputs (0major+206minor)pagefaults 0swaps
^CCommand terminated by signal 2
0.00user 0.00system 0:00.52elapsed 0%CPU (0avgtext+0avgdata 604maxresident)k
0inputs+0outputs (0major+198minor)pagefaults 0swaps

( while true; do; time cat; done; )  0,00s user 0,00s system 0% cpu 1,884 total

Only the last line is the result of an actual zsh-time, the rest is
the `time` binary.

A bit wibbly-woobly… time-y wimey ?

Regards,

-- 
Antoine Pietri


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: zsh built-in commands are removed when passing through a built-in command that spawns commands
  2013-05-15 14:14 zsh built-in commands are removed when passing through a built-in command that spawns commands Antoine Pietri
@ 2013-05-15 17:24 ` Bart Schaefer
  2013-05-15 17:26   ` Antoine Pietri
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2013-05-15 17:24 UTC (permalink / raw)
  To: Antoine Pietri; +Cc: Zsh hackers list

I can't reproduce this.  What do you get from

% time ( repeat 3; do; whence -a time; done )

??


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: zsh built-in commands are removed when passing through a built-in command that spawns commands
  2013-05-15 17:24 ` Bart Schaefer
@ 2013-05-15 17:26   ` Antoine Pietri
  2013-05-15 17:33     ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Antoine Pietri @ 2013-05-15 17:26 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh hackers list

2013/5/15 Bart Schaefer <schaefer@brasslantern.com>:
> I can't reproduce this.  What do you get from
>
> % time ( repeat 3; do; whence -a time; done )
>
> ??

% time ( repeat 3; do; whence -a time; done )
time
/usr/bin/time
time
/usr/bin/time
time
/usr/bin/time
( repeat 3; do; whence -a time; done; )  0,00s user 0,00s system 0%
cpu 0,002 total


-- 
Antoine Pietri


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: zsh built-in commands are removed when passing through a built-in command that spawns commands
  2013-05-15 17:26   ` Antoine Pietri
@ 2013-05-15 17:33     ` Bart Schaefer
  2013-05-15 19:28       ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2013-05-15 17:33 UTC (permalink / raw)
  To: Antoine Pietri; +Cc: Zsh hackers list

On Wed, May 15, 2013 at 10:26 AM, Antoine Pietri
<antoine.pietri1@gmail.com> wrote:
>
> % time ( repeat 3; do; whence -a time; done )
> time
> /usr/bin/time

Well, that indicates that the builtin time is still there.  So
something else must be going on.

Have you tried looking at the oddball while loop with setopt xtrace ?


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: zsh built-in commands are removed when passing through a built-in command that spawns commands
  2013-05-15 17:33     ` Bart Schaefer
@ 2013-05-15 19:28       ` Bart Schaefer
  0 siblings, 0 replies; 5+ messages in thread
From: Bart Schaefer @ 2013-05-15 19:28 UTC (permalink / raw)
  To: Antoine Pietri; +Cc: Zsh hackers list

On Wed, May 15, 2013 at 10:33 AM, Bart Schaefer
<schaefer@brasslantern.com> wrote:
>
> Well, that indicates that the builtin time is still there.  So
> something else must be going on.

Aha.  I can in fact reproduce it, I was misled by $TIMEFMT.

So ... what's happening is that the shell can't time itself timing
time, if you see what I mean. The trivial case is

% time time true

The built-in time [which is actually a keyword rather than a command,
which is why
  % time (sublist)
works at all] is executed in the current shell and is able to record
the elapsed time for a single "job".  If that job is also executed in
the current shell, the built-in handles that by reading the time stats
for the shell itself.  If that current-shell-job in turn is also the
built-in time, there's no nested set of time stats available ...
either the outer time has to be abandoned [or reported incorrectly] or
the inner one has to be handled differently.

Zsh chooses to solve this during parsing by simply not recognizing the
time keyword inside another time keyword.  You can see this by the
strange parse error in this example:

% time (true)
( true; )  0.00s user 0.00s system 48% cpu 0.001 total
% time time (true)
zsh: missing end of name
time (true)  0.00s user 0.00s system 49% cpu 0.001 total

A possible alternative would be for a nested "time" keyword to force
itself into a subshell.  This wouldn't cost any more processes than
the current approach of falling back to the external time command.
Unfortunately this is not entirely trivial to implement, though
someone who knows the internal wordcode representation better than I
do could probably do it reasonably quickly.

An intermediate approach is to recognize nested time keywords in
explicit subshells, which turns out to be pretty straightforward.  If
that were implemented,

% time ( time true )

would use the keyword in both positions, but

% time time true
% time { time true }

would behave as they do now.  We'd want to implement the subshell
variant anyway in order to avoid an unnecessary fork for the time
keyword inside the subshell, but by itself it'd introduce even more
inconsistency.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-05-15 19:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-15 14:14 zsh built-in commands are removed when passing through a built-in command that spawns commands Antoine Pietri
2013-05-15 17:24 ` Bart Schaefer
2013-05-15 17:26   ` Antoine Pietri
2013-05-15 17:33     ` Bart Schaefer
2013-05-15 19:28       ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).