about summary refs log tree commit diff
diff options
context:
space:
mode:
authordana <dana@dana.is>2017-12-13 20:49:58 -0600
committerPeter Stephenson <pws@zsh.org>2017-12-14 15:36:46 +0000
commitcb04ae40af123da88bf0209964965d17a9486325 (patch)
tree505bcf82722f7fa68050c7267068be40df5b0744
parenta3d92298ff9dd14c98b01c76d7e374499fd27ae7 (diff)
downloadzsh-cb04ae40af123da88bf0209964965d17a9486325.tar.gz
zsh-cb04ae40af123da88bf0209964965d17a9486325.tar.xz
zsh-cb04ae40af123da88bf0209964965d17a9486325.zip
add millisecond and microsecond options to TIMEFMT variable
-rw-r--r--ChangeLog6
-rw-r--r--Doc/Zsh/params.yo6
-rw-r--r--Src/jobs.c34
-rw-r--r--Test/A01grammar.ztst4
4 files changed, 48 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index e46c5228f..dfd30ca9c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2017-12-14  Peter Stephenson  <p.stephenson@samsung.com>
+
+	* dana: 42119: Doc/zsh/params.yo, Src/jobs.c,
+	Test/A01grammar.ztst: add millisecond and microsecond options to
+	TIMEFMT variable.
+
 2017-12-13  Peter Stephenson  <p.w.stephenson@ntlworld.com>
 
 	* Matthew Martin: 42113: Completion/BSD/Command/_bsd_pkg,
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