From kargl@troutmask.apl.washington.edu  Wed Jul 22 09:24:09 1998
Received: from troutmask.apl.washington.edu (troutmask.apl.washington.edu [128.95.76.54])
          by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id JAA01079
          for <FreeBSD-gnats-submit@freebsd.org>; Wed, 22 Jul 1998 09:24:05 -0700 (PDT)
          (envelope-from kargl@troutmask.apl.washington.edu)
Received: (from kargl@localhost)
	by troutmask.apl.washington.edu (8.8.8/8.8.5) id JAA27203;
	Wed, 22 Jul 1998 09:26:03 -0700 (PDT)
Message-Id: <199807221626.JAA27203@troutmask.apl.washington.edu>
Date: Wed, 22 Jul 1998 09:26:03 -0700 (PDT)
From: "Steven G. Kargl" <kargl@troutmask.apl.washington.edu>
Reply-To: kargl@troutmask.apl.washington.edu
To: FreeBSD-gnats-submit@freebsd.org
Subject: added options to /usr/bin/time
X-Send-Pr-Version: 3.2

>Number:         7368
>Category:       bin
>Synopsis:       Added options to /usr/bin/time
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Wed Jul 22 09:30:01 PDT 1998
>Closed-Date:    Fri Jul 24 00:19:39 PDT 1998
>Last-Modified:  Fri Jul 24 00:20:30 PDT 1998
>Originator:     Steven G. Kargl
>Release:        FreeBSD 3.0-CURRENT i386
>Organization:
Applied Physics Lab/Univ. of Washington
>Environment:

>Description:

By default, /usr/bin/time writes its output to stderr.  Two options
have been added to time(1) to write output to an alternative destination.
Option "-f filename" will write to filename, and filename can be - to
write to stdout.  Option "-a filename" will append the output to filename.
Time(1) man page has been updated to reflect the change.

>How-To-Repeat:

>Fix:
*** time.1.orig	Mon May 11 12:58:46 1998
--- time.1	Mon May 11 13:02:36 1998
***************
*** 39,44 ****
--- 39,46 ----
  .Nd time command execution
  .Sh SYNOPSIS
  .Nm
+ .Op Fl a Ar file
+ .Op Fl f Ar file
  .Op Fl l
  .Ar command
  .Sh DESCRIPTION
***************
*** 66,71 ****
--- 68,95 ----
  .Pp
  Available options:
  .Bl -tag -width Ds
+ .It Fl a Ar file
+ Append the output of
+ .Nm
+ to 
+ .Ar file
+ instead of writing to stderr.
+ .It Fl f Ar file
+ Write the output to 
+ .Ar file
+ instead of stderr.  If
+ .Ar file
+ exists, then 
+ .Nm
+ will overwrite the file if premissions permit such an operation.
+ The output can be sent to stdout by giving
+ a file name
+ .Do
+ -
+ .Dc
+ to the 
+ .Fl f
+ option.
  .It Fl l
  The contents of the
  .Em rusage
*** time.c.orig	Wed Aug 13 23:48:59 1997
--- time.c	Mon May 11 12:57:39 1998
***************
*** 56,61 ****
--- 56,62 ----
  #include <err.h>
  #include <stdio.h>
  #include <unistd.h>
+ #include <string.h>
  
  static int getstathz __P((void));
  static void usage __P((void));
