zsh-workers
 help / color / mirror / code / Atom feed
From: Wayne Davison <wayned@users.sourceforge.net>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: zsh-workers@zsh.org
Subject: Re: ommitted time on resume
Date: Sat, 6 Aug 2011 12:20:53 -0700	[thread overview]
Message-ID: <CAHSx_Ss6c1S9KRi8aco+CegZn63s_Da_UmCSTS8fckWRB7Jy=g@mail.gmail.com> (raw)
In-Reply-To: <110805201755.ZM32464@torch.brasslantern.com>


[-- Attachment #1.1: Type: text/plain, Size: 1895 bytes --]

On Fri, Aug 5, 2011 at 8:17 PM, Bart Schaefer <schaefer@brasslantern.com>wrote:

> Hm.  I wouldn't have expected it to print the time after the job
> was foregrounded again.
>

I sure expect that.  After all, the jobs output of the suspended command
still mentions the "time" prefix.

This seems to be caused by the handling of the first job suspension when it
creates a new process to replace the shell's role in the process handling --
it sets STAT_NOPRINT on the original job (or jobs -- the one(s) that have
STAT_TIMED set).  The STAT_NOPRINT causes a job to not show up in the output
of "jobs" (which just shows the newly-created super job for the whole
command), but it also causes the section of the code that would have gotten
around to printing out the time info to never get reached.

The attached patch seems to be the right fix for this.  It puts a check for
STAT_DONE && should_report_time() into the skip_print short-circuit in
printjob().  I've tested this with a time-wasting program and some pipelines
to see that the output seems correct.  For instance, assume that a.out just
takes 5 seconds in a cpu-wasting loop:

prompt$  time ./a.out | cat ~/foo/*(^/) | wc
 108376  459723 5888382
^Z
[2]  + 30000 suspended  ./a.out |
       30001 done       cat ~/foo/*(^/) |
       30002 done       wc
[1]  + 30003 suspended  time ./a.out | cat ~/foo/*(^/) | wc
prompt$ %
[1]  + 30003 continued  time ./a.out | cat ~/foo/*(^/) | wc
./a.out  5.55s user 0.02s system 54% cpu 10.258 total
cat ~/foo/*(^/)  0.00s user 0.01s system 3% cpu 0.239 total
wc  0.21s user 0.00s system 89% cpu 0.241 total

Without the patch, no times would be output at all.

For even more coolness, it would be nice for the shell to keep track of how
much elapsed time was spent suspended and either subtract it from the
process's wall-clock time output, or output the suspended time in an extra
field.

..wayne..

[-- Attachment #1.2: Type: text/html, Size: 2506 bytes --]

[-- Attachment #2: time-suspend.patch --]
[-- Type: text/x-patch, Size: 305 bytes --]

index 9c9b12f..f64c183 100644
--- a/Src/jobs.c
+++ b/Src/jobs.c
@@ -952,6 +952,8 @@ printjob(Job jn, int lng, int synch)
     }
 
     if (skip_print) {
+	if (jn->stat & STAT_DONE && should_report_time(jn))
+	    dumptime(jn);
 	if (jn->stat & STAT_DONE) {
 	    deletejob(jn);
 	    if (job == curjob) {

  reply	other threads:[~2011-08-06 19:21 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-05 23:21 Wayne Davison
2011-08-06  3:17 ` Bart Schaefer
2011-08-06 19:20   ` Wayne Davison [this message]
2011-08-06 19:45     ` Wayne Davison

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAHSx_Ss6c1S9KRi8aco+CegZn63s_Da_UmCSTS8fckWRB7Jy=g@mail.gmail.com' \
    --to=wayned@users.sourceforge.net \
    --cc=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).