bug-gnu-utils
[Top][All Lists]
Advanced

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

Re: gnu time - ru_maxrss value


From: Jiri Pirko
Subject: Re: gnu time - ru_maxrss value
Date: Thu, 18 Dec 2008 15:36:11 +0100

On Thu, 18 Dec 2008 01:45:49 -0500 (EST)
David C Niemi <address@hidden> wrote:

> 
> Hello Karl,
> 
> address@hidden has never been a valid address, so I had not seen it 
> until just now.  Thanks for passing it on.
> 
> DCN
> 
> On Wed, 17 Dec 2008, Karl Berry wrote:
> > Hi David --
> >
> > I'm not sure if you saw this, since the To: address was slightly
> > different ...
> >
> >
> > Date: Wed, 17 Dec 2008 17:07:44 +0100
> > From: Jiri Pirko <address@hidden>
> > To: address@hidden
> > Cc: address@hidden, address@hidden, address@hidden
> > Subject: gnu time - ru_maxrss value
> >
> > Hi.
> >
> > Currently I am working on patch to linux kernel which will enable
> > ru_maxrss field in getrusage() syscall. I was looking at the source of
> > GNU time util and it expects this value to be in pages and converts it
> > into KBs. However BSD systems are setting this value to KB inside the
> > kernel. It seems good to me to introduce this in linux kernel in the
> > same way: value in KBs. In that case, the GNU time util needs to be
> > changed in the following way:
> >
> > --- time.c  2008-12-17 12:32:01.000000000 +0100
> > +++ time.c~MAXRSS   2008-12-17 17:02:10.000000000 +0100
> > @@ -395,7 +395,7 @@ summarize (fp, fmt, command, resp)
> >                    ptok ((UL) resp->ru.ru_ixrss) / MSEC_TO_TICKS (v));
> >           break;
> >         case 'M':           /* Maximum resident set size.  */
> > -         fprintf (fp, "%lu", ptok ((UL) resp->ru.ru_maxrss));
> > +         fprintf (fp, "%lu", resp->ru.ru_maxrss);
> >           break;
> >         case 'O':           /* Outputs.  */
> >           fprintf (fp, "%ld", resp->ru.ru_oublock);
> >
> >
> > What do you think about this?
> >
> > Thanks
> >
> > Jirka
> >
> >
> 

I looked at this closer and /usr/bin/time is also assuming that
->ru_ixrss , ->ru_idrss , ru_isrss are in pages. These values should be
in KBs too so I think we actually need to get rid of ptok() function
with all its callings. What do you think about it?

--- time.c      2008-12-17 12:32:01.000000000 +0100
+++ time.c~MAXRSS       2008-12-18 15:29:09.000000000 +0100
@@ -240,39 +240,6 @@ linear_argv (argv)
   return new;
 }
 
-/* Return the number of kilobytes corresponding to a number of pages PAGES.
-   (Actually, we use it to convert pages*ticks into kilobytes*ticks.)
-
-   Try to do arithmetic so that the risk of overflow errors is minimized.
-   This is funky since the pagesize could be less than 1K.
-   Note: Some machines express getrusage statistics in terms of K,
-   others in terms of pages.  */
-
-static unsigned long
-ptok (pages)
-     unsigned long pages;
-{
-  static unsigned long ps = 0;
-  unsigned long tmp;
-  static long size = LONG_MAX;
-
-  /* Initialization.  */
-  if (ps == 0)
-    ps = (long) getpagesize ();
-
-  /* Conversion.  */
-  if (pages > (LONG_MAX / ps))
-    {                          /* Could overflow.  */
-      tmp = pages / 1024;      /* Smaller first, */
-      size = tmp * ps;         /* then larger.  */
-    }
-  else
-    {                          /* Could underflow.  */
-      tmp = pages * ps;                /* Larger first, */
-      size = tmp / 1024;       /* then smaller.  */
-    }
-  return size;
-}
 
 /* summarize: Report on the system use of a command.
 
@@ -366,8 +333,8 @@ summarize (fp, fmt, command, resp)
            case 'D':           /* Average unshared data size.  */
              fprintf (fp, "%lu",
                       MSEC_TO_TICKS (v) == 0 ? 0 :
-                      ptok ((UL) resp->ru.ru_idrss) / MSEC_TO_TICKS (v) +
-                      ptok ((UL) resp->ru.ru_isrss) / MSEC_TO_TICKS (v));
+                      resp->ru.ru_idrss / MSEC_TO_TICKS (v) +
+                      resp->ru.ru_isrss / MSEC_TO_TICKS (v));
              break;
            case 'E':           /* Elapsed real (wall clock) time.  */
              if (resp->elapsed.tv_sec >= 3600) /* One hour -> h:m:s.  */
@@ -390,12 +357,12 @@ summarize (fp, fmt, command, resp)
            case 'K':           /* Average mem usage == data+stack+text.  */
              fprintf (fp, "%lu",
                       MSEC_TO_TICKS (v) == 0 ? 0 :
-                      ptok ((UL) resp->ru.ru_idrss) / MSEC_TO_TICKS (v) +
-                      ptok ((UL) resp->ru.ru_isrss) / MSEC_TO_TICKS (v) +
-                      ptok ((UL) resp->ru.ru_ixrss) / MSEC_TO_TICKS (v));
+                      resp->ru.ru_idrss / MSEC_TO_TICKS (v) +
+                      resp->ru.ru_isrss / MSEC_TO_TICKS (v) +
+                      resp->ru.ru_ixrss / MSEC_TO_TICKS (v));
              break;
            case 'M':           /* Maximum resident set size.  */
-             fprintf (fp, "%lu", ptok ((UL) resp->ru.ru_maxrss));
+             fprintf (fp, "%lu", resp->ru.ru_maxrss);
              break;
            case 'O':           /* Outputs.  */
              fprintf (fp, "%ld", resp->ru.ru_oublock);
@@ -426,7 +393,7 @@ summarize (fp, fmt, command, resp)
            case 'X':           /* Average shared text size.  */
              fprintf (fp, "%lu",
                       MSEC_TO_TICKS (v) == 0 ? 0 :
-                      ptok ((UL) resp->ru.ru_ixrss) / MSEC_TO_TICKS (v));
+                      resp->ru.ru_ixrss / MSEC_TO_TICKS (v));
              break;
            case 'Z':           /* Page size.  */
              fprintf (fp, "%d", getpagesize ());
@@ -445,7 +412,7 @@ summarize (fp, fmt, command, resp)
            case 'p':           /* Average stack segment.  */
              fprintf (fp, "%lu",
                       MSEC_TO_TICKS (v) == 0 ? 0 :
-                      ptok ((UL) resp->ru.ru_isrss) / MSEC_TO_TICKS (v));
+                      resp->ru.ru_isrss / MSEC_TO_TICKS (v));
              break;
            case 'r':           /* Incoming socket messages received.  */
              fprintf (fp, "%ld", resp->ru.ru_msgrcv);
@@ -456,7 +423,7 @@ summarize (fp, fmt, command, resp)
            case 't':           /* Average resident set size.  */
              fprintf (fp, "%lu",
                       MSEC_TO_TICKS (v) == 0 ? 0 :
-                      ptok ((UL) resp->ru.ru_idrss) / MSEC_TO_TICKS (v));
+                      resp->ru.ru_idrss / MSEC_TO_TICKS (v));
              break;
            case 'w':           /* Voluntary context switches.  */
              fprintf (fp, "%ld", resp->ru.ru_nvcsw);





reply via email to

[Prev in Thread] Current Thread [Next in Thread]