use high precision time calls
authorSam Leffler <sam@ucbvax.Berkeley.EDU>
Fri, 4 Feb 1983 01:13:16 +0000 (17:13 -0800)
committerSam Leffler <sam@ucbvax.Berkeley.EDU>
Fri, 4 Feb 1983 01:13:16 +0000 (17:13 -0800)
SCCS-vsn: bin/csh/csh.c 4.10
SCCS-vsn: bin/csh/csh.h 4.6
SCCS-vsn: bin/csh/proc.c 4.8
SCCS-vsn: bin/csh/proc.h 4.3
SCCS-vsn: bin/csh/time.c 4.3

usr/src/bin/csh/csh.c
usr/src/bin/csh/csh.h
usr/src/bin/csh/proc.c
usr/src/bin/csh/proc.h
usr/src/bin/csh/time.c

index fb2aa79..74370a9 100644 (file)
@@ -1,4 +1,4 @@
-static char *sccsid = "@(#)csh.c 4.9 %G%";
+static char *sccsid = "@(#)csh.c 4.10 %G%";
 
 #include "sh.h"
 #include <sys/ioctl.h>
 
 #include "sh.h"
 #include <sys/ioctl.h>
@@ -871,7 +871,7 @@ mailchk()
        for (; *vp; vp++) {
                if (stat(*vp, &stb) < 0)
                        continue;
        for (; *vp; vp++) {
                if (stat(*vp, &stb) < 0)
                        continue;
-               new = stb.st_mtime > time0;
+               new = stb.st_mtime > time0.tv_sec;
                if (stb.st_size == 0 || stb.st_atime > stb.st_mtime ||
                    (stb.st_atime < chktim && stb.st_mtime < chktim) ||
                    loginsh && !new)
                if (stb.st_size == 0 || stb.st_atime > stb.st_mtime ||
                    (stb.st_atime < chktim && stb.st_mtime < chktim) ||
                    loginsh && !new)
index 3f40060..69d77e1 100644 (file)
@@ -1,4 +1,4 @@
-/* csh.h 4.5 82/12/30 */
+/* csh.h 4.6 83/02/03 */
 
 #include "sh.local.h"
 #include <time.h>
 
 #include "sh.local.h"
 #include <time.h>
@@ -57,7 +57,7 @@ char  *file;                  /* Name of shell file for $0 */
 char   *err;                   /* Error message from scanner/parser */
 int    errno;                  /* Error from C library routines */
 char   *shtemp;                /* Temp name for << shell files in /tmp */
 char   *err;                   /* Error message from scanner/parser */
 int    errno;                  /* Error from C library routines */
 char   *shtemp;                /* Temp name for << shell files in /tmp */
-time_t time0;                  /* Time at which the shell started */
+struct timeval time0;          /* Time at which the shell started */
 struct rusage ru0;
 
 /*
 struct rusage ru0;
 
 /*
index b92a066..aa296f6 100644 (file)
@@ -1,4 +1,4 @@
-static char *sccsid = "@(#)proc.c      4.7 (Berkeley) 82/12/30";
+static char *sccsid = "@(#)proc.c      4.8 (Berkeley) 83/02/03";
 
 #include "sh.h"
 #include "sh.dir.h"
 
 #include "sh.h"
 #include "sh.dir.h"
@@ -57,7 +57,7 @@ found:
                        time_t oldcutimes, oldcstimes;
                        oldcutimes = shtimes.tms_cutime;
                        oldcstimes = shtimes.tms_cstime;
                        time_t oldcutimes, oldcstimes;
                        oldcutimes = shtimes.tms_cutime;
                        oldcstimes = shtimes.tms_cstime;
-                       time(&pp->p_etime);
+                       gettimeofday(&pp->p_etime, (struct timezone *)0);
                        times(&shtimes);
                        pp->p_utime = shtimes.tms_cutime - oldcutimes;
                        pp->p_stime = shtimes.tms_cstime - oldcstimes;
                        times(&shtimes);
                        pp->p_utime = shtimes.tms_cutime - oldcutimes;
                        pp->p_stime = shtimes.tms_cstime - oldcstimes;
@@ -398,7 +398,7 @@ palloc(pid, t)
        }
        pp->p_next = proclist.p_next;
        proclist.p_next = pp;
        }
        pp->p_next = proclist.p_next;
        proclist.p_next = pp;
-       time(&pp->p_btime);
+       gettimeofday(&pp->p_btime, (struct timezone *)0);
 }
 
 padd(t)
 }
 
 padd(t)
@@ -621,8 +621,8 @@ prcomd:
                        if (linp != linbuf)
                                printf("\n\t");
                        { static struct rusage zru;
                        if (linp != linbuf)
                                printf("\n\t");
                        { static struct rusage zru;
-                         prusage(&zru, &pp->p_rusage,
-                             pp->p_etime - pp->p_btime);
+                         prusage(&zru, &pp->p_rusage, &pp->p_etime,
+                           &pp->p_btime);
                        }
                }
                if (tp == pp->p_friends) {
                        }
                }
                if (tp == pp->p_friends) {
@@ -646,18 +646,21 @@ prcomd:
 ptprint(tp)
        register struct process *tp;
 {
 ptprint(tp)
        register struct process *tp;
 {
-       time_t tetime = 0;
+       struct timeval tetime, diff;
+       static struct timeval ztime;
        struct rusage ru;
        static struct rusage zru;
        register struct process *pp = tp;
 
        ru = zru;
        struct rusage ru;
        static struct rusage zru;
        register struct process *pp = tp;
 
        ru = zru;
+       tetime = ztime;
        do {
                ruadd(&ru, &pp->p_rusage);
        do {
                ruadd(&ru, &pp->p_rusage);
-               if (pp->p_etime - pp->p_btime > tetime)
-                       tetime = pp->p_etime - pp->p_btime;
+               tvsub(&diff, &pp->p_etime, &pp->p_btime);
+               if (timercmp(&diff, &tetime, >))
+                       tetime = diff;
        } while ((pp = pp->p_friends) != tp);
        } while ((pp = pp->p_friends) != tp);
-       prusage(&zru, &ru, tetime);
+       prusage(&zru, &ru, &tetime, &ztime);
 }
 
 /*
 }
 
 /*
index 0cb12a4..45e965e 100644 (file)
@@ -1,4 +1,4 @@
-/* proc.h 4.2 %G% */
+/* proc.h 4.3 %G% */
 
 /*
  * C shell - process structure declarations
 
 /*
  * C shell - process structure declarations
@@ -22,11 +22,11 @@ struct process      {
        short   p_pid;
        short   p_jobid;                /* pid of job leader */
        /* if a job is stopped/background p_jobid gives its pgrp */
        short   p_pid;
        short   p_jobid;                /* pid of job leader */
        /* if a job is stopped/background p_jobid gives its pgrp */
-       time_t  p_btime;                /* begin time */
-       time_t  p_etime;                /* end time */
-       long    p_stime;                /* system cpu time */
-       long    p_utime;                /* user cpu time */
+       struct  timeval p_btime;        /* begin time */
+       struct  timeval p_etime;        /* end time */
        struct  rusage p_rusage;
        struct  rusage p_rusage;
+       long    p_utime;        /* XXX */
+       long    p_stime;        /* XXX */
        char    *p_command;             /* first PMAXLEN chars of command */
 };
 
        char    *p_command;             /* first PMAXLEN chars of command */
 };
 
