[MLton-user] Problem with Timer.checkCPUTimer on Sparc

shivers@cc.gatech.edu shivers@cc.gatech.edu
Sun, 2 Nov 2003 23:27:30 -0500


This code

  fun time2s t = (LargeInt.toString(Time.toMicroseconds t))
  fun timer2s tm = let val {usr,sys} = Timer.checkCPUTimer tm
		       val gc = Timer.checkGCTime tm
		   in "((usr " ^ (time2s usr) ^ ") "
		      ^"(sys " ^ (time2s sys) ^ ") "
		      ^"(gc  " ^ (time2s gc)  ^ "))"
		   end

conses up a little time report string in an sexpression format. I ran some code
on a Sparc, using build
    MLton 20030716-2 (built Thu Oct 16 08:29:13 2003 on blade)
and it produced the following string:

    ((usr 140000) (sys 30000) (gc  170000))

Note that gc time is 170 usec & usr time is 140 usec. But that is impossible,
since usr time *includes* gc time, according to the SML doc at

    http://www.standardml.org/Basis/timer.html

which says

    checkCPUTimer ct 
	returns the user time (usr) and system time (sys) that have
	accumulated since the timer ct was started. Note that implementations
	should include any time spent in the garbage collector in the usr time
	component.

    checkGCTime ct 
	returns the GC time that has accumulated since the timer ct was
	started. This function can be used in conjunction with checkCPUTimer
	to determine the non-GC user time as follows:

	fun userTime ct = let
	      val {usr, ...} = Timer.checkCPUTimer ct
	      in
		Time.- (usr, Timer.checkGCTime ct)
	      end

So it seems like my code took negative time. ??? Is this a bug? 
Did I make a mistake?
    -Olin