1 (* Copyright (C
) 1999-2006 Henry Cejtin
, Matthew Fluet
, Suresh
2 * Jagannathan
, and Stephen Weeks
.
3 * Copyright (C
) 1997-2000 NEC Research Institute
.
5 * MLton is released under a BSD
-style license
.
6 * See the file MLton
-LICENSE for details
.
9 structure MLtonRusage
: MLTON_RUSAGE
=
11 structure Prim
= PrimitiveFFI
.MLton
.Rusage
13 type t
= {utime
: Time
.time
, stime
: Time
.time
}
15 fun collect (utimeSec
, utimeUsec
, stimeSec
, stimeUsec
) =
17 fun toTime (sec
, usec
) =
20 Time
.fromSeconds (C_Time
.toLargeInt (sec ()))
22 Time
.fromMicroseconds (C_SUSeconds
.toLargeInt (usec ()))
24 Time
.+ (time_sec
, time_usec
)
27 {stime
= toTime (stimeSec
, stimeUsec
),
28 utime
= toTime (utimeSec
, utimeUsec
)}
31 val measureGC
= MLtonGC
.setRusageMeasureGC
35 val () = measureGC
true
39 val () = Prim
.getrusage ()
42 {children
= collect (children_utime_sec
, children_utime_usec
,
43 children_stime_sec
, children_stime_usec
),
44 gc
= collect (gc_utime_sec
, gc_utime_usec
,
45 gc_stime_sec
, gc_stime_usec
),
46 self
= collect (self_utime_sec
, self_utime_usec
,
47 self_stime_sec
, self_stime_usec
)}