getrusage bug?

Stephen Weeks MLton@sourcelight.com
Fri, 22 Jun 2001 11:06:05 -0700


I noticed that the times reported by mlton for assemble and link are almost
always zero, so something is wrong.  I wrote the following simple SML program to
test out getrusage, and indeed, by stracing it, one can see that
getrusage(RUSAGE_CHILDREN, ...) is always returning 0, even with a child that is
spinning at full speed.  Any ideas what's wrong?  Is this a know bug in
getrusage and is there a workaround?

val _ =
   case Posix.Process.fork () of
      NONE =>
	 let
	    fun loop () = loop ()
	 in
	    loop ()
	 end
    | SOME _ => 
	 let
	    fun start () = loop 100000000
	    and loop n =
	       if n = 0
		  then
		     let
			fun us {utime, stime} =
			   concat ["utime = ", Time.toString utime,
				   " stime = ", Time.toString stime]
			val {self, children, gc} =
			   MLton.Rusage.rusage ()
			val _ =
			   print (concat ["children  ", us children, "\n",
					  "gc  ", us gc, "\n",
					  "self  ", us self, "\n"])
		     in
			start ()
		     end
	       else
		  loop (n - 1)
	 in
	    start ()
	 end