Debian Codegraph @

lib/mlrisc-lib/MLRISC/control/mlrisc-timing.sml

raw
1 (* mlrisc-timing.sml
2 *
3 * COPYRIGHT (c) 2002 Bell Labs, Lucent Technologies
4 *)
5
6 signature MLRISC_TIMING =
7 sig
8
9 val timePhase : string -> ('a -> 'b) -> 'a -> 'b
10 end
11
12 structure MLRiscTiming : MLRISC_TIMING =
13 struct
14
15 fun timePhase name f =
16 let val timing = MLRiscControl.timing name
17 val { gc, usr, sys } = !timing
18 fun run x =
19 let val timer = Timer.startCPUTimer()
20 fun update timer =
21 let val t = Timer.checkCPUTimes timer
22 val gc' = #usr (#gc t)
23 val usr' = #usr (#nongc t)
24 val sys' = Time.+ (#sys (#gc t), #sys (#nongc t))
25 in timing := {gc=Time.+(gc,gc'),
26 usr=Time.+(usr,usr'),
27 sys=Time.+(sys,sys')}
28 end
29 val y = f x handle e => (update timer; raise e)
30 in update timer; y
31 end
32 in run end
33
34 end