NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: standards/18257: POSIX.2-1992: ps(1)'s TIME column has the wrong format



The following reply was made to PR standards/18257; it has been noted by GNATS.

From: Julian Djamil Fagir <gnrp%komkon2.de@localhost>
To: gnats-bugs%NetBSD.org@localhost
Cc: 
Subject: Re: standards/18257: POSIX.2-1992: ps(1)'s TIME column has the
 wrong format
Date: Tue, 14 Feb 2012 15:42:15 +0100

 --MP_/dbwTx/.nKTnAExi31fxRAl9
 Content-Type: text/plain; charset=US-ASCII
 Content-Transfer-Encoding: 7bit
 Content-Disposition: inline
 
 Hi,
 
 the attached patches should solve that issue.
 
 Though there's one issue: This patch introduces POSIX compliancy, but
 decreases precision. Before, you had the cputime measured in centiseconds,
 while POSIX requires it to be at most seconds.
 
 You could either introduce another keyword - e.g. pcputime or ptime (p for
 precision) to display them again - or dump this proposal and be non-posix
 compliant or dump the precision and be posix-compliant.
 
 Which is the way to go?
 
 Regards, Julian
 --MP_/dbwTx/.nKTnAExi31fxRAl9
 Content-Type: text/x-patch
 Content-Transfer-Encoding: 7bit
 Content-Disposition: attachment; filename=extern.h.diff
 
 --- bin/ps/extern.h
 +++ bin/ps/extern.h
 @@ -76,10 +76,11 @@
  void   pcpu(void *, VARENT *, int);
  void   pmem(void *, VARENT *, int);
  void   pnice(void *, VARENT *, int);
  void   pri(void *, VARENT *, int);
  void   printheader(void);
 +void   printtime(void *, VARENT *, int, int);
  void   putimeval(void *, VARENT *, int);
  void   pvar(void *, VARENT *, int);
  void   rgname(void *, VARENT *, int);
  void   rssize(void *, VARENT *, int);
  void   runame(void *, VARENT *, int);
 
 
 --MP_/dbwTx/.nKTnAExi31fxRAl9
 Content-Type: text/x-patch
 Content-Transfer-Encoding: 7bit
 Content-Disposition: attachment; filename=print.c.diff
 
 --- bin/ps/print.c
 +++ bin/ps/print.c
 @@ -102,10 +102,12 @@
  
  static time_t now;
  
  #define       min(a,b)        ((a) <= (b) ? (a) : (b))
  
 +#define PHOURS                0x01
 +
  static int
  iwidth(u_int64_t v)
  {
        u_int64_t nlim, lim;
        int w = 1;
 @@ -846,14 +848,29 @@
  }
  
  void
  elapsed(void *arg, VARENT *ve, int mode)
  {
 +      printtime(arg, ve, mode, 0);
 +}
 +
 +void
 +cputime(void *arg, VARENT *ve, int mode)
 +{
 +      printtime(arg, ve, mode, PHOURS);
 +}
 +
 +/* printmod defines whether we want to print the hours. POSIX specifies the
 + * cputime to be printed [dd-]hh:mm:ss, while the elapsed time should be 
printed
 + * as [[dd-]hh:]mm:ss. */
 +void
 +printtime(void *arg, VARENT *ve, int mode, int printmod)
 +{
        struct kinfo_proc2 *k;
        VAR *v;
        int32_t origseconds, secs, mins, hours, days;
 -      int fmtlen, printed_something;
 +      int fmtlen;
  
        k = arg;
        v = ve->var;
        if (k->p_uvalid == 0) {
                origseconds = 0;
 @@ -886,58 +903,34 @@
  
                if (origseconds > v->longestp) {
                        v->longestp = origseconds;
  
                        if (days > 0) {
 -                              /* +9 for "-hh:mm:ss" */
 +                              /* days+9 for "dd-hh:mm:ss" */
                                fmtlen = iwidth(days) + 9;
 -                      } else if (hours > 0) {
 -                              /* +6 for "mm:ss" */
 -                              fmtlen = iwidth(hours) + 6;
 +                      } else if (hours > 0 || printmod & PHOURS) {
 +                              /* 8 for "hh:mm:ss" */
 +                              fmtlen = 8;
                        } else {
 -                              /* +3 for ":ss" */
 -                              fmtlen = iwidth(mins) + 3;
 +                              /* 5 for "mm:ss" */
 +                              fmtlen = 5;
                        }
  
                        if (fmtlen > v->width)
                                v->width = fmtlen;
                }
        } else {
 -              printed_something = 0;
                fmtlen = v->width;
  
 -              if (days > 0) {
 -                      (void)printf("%*d", fmtlen - 9, days);
 -                      printed_something = 1;
 -              } else if (fmtlen > 9) {
 -                      (void)printf("%*s", fmtlen - 9, "");
 -              }
 -              if (fmtlen > 9)
 -                      fmtlen = 9;
 -
 -              if (printed_something) {
 -                      (void)printf("-%.*d", fmtlen - 7, hours);
 -                      printed_something = 1;
 -              } else if (hours > 0) {
 -                      (void)printf("%*d", fmtlen - 6, hours);
 -                      printed_something = 1;
 -              } else if (fmtlen > 6) {
 -                      (void)printf("%*s", fmtlen - 6, "");
 -              }
 -              if (fmtlen > 6)
 -                      fmtlen = 6;
 -
 -              /* Don't need to set fmtlen or printed_something any more... */
 -              if (printed_something) {
 -                      (void)printf(":%.*d", fmtlen - 4, mins);
 -              } else if (mins > 0) {
 -                      (void)printf("%*d", fmtlen - 3, mins);
 -              } else if (fmtlen > 3) {
 -                      (void)printf("%*s", fmtlen - 3, "0");
 -              }
 -
 -              (void)printf(":%.2d", secs);
 +              if (days > 0)
 +                      (void)printf("%*d-%.2d:%.2d:%.2d", fmtlen - 9,
 +                                      days, hours, mins, secs);
 +              else if (hours > 0 || printmod & PHOURS)
 +                      (void)printf("%*.2d:%.2d:%.2d", fmtlen - 6, hours,
 +                                      mins, secs);
 +              else
 +                      (void)printf("%*.2d:%.2d", fmtlen - 3, mins, secs);
        }
  }
  
  void
  wchan(void *arg, VARENT *ve, int mode)
 @@ -1010,64 +1003,10 @@
        VAR *v;
  
        l = arg;
        v = ve->var;
        intprintorsetwidth(v, l->l_cpuid, mode);
 -}
 -
 -void
 -cputime(void *arg, VARENT *ve, int mode)
 -{
 -      struct kinfo_proc2 *k;
 -      VAR *v;
 -      int32_t secs;
 -      int32_t psecs;  /* "parts" of a second. first micro, then centi */
 -      int fmtlen;
 -
 -      k = arg;
 -      v = ve->var;
 -
 -      /*
 -       * This counts time spent handling interrupts.  We could
 -       * fix this, but it is not 100% trivial (and interrupt
 -       * time fractions only work on the sparc anyway).       XXX
 -       */
 -      secs = k->p_rtime_sec;
 -      psecs = k->p_rtime_usec;
 -      if (sumrusage) {
 -              secs += k->p_uctime_sec;
 -              psecs += k->p_uctime_usec;
 -      }
 -      /*
 -       * round and scale to 100's
 -       */
 -      psecs = (psecs + 5000) / 10000;
 -      secs += psecs / 100;
 -      psecs = psecs % 100;
 -
 -      if (mode == WIDTHMODE) {
 -              /*
 -               * Ugg, this is the only field where a value of 0 is longer
 -               * than the column title.
 -               * Use SECSPERMIN, because secs is divided by that when
 -               * passed to iwidth().
 -               */
 -              if (secs == 0)
 -                      secs = SECSPERMIN;
 -
 -              if (secs > v->longestp) {
 -                      v->longestp = secs;
 -                      /* "+6" for the ":%02ld.%02ld" in the printf() below */
 -                      fmtlen = iwidth(secs / SECSPERMIN) + 6;
 -                      if (fmtlen > v->width)
 -                              v->width = fmtlen;
 -              }
 -      } else {
 -              (void)printf("%*ld:%02ld.%02ld", v->width - 6,
 -                  (long)(secs / SECSPERMIN), (long)(secs % SECSPERMIN),
 -                  (long)psecs);
 -      }
  }
  
  double
  getpcpu(k)
        const struct kinfo_proc2 *k;
 
 
 --MP_/dbwTx/.nKTnAExi31fxRAl9
 Content-Type: text/x-patch
 Content-Transfer-Encoding: 7bit
 Content-Disposition: attachment; filename=ps.1.diff
 
 --- bin/ps/ps.1
 +++ bin/ps/ps.1
 @@ -637,11 +637,13 @@
  user name (from svuid)
  .It Ar tdev
  control terminal device number
  .It Ar time
  accumulated CPU time, user + system (alias
 -.Ar cputime )
 +.Ar cputime ) ,
 +in the form
 +.Li [dd-]hh:mm:ss
  .It Ar tpgid
  control terminal process group
  .Tn ID
  .It Ar tsess
  control terminal session pointer
 
 
 --MP_/dbwTx/.nKTnAExi31fxRAl9--
 


Home | Main Index | Thread Index | Old Index