Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [RFC] Millisecond and microsecond specifiers for TIMEFMT
- X-seq: zsh-workers 42119
- From: dana <dana@xxxxxxx>
- To: Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
- Subject: Re: [RFC] Millisecond and microsecond specifiers for TIMEFMT
- Date: Wed, 13 Dec 2017 20:49:58 -0600
- Cc: zsh-workers@xxxxxxx
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dana-is.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=mbVow3vDw/EiHrHOOp2S5d+jQ5CJ0f22tvUHVKOOnTs=; b=R5miTcNdn1H9mwayOOgqN4WmAtPu4RnEYXDXrX7f/lES+Oz91FT/vINIPClN+S6lvP au2CtthDBmyMCqbEQAeZXEZq0nVYWiCrjDGkLS4LRqp19wXKo2spqhZzK2abloL4cUab xpIP30oUxSkt07zrM9jdTrfN01k70zQ4woZeHmNKtH1/96mFsmEM2d7GQCCa1AjU9tv2 AdY7Clt7Ffo7AZGVhhnlf9HkS2TLz+L8Brpl0vcdu1peG5WBAtXPoJj9dF5vkteIYecL Vy+zQrAWZBAX4Ndq/KiP/Z0FUYbqpPBPxE+R5AyfhOK9Tu5BdsTAKwHD1u+iL2xLuuT3 M7Og==
- In-reply-to: <20171213180152.0af7a27f@ntlworld.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <6A9332CC-D501-4B1C-9347-92D0E87E45D7@dana.is> <20171213180152.0af7a27f@ntlworld.com>
On 13 Dec 2017, at 12:01, Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx> wrote:
>You don't need to fiddle with SECONDS beyond turning it into floating
>point...
Yeah, that's what i was referring to. It works OK, for what it is.
On 13 Dec 2017, at 12:01, Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx> wrote:
>Can't see any obvious problem with this. Just needs documenting.
Added test and documentation then. I have absolutely no idea how to get yodl
built on macOS, so if someone has time to double-check my syntax that'd be nice.
Thanks!
dana
diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo
index 5757111b2..bb5c8a54d 100644
--- a/Doc/Zsh/params.yo
+++ b/Doc/Zsh/params.yo
@@ -1616,10 +1616,12 @@ sitem(tt(%c))(Number of involuntary context switches.)
sitem(tt(%J))(The name of this job.)
endsitem()
-A star may be inserted between the percent sign and flags printing time.
-This cause the time to be printed in
+A star may be inserted between the percent sign and flags printing time
+(e.g., `tt(%*E)'); this causes the time to be printed in
`var(hh)tt(:)var(mm)tt(:)var(ss)tt(.)var(ttt)'
format (hours and minutes are only printed if they are not zero).
+Alternatively, `tt(m)' or `tt(u)' may be used (e.g., `tt(%mE)') to produce
+time output in milliseconds or microseconds, respectively.
)
vindex(TMOUT)
item(tt(TMOUT))(
diff --git a/Src/jobs.c b/Src/jobs.c
index 226e7cff3..fc5bfacc6 100644
--- a/Src/jobs.c
+++ b/Src/jobs.c
@@ -728,6 +728,40 @@ printtime(struct timeval *real, child_times_t *ti, char *desc)
case 'S':
fprintf(stderr, "%4.2fs", system_time);
break;
+ case 'm':
+ switch (*++s) {
+ case 'E':
+ fprintf(stderr, "%0.fms", elapsed_time * 1000.0);
+ break;
+ case 'U':
+ fprintf(stderr, "%0.fms", user_time * 1000.0);
+ break;
+ case 'S':
+ fprintf(stderr, "%0.fms", system_time * 1000.0);
+ break;
+ default:
+ fprintf(stderr, "%%m");
+ s--;
+ break;
+ }
+ break;
+ case 'u':
+ switch (*++s) {
+ case 'E':
+ fprintf(stderr, "%0.fus", elapsed_time * 1000000.0);
+ break;
+ case 'U':
+ fprintf(stderr, "%0.fus", user_time * 1000000.0);
+ break;
+ case 'S':
+ fprintf(stderr, "%0.fus", system_time * 1000000.0);
+ break;
+ default:
+ fprintf(stderr, "%%u");
+ s--;
+ break;
+ }
+ break;
case '*':
switch (*++s) {
case 'E':
diff --git a/Test/A01grammar.ztst b/Test/A01grammar.ztst
index 5e7d6acd8..217f7bea4 100644
--- a/Test/A01grammar.ztst
+++ b/Test/A01grammar.ztst
@@ -369,6 +369,10 @@
(time cat) >&/dev/null
0:`time' keyword (status only)
+ TIMEFMT='%E %mE %uE %* %m%mm %u%uu'; time (:)
+0:`time' keyword with custom TIMEFMT
+*?[0-9]##.[0-9](#c2)s [0-9]##ms [0-9]##us %\* %m%mm %u%uu
+
if [[ -f foo && -d . && -n $ZTST_testdir ]]; then
true
else
Messages sorted by:
Reverse Date,
Date,
Thread,
Author