4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 #pragma ident "%Z%%M% %I% %E% SMI"
45 #include <sys/types.h>
46 #include <sys/times.h>
50 * The following use of HZ/10 will work correctly only if HZ is a multiple
51 * of 10. However the only values for HZ now in use are 100 for the 3B
52 * and 60 for other machines.
54 * The first value was HZ/10. Since HZ should be gotten from sysconf()
55 * it is dynamically initialized at entry to the main program.
57 static clock_t quant
[] = { 10, 10, 10, 6, 10, 6, 10, 10, 10 };
58 static char *pad
= "000 ";
59 static char *sep
= "\0\0.\0:\0:\0\0";
60 static char *nsep
= "\0\0.\0 \0 \0\0";
62 static void usage(void);
63 static void printt(char *, clock_t);
66 main(int argc
, char **argv
)
73 int clock_tick
= CLK_TCK
;
74 clock_t before
, after
;
76 (void) setlocale(LC_ALL
, "");
77 #if !defined(TEXT_DOMAIN)
78 #define TEXT_DOMAIN "SYS_TEST"
80 (void) textdomain(TEXT_DOMAIN
);
82 while ((c
= getopt(argc
, argv
, "p")) != EOF
)
95 * time(1) is only accurate to a tenth of a second. We need to
96 * determine the number of clock ticks in a tenth of a second in
97 * order to later divide away what we don't care about.
99 quant
[0] = clock_tick
/10;
101 before
= times(&buffer
);
105 if (p
== (pid_t
)-1) {
110 (void) execvp(argv
[0], &argv
[0]);
117 (void) signal(SIGINT
, SIG_IGN
);
118 (void) signal(SIGQUIT
, SIG_IGN
);
119 while (wait(&status
) != p
);
120 if ((status
& 0377) != '\0')
121 (void) fprintf(stderr
, "time: %s\n",
122 gettext("command terminated abnormally."));
123 after
= times(&buffer
);
124 (void) fprintf(stderr
, "\n");
126 (void) fprintf(stderr
, "real %.2f\nuser %.2f\nsys %.2f\n",
127 (double)(after
-before
)/clock_tick
,
128 (double)buffer
.tms_cutime
/clock_tick
,
129 (double)buffer
.tms_cstime
/clock_tick
);
131 printt("real", (after
-before
));
132 printt("user", buffer
.tms_cutime
);
133 printt("sys ", buffer
.tms_cstime
);
136 return ((status
& 0xff00)
138 : ((status
& 0x00ff) ? ((status
& ~WCOREFLG
) | 0200) : 0));
143 printt(char *s
, clock_t a
)
150 a
/= quant
[0]; /* Divide away the accuracy we don't care about */
153 * We now have the number of tenths of seconds elapsed in terms of
154 * ticks. Loop through to determine the actual digits.
156 for (i
= 1; i
< 9; i
++) {
157 digit
[i
] = a
% quant
[i
];
160 (void) fprintf(stderr
, s
);
163 c
= (digit
[i
] != 0) ? digit
[i
]+'0' : (nonzero
? '0': pad
[i
]);
165 (void) putc(c
, stderr
);
167 c
= nonzero
?sep
[i
]:nsep
[i
];
169 (void) putc(c
, stderr
);
171 (void) fprintf(stderr
, "\n");
177 (void) fprintf(stderr
,
178 gettext("usage: time [-p] utility [argument...]\n"));