add -l to print whole rusage
authorMike Karels <karels@ucbvax.Berkeley.EDU>
Sun, 1 Nov 1987 12:39:39 +0000 (04:39 -0800)
committerMike Karels <karels@ucbvax.Berkeley.EDU>
Sun, 1 Nov 1987 12:39:39 +0000 (04:39 -0800)
SCCS-vsn: usr.bin/time/time.c 4.6

usr/src/usr.bin/time/time.c

index 1b6edd6..d10082b 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)time.c      4.5 (Berkeley) %G%";
+static char *sccsid = "@(#)time.c      4.6 (Berkeley) %G%";
 #endif
 
 /*
 #endif
 
 /*
@@ -15,13 +15,18 @@ 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);
+       if (strcmp(argv[1], "-l") == 0) {
+               lflag++;
+               argc--;
+               argv++;
+       }
        gettimeofday(&before, 0);
        p = fork();
        if (p < 0) {
        gettimeofday(&before, 0);
        p = fork();
        if (p < 0) {
@@ -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, "%10D  %s\n",
+                       ru.ru_maxrss, "maximum resident set size");
+               fprintf(stderr, "%10D  %s\n",
+                       ru.ru_ixrss / ticks, "average shared memory size");
+               fprintf(stderr, "%10D  %s\n",
+                       ru.ru_idrss / ticks, "average unshared data size");
+               fprintf(stderr, "%10D  %s\n",
+                       ru.ru_isrss / ticks, "average unshared stack size");
+               fprintf(stderr, "%10D  %s\n",
+                       ru.ru_minflt, "page reclaims");
+               fprintf(stderr, "%10D  %s\n",
+                       ru.ru_majflt, "page faults");
+               fprintf(stderr, "%10D  %s\n",
+                       ru.ru_nswap, "swaps");
+               fprintf(stderr, "%10D  %s\n",
+                       ru.ru_inblock, "block input operations");
+               fprintf(stderr, "%10D  %s\n",
+                       ru.ru_oublock, "block output operations");
+               fprintf(stderr, "%10D  %s\n",
+                       ru.ru_msgsnd, "messages sent");
+               fprintf(stderr, "%10D  %s\n",
+                       ru.ru_msgrcv, "messages received");
+               fprintf(stderr, "%10D  %s\n",
+                       ru.ru_nsignals, "signals received");
+               fprintf(stderr, "%10D  %s\n",
+                       ru.ru_nvcsw, "voluntary context switches");
+               fprintf(stderr, "%10D  %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, "%9d.%02d %s ", tv->tv_sec, tv->tv_usec/10000, s);
 }
 }