index e9ed8b1..4ce20a9 100644 (file)
@@ -1,4 +1,4 @@
-/*     time.c  4.2     82/12/30        */
+/*     time.c  4.3     83/02/03        */
 
 #include "sh.h"
 
 
 #include "sh.h"
 
@@ -12,7 +12,7 @@ settimes()
 {
        struct rusage ruch;
 
 {
        struct rusage ruch;
 
-       time(&time0);
+       gettimeofday(&time0, (struct timezone *)0);
        getrusage(RUSAGE_SELF, &ru0);
        getrusage(RUSAGE_CHILDREN, &ruch);
        ruadd(&ru0, &ruch);
        getrusage(RUSAGE_SELF, &ru0);
        getrusage(RUSAGE_CHILDREN, &ruch);
        ruadd(&ru0, &ruch);
@@ -24,14 +24,14 @@ settimes()
  */
 dotime()
 {
  */
 dotime()
 {
-       time_t timedol;
+       struct timeval timedol;
        struct rusage ru1, ruch;
 
        getrusage(RUSAGE_SELF, &ru1);
        getrusage(RUSAGE_CHILDREN, &ruch);
        ruadd(&ru1, &ruch);
        struct rusage ru1, ruch;
 
        getrusage(RUSAGE_SELF, &ru1);
        getrusage(RUSAGE_CHILDREN, &ruch);
        ruadd(&ru1, &ruch);
-       time(&timedol);
-       prusage(&ru0, &ru1, timedol - time0);
+       gettimeofday(&timedol, (struct timezone *)0);
+       prusage(&ru0, &ru1, &timedol, &time0);
 }
 
 /*
 }
 
 /*
@@ -75,9 +75,9 @@ ruadd(ru, ru2)
        while (--cnt > 0);
 }
 
        while (--cnt > 0);
 }
 
-prusage(r0, r1, sec)
+prusage(r0, r1, e, b)
        register struct rusage *r0, *r1;
        register struct rusage *r0, *r1;
-       time_t sec;
+       struct timeval *e, *b;
 {
        register time_t t =
            (r1->ru_utime.tv_sec-r0->ru_utime.tv_sec)*100+
 {
        register time_t t =
            (r1->ru_utime.tv_sec-r0->ru_utime.tv_sec)*100+
@@ -87,6 +87,8 @@ prusage(r0, r1, sec)
        register char *cp;
        register int i;
        register struct varent *vp = adrof("time");
        register char *cp;
        register int i;
        register struct varent *vp = adrof("time");
+       int ms =
+           (e->tv_sec-b->tv_sec)*100 + (e->tv_usec-b->tv_usec)/10000;
 
        cp = "%Uu %Ss %E %P %X+%Dk %I+%Oio %Fpf+%Ww";
        if (vp && vp->vec[0] && vp->vec[1])
 
        cp = "%Uu %Ss %E %P %X+%Dk %I+%Oio %Fpf+%Ww";
        if (vp && vp->vec[0] && vp->vec[1])
@@ -105,11 +107,11 @@ prusage(r0, r1, sec)
                break;
 
        case 'E':
                break;
 
        case 'E':
-               psecs(sec);
+               psecs(ms / 100);
                break;
 
        case 'P':
                break;
 
        case 'P':
-               printf("%d%%", (int) (t / ((sec ? sec : 1))));
+               printf("%d%%", (int) (t*100 / ((ms ? ms : 1))));
                break;
 
        case 'W':
                break;
 
        case 'W':