zsh-users
 help / color / mirror / code / Atom feed
* time builtin vs. time(1): difference in memory numbers
@ 2010-12-04  1:43 Anonymous
  2010-12-04 18:28 ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Anonymous @ 2010-12-04  1:43 UTC (permalink / raw)
  To: zsh-users

zsh-4.3.10_4, FreeBSD 9.0-CURRENT r216095M amd64

I'm a bit puzzled by...

- numbers for shared/unshared space don't match those from `time -l'
- zsh manual page claims that %M stands for memory in Kbytes while it
  displays them in Mbytes

Do %X/%D/%K/%M display consistent numbers on Linuces or other BSDs?

$ tcsh -f
% set time=(3 "%X shared %D unshared %K total %M maxres")
% time xz -c /COPYRIGHT >/dev/null
52 shared 3148 unshared 3200 total 8132 maxres

$ zsh -f
% TIMEFMT="%X shared %D unshared %K total %M maxres"
% time xz -c /COPYRIGHT >/dev/null
6953 shared 420930 unshared 427883 total 17 maxres

$ command time -l xz -c /COPYRIGHT >/dev/null
        0.02 real         0.00 user         0.02 sys
     17220  maximum resident set size
        78  average shared memory size
      3032  average unshared data size
       192  average unshared stack size
      4386  page reclaims
         0  page faults
         0  swaps
         0  block input operations
         1  block output operations
         0  messages sent
         0  messages received
         0  signals received
         1  voluntary context switches
         1  involuntary context switches

time(1) is close to ps(1) and STATUS (^T) in numbers about resident size.
Not sure why maxres (%M) is halved for tcsh.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: time builtin vs. time(1): difference in memory numbers
  2010-12-04  1:43 time builtin vs. time(1): difference in memory numbers Anonymous
@ 2010-12-04 18:28 ` Bart Schaefer
  2010-12-05 11:38   ` Anonymous
  0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2010-12-04 18:28 UTC (permalink / raw)
  To: zsh-users

On Dec 4,  4:43am, Anonymous wrote:
} Subject: time builtin vs. time(1): difference in memory numbers
}
} zsh-4.3.10_4, FreeBSD 9.0-CURRENT r216095M amd64
} 
} I'm a bit puzzled by...
} 
} - numbers for shared/unshared space don't match those from `time -l'

Zsh's %X and %D compute the average amount of shared/unshared space by
using the ru_ixrss and (ru_idrss + ru_isrss) values from rusage,
respectively, as the numerator, and (ru_utime + ru_stime) as the
denominator.  I don't know what the BSD time command uses for the
denominator.  Zsh also rounds down microseconds to perform all of its
computations in seconds, which may lead to differences.

} - zsh manual page claims that %M stands for memory in Kbytes while it
}   displays them in Mbytes

Hm.  %M stands for ru_maxrss / 1024.  Zsh would only be displaying
that in Mbytes if ru_maxrss is expressed in Gbytes internally.  Has
FreeBSD changed the base units of maxrss in rusage?

-- 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: time builtin vs. time(1): difference in memory numbers
  2010-12-04 18:28 ` Bart Schaefer
@ 2010-12-05 11:38   ` Anonymous
  2010-12-05 13:59     ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Anonymous @ 2010-12-05 11:38 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-users

Bart Schaefer <schaefer@brasslantern.com> writes:

> On Dec 4,  4:43am, Anonymous wrote:
> } Subject: time builtin vs. time(1): difference in memory numbers
> }
> } zsh-4.3.10_4, FreeBSD 9.0-CURRENT r216095M amd64
> } 
> } I'm a bit puzzled by...
> } 
> } - numbers for shared/unshared space don't match those from `time -l'
>
> Zsh's %X and %D compute the average amount of shared/unshared space by
> using the ru_ixrss and (ru_idrss + ru_isrss) values from rusage,
> respectively, as the numerator, and (ru_utime + ru_stime) as the
> denominator.  I don't know what the BSD time command uses for the
> denominator.

According to getrusage(2) on BSDs ixrss/idrss/isrss are "expressed in
units of kilobytes * ticks-of-execution". So, I've made a quick hack

  http://www.freebsd.org/cgi/query-pr.cgi?pr=ports/152820

a bit different from time(1) that uses stathz from kern.clockrate sysctl.

> Zsh also rounds down microseconds to perform all of its
> computations in seconds, which may lead to differences.
>
> } - zsh manual page claims that %M stands for memory in Kbytes while it
> }   displays them in Mbytes
>
> Hm.  %M stands for ru_maxrss / 1024.  Zsh would only be displaying
> that in Mbytes if ru_maxrss is expressed in Gbytes internally.  Has
> FreeBSD changed the base units of maxrss in rusage?

maxrss like ixrss/idrss/isrss is expressed "in kilobytes"

  http://man.freebsd.org/getrusage/2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: time builtin vs. time(1): difference in memory numbers
  2010-12-05 11:38   ` Anonymous
@ 2010-12-05 13:59     ` Bart Schaefer
  0 siblings, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2010-12-05 13:59 UTC (permalink / raw)
  To: zsh-users

[Further discussion on this thread probably should go to zsh-workers.]

On Dec 5,  2:38pm, Anonymous wrote:
} Subject: Re: time builtin vs. time(1): difference in memory numbers
}
} According to getrusage(2) on BSDs ixrss/idrss/isrss are "expressed in
} units of kilobytes * ticks-of-execution". So, I've made a quick hack
} 
}   http://www.freebsd.org/cgi/query-pr.cgi?pr=ports/152820

Looks like it'd be appropriate to wrap that first hunk in
#ifdef _SC_CLK_TCK
??

I'm curious if FreeBSD has anything like this (from <asm/param.h>
on RHEL4):

#define HZ sysconf(_SC_CLK_TCK)

} Bart Schaefer <schaefer@brasslantern.com> writes:
} > } - zsh manual page claims that %M stands for memory in Kbytes while it
} > }   displays them in Mbytes
} >
} > Hm.  %M stands for ru_maxrss / 1024.  Zsh would only be displaying
} > that in Mbytes if ru_maxrss is expressed in Gbytes internally.  Has
} > FreeBSD changed the base units of maxrss in rusage?
} 
} maxrss like ixrss/idrss/isrss is expressed "in kilobytes"

D'oh, I'm backwards on the multiplication there, so that makes sense.

Some quick searching indicates that ru_maxrss is in fact commonly
returned in KB, but linux kernels prior to Dec 2008 may have used
different units (and even earlier, didn't have this at all).

The code in jobs.c dates from 2004 and the ChangeLog says it's restoring
even older code that was removed at some point, so it is probably based
on neither linux nor FreeBSD.  Unless someone can figure out what that
may have been, it's probably safe to remove the "/ 1024".

-- 


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-12-05 13:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-04  1:43 time builtin vs. time(1): difference in memory numbers Anonymous
2010-12-04 18:28 ` Bart Schaefer
2010-12-05 11:38   ` Anonymous
2010-12-05 13:59     ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).