[MLton] getrusage and times?

Matthew Fluet fluet@cs.cornell.edu
Wed, 2 Nov 2005 08:29:16 -0500 (EST)

>> MLton seems to really like calling:
>> getrusage(RUSAGE_SELF, {ru_utime={0, 1999}, ru_stime={0, 3999}, ...}) = 0
>> times({tms_utime=0, tms_stime=0, tms_cutime=0, tms_cstime=0}) = 432034594
> The call to getrusage comes from the GC keeping track of how much time
> it consumes: see {start,stop}Timing in gc.c.  The call to times is to
> work around a (now pretty old) Linux kernel bug in getrusage.  The
> calls aren't supposed to happen unless someone is (possibly) going to
> ask for the information: see needGCTime in gc.c.  Unfortunately there
> is a bug, which has been there at least since 20041109, that causes
> the information to always be collected.  I've checked in a (one line)
> fix.
> In looking at it now, although the use of weaks is clever, perhaps we
> should adopt a more robust, explicit, and portable solution.  What
> about adding a function
>  val MLton.Rusage.keepGCTime: bool -> unit
> or possibly
>  val MLton.GC.keepTime: bool -> unit
> that would simply set a flag in the gcState, which needGCTime could
> check to decide whether or not to call getrusage.  The default value
> would be true (to mimic current behavior).

There is an odd behavior, it seems to me, that if the program uses 
MLton.GC.setSummary, then the summary at the end only includes timing 
information for the portion of the program during which gcState.summary 
was true.

static inline bool detailedGCTime (GC_state s) {
         return s->summary;
static inline bool needGCTime (GC_state s) {
         return DEBUG or s->summary or s->messages or s->rusageIsEnabled;