[Top][All Lists]

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

Re: GNU time: incorrect results

From: Bob Proulx
Subject: Re: GNU time: incorrect results
Date: Fri, 1 Oct 2010 16:12:37 -0600
User-agent: Mutt/1.5.20 (2009-06-14)

Sven Hartrumpf wrote:
>         Maximum resident set size (kbytes): 2004096
> top and htop show only around 500000.

Thank you for your report.  You have indeed found a bug in GNU time.
GNU time is expecting the ru_maxrss value to indicate in pages and is
converting that value from number of pages to kbytes.  That is
incorrect and results in the bug you found.

> And the wait4 result "ru_maxrss" differs as expected:
> wait4(... , ru_maxrss=501024, ...
> Who multiplies the correct "ru_maxrss" value by 4?

GNU time does, which is incorrect.

The rusage structure is documented in getrusage(2) and says:

               long   ru_maxrss;        /* maximum resident set size */

While other entries are documented as pages that entry is without
units attached to the comment.  That is undoubtedly the source of the
error.  Pages were assumed when it was really kbytes.  Looking at the
libc documentation we see that it is not ambiguous:

  $ info libc 'Resource Usage'

    'long int ru_maxrss'
          The maximum resident set size used, in kilobytes.  That is,
          the maximum number of kilobytes of physical memory that
          PROCESSES used simultaneously.

And other older BSD documentation concurs.  The value is reported in

This trivial patch corrects the problem.  I will see about getting GNU
time updated.

diff -ru time-1.7.orig/ChangeLog time-1.7/ChangeLog
--- time-1.7.orig/ChangeLog     1996-07-11 10:37:20.000000000 -0600
+++ time-1.7/ChangeLog  2010-10-01 16:03:09.000000000 -0600
@@ -1,3 +1,10 @@
+2010-10-01  Bob Proulx  <>
+       The struct rusage reports ru_maxrss in kbytes not pages and
+       should not be converted through pages-to-kbytes again.
+       Reported by Sven Hartrumpf.
+       * time.c (summarize): Do not call ptok on ru_maxrss.
diff -ru time-1.7.orig/time.c time-1.7/time.c
--- time-1.7.orig/time.c        1996-06-13 13:38:21.000000000 -0600
+++ time-1.7/time.c     2010-10-01 15:49:11.000000000 -0600
@@ -392,7 +392,7 @@
                       ptok ((UL) resp->ru.ru_ixrss) / MSEC_TO_TICKS (v));
            case 'M':           /* Maximum resident set size.  */
-             fprintf (fp, "%lu", ptok ((UL) resp->ru.ru_maxrss));
+             fprintf (fp, "%lu", (UL) resp->ru.ru_maxrss);
            case 'O':           /* Outputs.  */
              fprintf (fp, "%ld", resp->ru.ru_oublock);

Thanks again for reporting this problem and for helping to improve


reply via email to

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