From: hzoli@cs.elte.hu (Zoltan Hidvegi)
To: zsh-workers@math.gatech.edu (zsh-workers)
Subject: Re: TIMEFMT variable - request for extension
Date: Fri, 9 Jun 1995 19:27:18 +0100 (MET DST) [thread overview]
Message-ID: <9506091727.AA07590@turan.elte.hu> (raw)
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
>
>
> 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);
parent reply other threads:[~1995-06-09 17:31 UTC|newest]
Thread overview: expand[flat|nested] mbox.gz Atom feed
[parent not found: <9506061458.AA12500@tuvok.nl.nuwc.navy.mil>]
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=9506091727.AA07590@turan.elte.hu \
--to=hzoli@cs.elte.hu \
--cc=zsh-workers@math.gatech.edu \
/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).