traceBatch Verbosity problem
Matthew Fluet
fluet@CS.Cornell.EDU
Mon, 24 Sep 2001 12:08:45 -0400 (EDT)
> > Another possibility would be to move the tracers inside the functions, so that
> > there is a verbosity test once per compile (or chunk, or something better than
> > per function call). Although you should probably measure the time to see if it
> > matters.
>
> Forget what I said. This is noise. It just pushes the test on the bool ref
> into a switch on the datatype variant representing the lambda. I guess the
> latter is slightly better since there's no deref, but there's still a test.
>
> I'd say go for the test, since that's gotta be cheaper than counting the time.
So, I've tried replacing the existing traceBatch with the following,
which does what I want, except that I am consistently getting Time
exceptions in the timeToString call when it takes the difference
(totalGC - total); i.e., somehow the time bug has arisen once again.
Anyone see anything obviously wrong with this?
val ('a, 'b) traceBatch: (verbosity * string) -> ('a -> 'b) ->
(('a -> 'b) * (unit -> unit)) =
fn (verb, name) =>
fn f => let
val total = ref Time.zero
val totalGC = ref Time.zero
in
(fn a
=> if Verbosity.<= (verb, !verbosity)
then let
val (t, gc) = time ()
fun done ()
= let
val (t', gc') = time ()
in
total :=
timePlus (!total,
timeMinus
(t', t',
"traceBatch: 't - t"),
"traceBatch: !total") ;
totalGC :=
timePlus (!totalGC,
timeMinus
(gc', gc,
"traceBatch: gc' - gc"),
"traceBatch: !totalGC")
end
in
(f a
before done ())
handle e => (messageStr (verb,
concat [name, " raised"])
; raise e)
end
else f a,
fn () => messageStr (verb,
concat [name,
" totals ",
timeToString
{total = !total,
gc = !totalGC}]))
end