BSD 4_3_Tahoe release
[unix-history] / usr / src / bin / time.c
index d2aae1a..e659ddd 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)time.c      4.5 (Berkeley) 7/1/83";
+static char *sccsid = "@(#)time.c      4.7 (Berkeley) 11/17/87";
 #endif
 
 /*
 #endif
 
 /*
@@ -15,14 +15,19 @@ main(argc, argv)
        int argc;
        char **argv;
 {
        int argc;
        char **argv;
 {
-       int status;
+       int status, lflag = 0;
        register int p;
        struct timeval before, after;
        struct rusage ru;
 
        if (argc<=1)
                exit(0);
        register int p;
        struct timeval before, after;
        struct rusage ru;
 
        if (argc<=1)
                exit(0);
-       gettimeofday(&before, 0);
+       if (strcmp(argv[1], "-l") == 0) {
+               lflag++;
+               argc--;
+               argv++;
+       }
+       gettimeofday(&before, (struct timezone *)NULL);
        p = fork();
        if (p < 0) {
                perror("time");
        p = fork();
        if (p < 0) {
                perror("time");
@@ -33,11 +38,11 @@ main(argc, argv)
                perror(argv[1]);
                exit(1);
        }
                perror(argv[1]);
                exit(1);
        }
-       signal(SIGINT, SIG_IGN);
-       signal(SIGQUIT, SIG_IGN);
+       (void)signal(SIGINT, SIG_IGN);
+       (void)signal(SIGQUIT, SIG_IGN);
        while (wait3(&status, 0, &ru) != p)
                ;
        while (wait3(&status, 0, &ru) != p)
                ;
-       gettimeofday(&after, 0);
+       gettimeofday(&after, (struct timezone *)NULL);
        if ((status&0377) != 0)
                fprintf(stderr, "Command terminated abnormally.\n");
        after.tv_sec -= before.tv_sec;
        if ((status&0377) != 0)
                fprintf(stderr, "Command terminated abnormally.\n");
        after.tv_sec -= before.tv_sec;
@@ -48,6 +53,41 @@ main(argc, argv)
        printt("user", &ru.ru_utime);
        printt("sys ", &ru.ru_stime);
        fprintf(stderr, "\n");
        printt("user", &ru.ru_utime);
        printt("sys ", &ru.ru_stime);
        fprintf(stderr, "\n");
+       if (lflag) {
+               int hz = 100;                   /* XXX */
+               long ticks;
+
+               ticks = hz * (ru.ru_utime.tv_sec + ru.ru_stime.tv_sec) +
+                    hz * (ru.ru_utime.tv_usec + ru.ru_stime.tv_usec) / 1000000;
+               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 (status>>8);
 }
 
        exit (status>>8);
 }
 
@@ -56,5 +96,5 @@ printt(s, tv)
        struct timeval *tv;
 {
 
        struct timeval *tv;
 {
 
-       fprintf(stderr, "%9d.%01d %s ", tv->tv_sec, tv->tv_usec/100000, s);
+       fprintf(stderr, "%9ld.%02ld %s ", tv->tv_sec, tv->tv_usec/10000, s);
 }
 }