profiling

Stephen Weeks MLton@sourcelight.com
Mon, 21 Jan 2002 11:32:26 -0800


> I finished updating the profiling information in the docs.
> I think the MLton.Profile structure is nice, but we can probably do
> better.  Here's an ambitious signature:
...
> Here's the vision: data is really an int array.

I don't think it's a good idea to move the profile counter array into
SML space.  If you do, then profiling really affects program behavior
because we have to gc the array.  I'd rather go for a signature like
the following, where all of the functions are implemented as FFI
calls.

signature MLTON_PROFILE =
   sig
      val profile: bool

      structure Data:
	 sig
	    type t

	    val equals: t * t -> bool
	    val free: t -> unit
	    val malloc: unit -> t
	    val reset: t -> unit
	    val write: t * string -> unit
	 end
      
      val current: unit -> Data.t
      val setCurrent: Data.t -> unit
   end

Actually, equals and current could be implemented at SML level if the
basis library put a wrapper around the raw profile array and were
responsible for the initialization and writing at exit of the
"mlmon.out" main profile array.  I have no problems with that.