diff options
author | David E. O'Brien <obrien@FreeBSD.org> | 2000-10-28 21:48:53 +0000 |
---|---|---|
committer | David E. O'Brien <obrien@FreeBSD.org> | 2000-10-28 21:48:53 +0000 |
commit | ea257bd5544f0d72af9f801d885f7c0cdfc8c126 (patch) | |
tree | c9a5ad4f95e7e82dcdf41e4a341eff4cbd64793a /usr.bin/time | |
parent | a1b75a424f230abe61e7d4a5f451f63628f5f6ba (diff) | |
download | src-ea257bd5544f0d72af9f801d885f7c0cdfc8c126.tar.gz src-ea257bd5544f0d72af9f801d885f7c0cdfc8c126.zip |
Notes
Diffstat (limited to 'usr.bin/time')
-rw-r--r-- | usr.bin/time/time.1 | 6 | ||||
-rw-r--r-- | usr.bin/time/time.c | 44 |
2 files changed, 45 insertions, 5 deletions
diff --git a/usr.bin/time/time.1 b/usr.bin/time/time.1 index 48cd78d1e38a..e896f1ce765f 100644 --- a/usr.bin/time/time.1 +++ b/usr.bin/time/time.1 @@ -40,7 +40,8 @@ .Nd time command execution .Sh SYNOPSIS .Nm -.Op Fl alp +.Op Fl al +.Op Fl h | Fl p .Op Fl o Ar file .Ar command .Sh DESCRIPTION @@ -73,6 +74,9 @@ If the flag is used, append to the specified file rather than overwriting it. Otherwise, this option has no effect. +.It Fl h +Print times in a human friendly format. Times are printed in minutes, hours, +etc. as appropiate. .It Fl l The contents of the .Em rusage diff --git a/usr.bin/time/time.c b/usr.bin/time/time.c index e802e4dbb9c0..5a35f68ee100 100644 --- a/usr.bin/time/time.c +++ b/usr.bin/time/time.c @@ -61,6 +61,7 @@ static const char rcsid[] = #include <signal.h> static int getstathz __P((void)); +static void humantime __P((FILE *, long, long)); static void usage __P((void)); int @@ -69,19 +70,22 @@ main(argc, argv) char **argv; { register int pid; - int aflag, ch, lflag, status, pflag; + int aflag, ch, hflag, lflag, status, pflag; struct timeval before, after; struct rusage ru; FILE *out = stderr; char *ofn = NULL; int exitonsig = 0; /* Die with same signal as child */ - aflag = lflag = pflag = 0; - while ((ch = getopt(argc, argv, "alo:p")) != -1) + aflag = hflag = lflag = pflag = 0; + while ((ch = getopt(argc, argv, "ahlo:p")) != -1) switch((char)ch) { case 'a': aflag = 1; break; + case 'h': + hflag = 1; + break; case 'l': lflag = 1; break; @@ -144,6 +148,13 @@ main(argc, argv) ru.ru_utime.tv_sec, ru.ru_utime.tv_usec/10000); fprintf(out, "sys %ld.%02ld\n", ru.ru_stime.tv_sec, ru.ru_stime.tv_usec/10000); + } else if (hflag) { + humantime(out, after.tv_sec, after.tv_usec/10000); + fprintf(out, " real%c", hflag ? '\t' : ' '); + humantime(out, ru.ru_utime.tv_sec, ru.ru_utime.tv_usec/10000); + fprintf(out, " user%c", hflag ? '\t' : ' '); + humantime(out, ru.ru_stime.tv_sec, ru.ru_stime.tv_usec/10000); + fprintf(out, " sys\n"); } else { fprintf(out, "%9ld.%02ld real ", after.tv_sec, after.tv_usec/10000); @@ -207,7 +218,7 @@ main(argc, argv) static void usage() { - fprintf(stderr, "usage: time [-alp] [-o file] command\n"); + fprintf(stderr, "usage: time [-al] [-h|-p] [-o file] command\n"); exit(1); } @@ -228,3 +239,28 @@ getstathz() err(1, "sysctl kern.clockrate"); return clockrate.stathz; } + +static void +humantime(out, sec, usec) + FILE *out; + long sec; + long usec; +{ + long days, hrs, mins; + + days = sec / (60L * 60 * 24); + sec %= (60L * 60 * 24); + hrs = sec / (60L * 60); + sec %= (60L * 60); + mins = sec / 60; + sec %= 60; + + fprintf(out, "\t"); + if (days) + fprintf(out, "%ldd", days); + if (hrs) + fprintf(out, "%ldh", hrs); + if (mins) + fprintf(out, "%ldm", mins); + fprintf(out, "%ld.%02lds", sec, usec); +} |