From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gatech.edu (gatech.edu [130.207.244.244]) by werple.mira.net.au (8.6.12/8.6.9) with SMTP id DAA15785 for ; Sat, 10 Jun 1995 03:31:41 +1000 Received: from math (math.skiles.gatech.edu) by gatech.edu with SMTP id AA09935 (5.65c/Gatech-10.0-IDA for ); Fri, 9 Jun 1995 13:30:51 -0400 Received: by math (5.x/SMI-SVR4) id AA27759; Fri, 9 Jun 1995 13:28:31 -0400 Resent-Date: Fri, 9 Jun 1995 19:27:18 +0100 (MET DST) Old-Return-Path: From: hzoli@cs.elte.hu (Zoltan Hidvegi) Message-Id: <9506091727.AA07590@turan.elte.hu> Subject: Re: TIMEFMT variable - request for extension To: zsh-workers@math.gatech.edu (zsh-workers) Date: Fri, 9 Jun 1995 19:27:18 +0100 (MET DST) In-Reply-To: <9506061458.AA12500@tuvok.nl.nuwc.navy.mil> from "hall@tuvok.nl.nuwc.navy.mil" at Jun 6, 95 10:58:52 am X-Mailer: ELM [version 2.4 PL21] Content-Type: text Resent-Message-Id: <"wJuo43.0.fn6.zI8sl"@math> Resent-From: zsh-workers@math.gatech.edu X-Mailing-List: archive/latest/96 X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu > > > Dear Zsh Users, > Does anyone know of a simple way to get the format of the time report > to print in HH:MM:SS format? I have read the zshparam.1 man page and don't > see such an option. The closest thing to it is %E, the elapsed user time in > seconds. However, seeing "3600.12" seconds is not as user friendly as > "1:00:00.12". Thanks. :-) I also missed this feature. Here is a patch to implement this. If you write a star between the percent sign and the E, U or S flags, the time will be printed in hh:mm:ss.ttt if it's greater that 1 hour. In mm.ss.ttt if it's at least 1 minute, and only the number of seconts will be pronted if it's less than a minute. Eg. % TIMEFMT='%J: %U+%S, %P CPU, %*E total' % time sleep 61 sleep 61: 0.020s+0.040s, 0% CPU, 1:01.055 total The output format can be asily altered by modifying the three printf's in the printhhmmss function. The patch to the manual also tells the fact that only a few of the documented TIMEFMT escapes are usable. The source patch replaces an (s++, *s) with (*++s) since the later is more clear I think. Zoltan rcsdiff -qc -kk -r1.7 -r1.8 Doc/zshparam.1 *** Doc/zshparam.1 --- Doc/zshparam.1 1995/06/08 01:40:56 *************** *** 711,716 **** --- 711,720 ---- .PD .PP .PD 0 + Currently, only the E, U, S, P and J flags are implemented. + A star may be inserted between the percent sign and flags printing time. + This cause the time to be printed in hh:mm:ss.ttt format (hours and + minutes are only printed if they are not zero). .TP .B TMOUT If this parameter is nonzero, the shell will receive an \fBALRM\fP rcsdiff -qc -kk -r1.1 -r1.2 Src/jobs.c *** Src/jobs.c --- Src/jobs.c 1995/06/09 17:20:56 *************** *** 641,646 **** --- 641,665 ---- /**/ void + printhhmmss(double secs) + { + int intsecs = secs; + int tsecs = 1000 * (secs - intsecs); + int mins = intsecs / 60; + int hours = mins / 60; + + intsecs -= 60 * mins; + mins -= 60 * hours; + if (hours) + fprintf(stderr, "%d:%02d:%02d.%03d", hours, mins, intsecs, tsecs); + else if (mins) + fprintf(stderr, "%d:%02d.%03d", mins, intsecs, tsecs); + else + fprintf(stderr, "%d.%03d", intsecs, tsecs); + } + + /**/ + void printtime(struct timeval *real, struct timeinfo *ti, char *desc) { char *s; *************** *** 676,682 **** for (s = (timefmt ? timefmt : DEFAULT_TIMEFMT); *s; s++) if (*s == '%') ! switch (s++, *s) { case 'E': fprintf(stderr, "%4.3fs", elapsed_time); break; --- 695,701 ---- for (s = (timefmt ? timefmt : DEFAULT_TIMEFMT); *s; s++) if (*s == '%') ! switch (*++s) { case 'E': fprintf(stderr, "%4.3fs", elapsed_time); break; *************** *** 685,690 **** --- 704,726 ---- break; case 'S': fprintf(stderr, "%4.3fs", system_time); + break; + case '*': + switch (*++s) { + case 'E': + printhhmmss(elapsed_time); + break; + case 'U': + printhhmmss(user_time); + break; + case 'S': + printhhmmss(system_time); + break; + default: + fprintf(stderr, "%%*"); + s--; + break; + } break; case 'P': fprintf(stderr, "%d%%", percent);