Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/time Allow the user to specify the output format on ...



details:   https://anonhg.NetBSD.org/src/rev/3c3fcf88a9c2
branches:  trunk
changeset: 825459:3c3fcf88a9c2
user:      christos <christos%NetBSD.org@localhost>
date:      Sat Jul 15 14:34:08 2017 +0000

description:
Allow the user to specify the output format on the command line.

diffstat:

 usr.bin/time/ext.h  |   6 ++--
 usr.bin/time/time.1 |  54 +++++++++++++++++++++++++++++++++++++++++++++++++---
 usr.bin/time/time.c |  28 ++++++++++++++++----------
 3 files changed, 70 insertions(+), 18 deletions(-)

diffs (181 lines):

diff -r c04a7531df62 -r 3c3fcf88a9c2 usr.bin/time/ext.h
--- a/usr.bin/time/ext.h        Sat Jul 15 13:54:07 2017 +0000
+++ b/usr.bin/time/ext.h        Sat Jul 15 14:34:08 2017 +0000
@@ -1,5 +1,5 @@
-/*     $NetBSD: ext.h,v 1.2 2011/11/09 19:10:10 christos Exp $ */
+/*     $NetBSD: ext.h,v 1.3 2017/07/15 14:34:08 christos Exp $ */
 
 /* borrowed from ../../bin/csh/extern.h */
-void prusage(FILE *, struct rusage *, struct rusage *, struct timespec *,
-        struct timespec *);
+void prusage1(FILE *, const char *fmt, struct rusage *, struct rusage *,
+    struct timespec *, struct timespec *);
diff -r c04a7531df62 -r 3c3fcf88a9c2 usr.bin/time/time.1
--- a/usr.bin/time/time.1       Sat Jul 15 13:54:07 2017 +0000
+++ b/usr.bin/time/time.1       Sat Jul 15 14:34:08 2017 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: time.1,v 1.26 2016/12/21 18:01:21 abhinav Exp $
+.\"    $NetBSD: time.1,v 1.27 2017/07/15 14:34:08 christos Exp $
 .\"
 .\" Copyright (c) 1980, 1991, 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\"     @(#)time.1     8.1 (Berkeley) 6/6/93
 .\"
-.Dd November 9, 2011
+.Dd July 15, 2017
 .Dt TIME 1
 .Os
 .Sh NAME
@@ -38,6 +38,7 @@
 .Sh SYNOPSIS
 .Nm
 .Op Fl clp
+.Op Fl f Ar fmt
 .Ar command
 .Op Ar argument ...
 .Sh DESCRIPTION
@@ -63,10 +64,55 @@
 Available options:
 .Bl -tag -width Ds
 .It Fl c
-Displays information in the format used by the
+Displays information in the format used by default the
 .Nm
 builtin of
-.Xr csh 1 .
+.Xr csh 1 uses (\&%Uu \&%Ss \&%E \&%P \&%X+\&%Dk \&%I+\&%Oio \&%Fpf+\&%Ww).
+.It Fl f
+Specify a time format using the
+.Xr csh 1
+.Nm
+builtin syntax.
+The following sequences may be used in the format string:
+.Pp
+.Bl -tag -width 4n -compact
+.It \&%U
+The time the process spent in user mode in cpu seconds.
+.It \&%S
+The time the process spent in kernel mode in cpu seconds.
+.It \&%E
+The elapsed (wall clock) time in seconds.
+.It \&%P
+The CPU percentage computed as (\&%U + \&%S) / \&%E.
+.It \&%W
+Number of times the process was swapped.
+.It \&%X
+The average amount in (shared) text space used in Kbytes.
+.It \&%D
+The average amount in (unshared) data/stack space used in Kbytes.
+.It \&%K
+The total space used (\&%X + \&%D) in Kbytes.
+.It \&%M
+The maximum memory the process had in use at any time in Kbytes.
+.It \&%F
+The number of major page faults (page needed to be brought from disk).
+.It \&%R
+The number of minor page faults.
+.It \&%I
+The number of input operations.
+.It \&%O
+The number of output operations.
+.It \&%r
+The number of socket messages received.
+.It \&%s
+The number of socket messages sent.
+.It \&%k
+The number of signals received.
+.It \&%w
+The number of voluntary context switches (waits).
+.It \&%c
+The number of involuntary context switches.
+.El
 .It Fl l
 Lists resource utilization information.
 The contents of the
diff -r c04a7531df62 -r 3c3fcf88a9c2 usr.bin/time/time.c
--- a/usr.bin/time/time.c       Sat Jul 15 13:54:07 2017 +0000
+++ b/usr.bin/time/time.c       Sat Jul 15 14:34:08 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: time.c,v 1.22 2011/11/09 19:10:10 christos Exp $       */
+/*     $NetBSD: time.c,v 1.23 2017/07/15 14:34:08 christos Exp $       */
 
 /*
  * Copyright (c) 1987, 1988, 1993
@@ -39,7 +39,7 @@
 #if 0
 static char sccsid[] = "@(#)time.c     8.1 (Berkeley) 6/6/93";
 #endif
-__RCSID("$NetBSD: time.c,v 1.22 2011/11/09 19:10:10 christos Exp $");
+__RCSID("$NetBSD: time.c,v 1.23 2017/07/15 14:34:08 christos Exp $");
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -70,31 +70,37 @@
        int ch, status;
        int volatile portableflag;
        int volatile lflag;
-       int volatile cshflag;
        const char *decpt;
+       const char *fmt;
        const struct lconv *lconv;
        struct timespec before, after;
        struct rusage ru;
 
        (void)setlocale(LC_ALL, "");
 
-       cshflag = lflag = portableflag = 0;
-       while ((ch = getopt(argc, argv, "clp")) != -1) {
+       lflag = portableflag = 0;
+       fmt = NULL;
+       while ((ch = getopt(argc, argv, "cf:lp")) != -1) {
                switch (ch) {
+               case 'f':
+                       fmt = optarg;
+                       portableflag = 0;
+                       lflag = 0;
+                       break;
                case 'c':
-                       cshflag = 1;
+                       fmt = "%Uu %Ss %E %P %X+%Dk %I+%Oio %Fpf+%Ww";
                        portableflag = 0;
                        lflag = 0;
                        break;
                case 'p':
                        portableflag = 1;
-                       cshflag = 0;
+                       fmt = NULL;
                        lflag = 0;
                        break;
                case 'l':
                        lflag = 1;
                        portableflag = 0;
-                       cshflag = 0;
+                       fmt = NULL;
                        break;
                case '?':
                default:
@@ -133,11 +139,11 @@
            (decpt = lconv->decimal_point) == NULL)
                decpt = ".";
 
-       if (cshflag) {
+       if (fmt) {
                static struct rusage null_ru;
                before.tv_sec = 0;
                before.tv_nsec = 0;
-               prusage(stderr, &null_ru, &ru, &after, &before);
+               prusage1(stderr, fmt, &null_ru, &ru, &after, &before);
        } else if (portableflag) {
                prts("real ", decpt, &after, "\n");
                prtv("user ", decpt, &ru.ru_utime, "\n");
@@ -178,7 +184,7 @@
 usage(void)
 {
 
-       (void)fprintf(stderr, "Usage: %s [-clp] utility [argument ...]\n",
+       (void)fprintf(stderr, "Usage: %s [-clp] [-f <fmt>] utility [argument ...]\n",
            getprogname());
        exit(EXIT_FAILURE);
 }



Home | Main Index | Thread Index | Old Index