[MLton] MLton.Rusage.measureGC

Stephen Weeks MLton@mlton.org
Tue, 25 Apr 2006 15:30:42 -0700


> I am confused by the logic and default value for the bool set by the
> function MLton.Rusage.measureGC.  On the other hand, I am also
> confused about what it means to set it to false.

Here is the conlusion of the discussion about this from last November:

  http://mlton.org/pipermail/mlton/2005-November/028175.html

The default value is false, unless the program directly or indirectly
uses MLton.Rusage.rusage.  Setting the value to false causes GC time
to not be measured, even if the program uses MLton.Rusage.rusage.

> It seems from a test that if I don't set it and I don't use either
> of gc-summary or gc-messages, that time spent in the GC counts both
> in the #gc and #self members of the record.

That is consistent with your program using MLton.Rusage.rusage.  Does
it?

> This is the same behavior if I set it to true.

Still consistent, if your program uses MLton.Rusage.rusage.

> (I don't quite see how that happens since gc.c initializes the
> member of the C struct to FALSE and needGCTime() would only return
> true if the member were TRUE, or DEBUG, summary or messages were
> going on, and none of these were.  In fact, the struct member is
> NEVER set to any thing but true in any code I can find.)

Yep.  It's initialized to false and only ever set to false if the code
does "MLton.Rusage.measureGC false".

> If I set it to false then it only counts in the #self time and the
> #gc time is 0.

Sounds right to me.

> I assume that the only reason behind this is to save the CPU time in
> computing the start and end times around a GC 

Yep.

> and adding it to the total. If that is the case, then the
> documentation should say that, and it should say that this (that
> which is set by MLton.Rusage.measureGC) only controls whether the
> #gc accumulates the GC time and that it goes to #self regardless.

OK.  I've clarifed things to read

  measureGC b
    controls whether garbage collection time is separately measured
    during program execution.  This affects the behavior of both
    rusage and Timer.checkCPUTimes, both of which will return gc times
    of zero with measureGC false.  Note that garbage collection time
    is always measured when either gc-messages or gc-summary is given
    as a runtime system option.

  rusage ()
    corresponds to the C getrusage function. It returns the resource
    usage of the exited children, the garbage collector, and the
    process itself.  The process time (self) includes the gc time,
    regardless of whether measureGC is used or not.
 
> Also, it seems that the default really should be false, but it isn't
> (despite what the code looks like).

The default is and should be false.

> Am I missing something?

Hopefully, the only thing you're missing is that your code uses
MLton.Rusage.rusage.