| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: time.c,v 1.17 2008/02/24 05:20:17 dholland Exp $ */ | | 1 | /* $NetBSD: time.c,v 1.18 2011/08/28 07:49:16 christos Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 1980, 1991, 1993 | | 4 | * Copyright (c) 1980, 1991, 1993 |
5 | * The Regents of the University of California. All rights reserved. | | 5 | * The Regents of the University of California. All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -24,43 +24,43 @@ | | | @@ -24,43 +24,43 @@ |
24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | | 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
29 | * SUCH DAMAGE. | | 29 | * SUCH DAMAGE. |
30 | */ | | 30 | */ |
31 | | | 31 | |
32 | #include <sys/cdefs.h> | | 32 | #include <sys/cdefs.h> |
33 | #ifndef lint | | 33 | #ifndef lint |
34 | #if 0 | | 34 | #if 0 |
35 | static char sccsid[] = "@(#)time.c 8.1 (Berkeley) 5/31/93"; | | 35 | static char sccsid[] = "@(#)time.c 8.1 (Berkeley) 5/31/93"; |
36 | #else | | 36 | #else |
37 | __RCSID("$NetBSD: time.c,v 1.17 2008/02/24 05:20:17 dholland Exp $"); | | 37 | __RCSID("$NetBSD: time.c,v 1.18 2011/08/28 07:49:16 christos Exp $"); |
38 | #endif | | 38 | #endif |
39 | #endif /* not lint */ | | 39 | #endif /* not lint */ |
40 | | | 40 | |
41 | #ifndef NOT_CSH | | 41 | #ifndef NOT_CSH |
42 | #include <sys/types.h> | | 42 | #include <sys/types.h> |
43 | #include <stdarg.h> | | 43 | #include <stdarg.h> |
44 | #include "csh.h" | | 44 | #include "csh.h" |
45 | #include "extern.h" | | 45 | #include "extern.h" |
46 | #endif | | 46 | #endif |
| | | 47 | #include <util.h> |
47 | | | 48 | |
48 | /* | | 49 | /* |
49 | * C Shell - routines handling process timing and niceing | | 50 | * C Shell - routines handling process timing and niceing |
50 | */ | | 51 | */ |
51 | static void pdeltat(FILE *, struct timeval *, struct timeval *); | | 52 | static void pdeltat(FILE *, struct timeval *, struct timeval *); |
52 | static void pcsecs(FILE *, long); | | 53 | static void pcsecs(FILE *, long); |
53 | extern char *strpct(u_long, u_long, u_int); | | | |
54 | | | 54 | |
55 | #ifndef NOT_CSH | | 55 | #ifndef NOT_CSH |
56 | void | | 56 | void |
57 | settimes(void) | | 57 | settimes(void) |
58 | { | | 58 | { |
59 | struct rusage ruch; | | 59 | struct rusage ruch; |
60 | | | 60 | |
61 | (void)gettimeofday(&time0, NULL); | | 61 | (void)gettimeofday(&time0, NULL); |
62 | (void)getrusage(RUSAGE_SELF, &ru0); | | 62 | (void)getrusage(RUSAGE_SELF, &ru0); |
63 | (void)getrusage(RUSAGE_CHILDREN, &ruch); | | 63 | (void)getrusage(RUSAGE_CHILDREN, &ruch); |
64 | ruadd(&ru0, &ruch); | | 64 | ruadd(&ru0, &ruch); |
65 | } | | 65 | } |
66 | | | 66 | |
| @@ -176,27 +176,29 @@ prusage(FILE *fp, struct rusage *r0, str | | | @@ -176,27 +176,29 @@ prusage(FILE *fp, struct rusage *r0, str |
176 | (r0->ru_ixrss + r0->ru_idrss + r0->ru_isrss)) / t)); | | 176 | (r0->ru_ixrss + r0->ru_idrss + r0->ru_isrss)) / t)); |
177 | break; | | 177 | break; |
178 | case 'M': /* max. Resident Set Size */ | | 178 | case 'M': /* max. Resident Set Size */ |
179 | (void)fprintf(fp, "%ld", r1->ru_maxrss / 2L); | | 179 | (void)fprintf(fp, "%ld", r1->ru_maxrss / 2L); |
180 | break; | | 180 | break; |
181 | case 'O': /* FS blocks out */ | | 181 | case 'O': /* FS blocks out */ |
182 | (void)fprintf(fp, "%ld", r1->ru_oublock - r0->ru_oublock); | | 182 | (void)fprintf(fp, "%ld", r1->ru_oublock - r0->ru_oublock); |
183 | break; | | 183 | break; |
184 | case 'P': /* percent time spent running */ | | 184 | case 'P': /* percent time spent running */ |
185 | /* check if it did not run at all */ | | 185 | /* check if it did not run at all */ |
186 | if (ms == 0) { | | 186 | if (ms == 0) { |
187 | (void)fputs("0.0%", fp); | | 187 | (void)fputs("0.0%", fp); |
188 | } else { | | 188 | } else { |
189 | (void)fputs(strpct((ulong)t, (ulong)ms, 1), fp); | | 189 | char pb[32]; |
| | | 190 | (void)fputs(strpct(pb, sizeof(pb), t, ms, 1), fp); |
| | | 191 | (void)fputc('%', fp); |
190 | } | | 192 | } |
191 | break; | | 193 | break; |
192 | case 'R': /* page reclaims */ | | 194 | case 'R': /* page reclaims */ |
193 | (void)fprintf(fp, "%ld", r1->ru_minflt - r0->ru_minflt); | | 195 | (void)fprintf(fp, "%ld", r1->ru_minflt - r0->ru_minflt); |
194 | break; | | 196 | break; |
195 | case 'S': /* system CPU time used */ | | 197 | case 'S': /* system CPU time used */ |
196 | pdeltat(fp, &r1->ru_stime, &r0->ru_stime); | | 198 | pdeltat(fp, &r1->ru_stime, &r0->ru_stime); |
197 | break; | | 199 | break; |
198 | case 'U': /* user CPU time used */ | | 200 | case 'U': /* user CPU time used */ |
199 | pdeltat(fp, &r1->ru_utime, &r0->ru_utime); | | 201 | pdeltat(fp, &r1->ru_utime, &r0->ru_utime); |
200 | break; | | 202 | break; |
201 | case 'W': /* number of swaps */ | | 203 | case 'W': /* number of swaps */ |
202 | i = r1->ru_nswap - r0->ru_nswap; | | 204 | i = r1->ru_nswap - r0->ru_nswap; |