Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 22 Jul 1998 09:26:03 -0700 (PDT)
From:      "Steven G. Kargl" <kargl@troutmask.apl.washington.edu>
To:        FreeBSD-gnats-submit@FreeBSD.ORG
Subject:   bin/7368: added options to /usr/bin/time
Message-ID:  <199807221626.JAA27203@troutmask.apl.washington.edu>

next in thread | raw e-mail | index | archive | help

>Number:         7368
>Category:       bin
>Synopsis:       Added options to /usr/bin/time
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:
>Keywords:
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Wed Jul 22 09:30:01 PDT 1998
>Last-Modified:
>Originator:     Steven G. Kargl
>Organization:
Applied Physics Lab/Univ. of Washington
>Release:        FreeBSD 3.0-CURRENT i386
>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);
>Audit-Trail:
>Unformatted:

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199807221626.JAA27203>