***************
*** 65,78 ****
  	int argc;
  	char **argv;
  {
  	register int pid;
  	int ch, status, lflag;
  	struct timeval before, after;
  	struct rusage ru;
  
  	lflag = 0;
! 	while ((ch = getopt(argc, argv, "l")) != -1)
  		switch((char)ch) {
  		case 'l':
  			lflag = 1;
  			break;
--- 66,101 ----
  	int argc;
  	char **argv;
  {
+ 	extern char *optarg;
+ 	extern int optind;
+ 
  	register int pid;
  	int ch, status, lflag;
  	struct timeval before, after;
  	struct rusage ru;
+ 	FILE *out = NULL;
  
  	lflag = 0;
! 	while ((ch = getopt(argc, argv, "a:f:l")) != -1)
  		switch((char)ch) {
+ 		case 'a':
+ 			if (out)
+ 				err(1, optarg);
+ 			out = fopen(optarg, "a");
+ 			if (!out)
+ 				err(1, optarg);
+ 			break;
+ 		case 'f':
+ 			if (out)
+ 				err(1, optarg);
+ 			if (strcmp(optarg, "-") == 0)
+ 				out = stdout;
+ 			else {
+ 				out = fopen(optarg, "w");
+ 				if (!out)
+ 					err(1, optarg);
+ 			}
+ 			break;
  		case 'l':
  			lflag = 1;
  			break;
***************
*** 85,90 ****
--- 108,116 ----
  		exit(0);
  	argv += optind;
  
+ 	if (!out)
+ 		out = stderr;
+ 
  	gettimeofday(&before, (struct timezone *)NULL);
  	switch(pid = vfork()) {
  	case -1:			/* error */
***************
*** 107,116 ****
  	after.tv_usec -= before.tv_usec;
  	if (after.tv_usec < 0)
  		after.tv_sec--, after.tv_usec += 1000000;
! 	fprintf(stderr, "%9ld.%02ld real ", after.tv_sec, after.tv_usec/10000);
! 	fprintf(stderr, "%9ld.%02ld user ",
  	    ru.ru_utime.tv_sec, ru.ru_utime.tv_usec/10000);
! 	fprintf(stderr, "%9ld.%02ld sys\n",
  	    ru.ru_stime.tv_sec, ru.ru_stime.tv_usec/10000);
  	if (lflag) {
  		int hz = getstathz();
--- 133,142 ----
  	after.tv_usec -= before.tv_usec;
  	if (after.tv_usec < 0)
  		after.tv_sec--, after.tv_usec += 1000000;
! 	fprintf(out, "%9ld.%02ld real ", after.tv_sec, after.tv_usec/10000);
! 	fprintf(out, "%9ld.%02ld user ",
  	    ru.ru_utime.tv_sec, ru.ru_utime.tv_usec/10000);
! 	fprintf(out, "%9ld.%02ld sys\n",
  	    ru.ru_stime.tv_sec, ru.ru_stime.tv_usec/10000);
  	if (lflag) {
  		int hz = getstathz();
***************
*** 126,158 ****
  		if (ticks == 0)
  			ticks = 1;
  
! 		fprintf(stderr, "%10ld  %s\n",
  			ru.ru_maxrss, "maximum resident set size");
! 		fprintf(stderr, "%10ld  %s\n",
  			ru.ru_ixrss / ticks, "average shared memory size");
! 		fprintf(stderr, "%10ld  %s\n",
  			ru.ru_idrss / ticks, "average unshared data size");
! 		fprintf(stderr, "%10ld  %s\n",
  			ru.ru_isrss / ticks, "average unshared stack size");
! 		fprintf(stderr, "%10ld  %s\n",
  			ru.ru_minflt, "page reclaims");
! 		fprintf(stderr, "%10ld  %s\n",
  			ru.ru_majflt, "page faults");
! 		fprintf(stderr, "%10ld  %s\n",
  			ru.ru_nswap, "swaps");
! 		fprintf(stderr, "%10ld  %s\n",
  			ru.ru_inblock, "block input operations");
! 		fprintf(stderr, "%10ld  %s\n",
  			ru.ru_oublock, "block output operations");
! 		fprintf(stderr, "%10ld  %s\n",
  			ru.ru_msgsnd, "messages sent");
! 		fprintf(stderr, "%10ld  %s\n",
  			ru.ru_msgrcv, "messages received");
! 		fprintf(stderr, "%10ld  %s\n",
  			ru.ru_nsignals, "signals received");
! 		fprintf(stderr, "%10ld  %s\n",
  			ru.ru_nvcsw, "voluntary context switches");
! 		fprintf(stderr, "%10ld  %s\n",
  			ru.ru_nivcsw, "involuntary context switches");
  	}
  	exit (WIFEXITED(status) ? WEXITSTATUS(status) : EXIT_FAILURE);
--- 152,184 ----
  		if (ticks == 0)
  			ticks = 1;
  
! 		fprintf(out, "%10ld  %s\n",
  			ru.ru_maxrss, "maximum resident set size");
! 		fprintf(out, "%10ld  %s\n",
  			ru.ru_ixrss / ticks, "average shared memory size");
! 		fprintf(out, "%10ld  %s\n",
  			ru.ru_idrss / ticks, "average unshared data size");
! 		fprintf(out, "%10ld  %s\n",
  			ru.ru_isrss / ticks, "average unshared stack size");
! 		fprintf(out, "%10ld  %s\n",
  			ru.ru_minflt, "page reclaims");
! 		fprintf(out, "%10ld  %s\n",
  			ru.ru_majflt, "page faults");
! 		fprintf(out, "%10ld  %s\n",
  			ru.ru_nswap, "swaps");
! 		fprintf(out, "%10ld  %s\n",
  			ru.ru_inblock, "block input operations");
! 		fprintf(out, "%10ld  %s\n",
  			ru.ru_oublock, "block output operations");
! 		fprintf(out, "%10ld  %s\n",
  			ru.ru_msgsnd, "messages sent");
! 		fprintf(out, "%10ld  %s\n",
  			ru.ru_msgrcv, "messages received");
! 		fprintf(out, "%10ld  %s\n",
  			ru.ru_nsignals, "signals received");
! 		fprintf(out, "%10ld  %s\n",
  			ru.ru_nvcsw, "voluntary context switches");
! 		fprintf(out, "%10ld  %s\n",
  			ru.ru_nivcsw, "involuntary context switches");
  	}
  	exit (WIFEXITED(status) ? WEXITSTATUS(status) : EXIT_FAILURE);
>Release-Note:
>Audit-Trail:

From: smoergrd@oslo.geco-prakla.slb.com (Dag-Erling Coidan Smrgrav)
To: kargl@troutmask.apl.washington.edu
Cc: FreeBSD-gnats-submit@freebsd.org
Subject: Re: bin/7368: added options to /usr/bin/time
Date: 23 Jul 1998 10:12:03 +0200

 "Steven G. Kargl" <kargl@troutmask.apl.washington.edu> writes:
 > By default, /usr/bin/time writes its output to stderr.  Two options
 > have been added to time(1) to write output to an alternative destination.
 > Option "-f filename" will write to filename, and filename can be - to
 > write to stdout.  Option "-a filename" will append the output to filename.
 > Time(1) man page has been updated to reflect the change.
 
 Two words: output redirection. You may consider reading the sh(1) man
 page to explore the possibilities offered by this feature.
 
 DES
 -- 
 Dag-Erling Smrgrav - smoergrd@oslo.geco-prakla.slb.com

From: "Niall Smart" <nialls@euristix.ie>
To: FreeBSD-gnats-submit@freebsd.org, kargl@troutmask.apl.washington.edu
Cc:  Subject: Re: bin/7368: added options to /usr/bin/time
Date: Thu, 23 Jul 1998 10:46:15 +0100

 > >Number:         7368
 > >Synopsis:       Added options to /usr/bin/time
 
 > By default, /usr/bin/time writes its output to stderr.  Two options
 > have been added to time(1) to write output to an alternative destination.
 > Option "-f filename" will write to filename, and filename can be - to
 > write to stdout.  Option "-a filename" will append the output to filename.
 > Time(1) man page has been updated to reflect the change.
 
 Your shell should handle I/O redirection.  I do not think this patch 
 should be integrated.  These options violate The UNIX Philosophy.
 
 Niall 

From: "Steven G. Kargl" <kargl@apl.washington.edu>
To: freebsd-gnats-submit@freebsd.org, kargl@troutmask.apl.washington.edu
Cc:  Subject: Re: bin/7368: Added options to /usr/bin/time
Date: Thu, 23 Jul 1998 09:45:43 -0700

 I've sent followups to both Dag-Erling and Niall in private
 email before I realized,  I could/should document my rebuttal
 here.
 
 How does one redirect via a shell the output of /usr/bin/time
 without redirecting the output from the command that is being
 timed. The answer is you can't, and is the motivation for the new
 options.
 
 -- 
 Steve
 
 finger kargl@troutmask.apl.washington.edu
 http://troutmask.apl.washington.edu/~clesceri/kargl.html

From: Poul-Henning Kamp <phk@critter.freebsd.dk>
To: "Steven G. Kargl" <kargl@apl.washington.edu>
Cc: freebsd-bugs@FreeBSD.ORG, freebsd-gnats-submit@FreeBSD.ORG
Subject: Re: bin/7368: Added options to /usr/bin/time 
Date: Thu, 23 Jul 1998 20:27:49 +0200

 In message <199807231650.JAA01687@freefall.freebsd.org>, "Steven G. Kargl" writ
 es:
 >The following reply was made to PR bin/7368; it has been noted by GNATS.
 >
 >From: "Steven G. Kargl" <kargl@apl.washington.edu>
 >To: freebsd-gnats-submit@freebsd.org, kargl@troutmask.apl.washington.edu
 >Cc:  Subject: Re: bin/7368: Added options to /usr/bin/time
 >Date: Thu, 23 Jul 1998 09:45:43 -0700
 >
 > I've sent followups to both Dag-Erling and Niall in private
 > email before I realized,  I could/should document my rebuttal
 > here.
 > 
 > How does one redirect via a shell the output of /usr/bin/time
 > without redirecting the output from the command that is being
 > timed. The answer is you can't, and is the motivation for the new
 > options.
 
 
 will
 
 	time csh -c "foocommand >& foo.out" >& time.out
 
 do ?
 
 (I'm not against the addition as such, as long as current
 behaviour isn't changed.)
 
 --
 Poul-Henning Kamp             FreeBSD coreteam member
 phk@FreeBSD.ORG               "Real hackers run -current on their laptop."
 "ttyv0" -- What UNIX calls a $20K state-of-the-art, 3D, hi-res color terminal

From: "Steven G. Kargl" <kargl@troutmask.apl.washington.edu>
To: phk@critter.freebsd.dk (Poul-Henning Kamp)
Cc: freebsd-bugs@FreeBSD.ORG, freebsd-gnats-submit@FreeBSD.ORG
Subject: Re: bin/7368: Added options to /usr/bin/time
Date: Thu, 23 Jul 1998 11:52:30 -0700 (PDT)

 According to Poul-Henning Kamp:
 > In message <199807231650.JAA01687@freefall.freebsd.org>, "Steven G. Kargl" writ
 > es:
 > >The following reply was made to PR bin/7368; it has been noted by GNATS.
 > >
 > >From: "Steven G. Kargl" <kargl@apl.washington.edu>
 > >To: freebsd-gnats-submit@freebsd.org, kargl@troutmask.apl.washington.edu
 > >Cc:  Subject: Re: bin/7368: Added options to /usr/bin/time
 > >Date: Thu, 23 Jul 1998 09:45:43 -0700
 > >
 > > I've sent followups to both Dag-Erling and Niall in private
 > > email before I realized,  I could/should document my rebuttal
 > > here.
 > > 
 > > How does one redirect via a shell the output of /usr/bin/time
 > > without redirecting the output from the command that is being
 > > timed. The answer is you can't, and is the motivation for the new
 > > options.
 > 
 > 
 > will
 > 
 > 	time csh -c "foocommand >& foo.out" >& time.out
 > 
 > do ?
 > 
 > (I'm not against the addition as such, as long as current
 > behaviour isn't changed.)
 > 
 
 Current behavior is unchanged.  I've added options.  Your suggest
 seems to work (I learn something new everyday).
 
 However, consider
 
 foreach i (*.dat)
 time -a time.out foocommand $i
 end
 
 foreach i (*.c)
 time csh -c "foocommand $i" >>& time.out
 end
 
 One of these seems to be easier to remember for those who
 are not great at shell programmer.
 
 The former times the execution of foocommand while the later times
 the execution of csh + foocommand.  If the execution time of csh
 is small in comparison the execution time of foocommand, then ones
 statistics may not be too tainted.  But, what happens if csh time
 swamps foocommand.
 
 -- 
 Steve
 
 finger kargl@troutmask.apl.washington.edu
 http://troutmask.apl.washington.edu/~clesceri/kargl.html
State-Changed-From-To: open->closed 
State-Changed-By: phk 
State-Changed-When: Fri Jul 24 00:19:39 PDT 1998 
State-Changed-Why:  
The peter principle at work again. 

committed, thanks! 
>Unformatted:
