[sledge] Do not expose Report dependency on Unix.process_times

Summary: Now elapsed time and the info in Unix.process_times is treated uniformly.

Reviewed By: jvillard

Differential Revision: D24306049

fbshipit-source-id: 09ab734ea
master
Josh Berdine 4 years ago committed by Facebook GitHub Bot
parent a204c7f7be
commit e2f0aab454

@ -12,12 +12,11 @@ let read filename =
List.iter (Sexp.load_sexps filename) ~f:(fun sexp -> List.iter (Sexp.load_sexps filename) ~f:(fun sexp ->
let {Report.name; entry} = Report.t_of_sexp sexp in let {Report.name; entry} = Report.t_of_sexp sexp in
match (Tbl.find_opt tbl name, entry) with match (Tbl.find_opt tbl name, entry) with
| None, ProcessTimes (etime, ptimes) -> | None, ProcessTimes ptimes -> Tbl.replace tbl name ([ptimes], [], [])
Tbl.replace tbl name ([(etime, ptimes)], [], [])
| None, GcStats gc -> Tbl.replace tbl name ([], [gc], []) | None, GcStats gc -> Tbl.replace tbl name ([], [gc], [])
| None, Status status -> Tbl.replace tbl name ([], [], [status]) | None, Status status -> Tbl.replace tbl name ([], [], [status])
| Some (times, gcs, statuses), ProcessTimes (etime, ptimes) -> | Some (times, gcs, statuses), ProcessTimes ptimes ->
Tbl.replace tbl name ((etime, ptimes) :: times, gcs, statuses) Tbl.replace tbl name (ptimes :: times, gcs, statuses)
| Some (times, gcs, statuses), GcStats gc -> | Some (times, gcs, statuses), GcStats gc ->
Tbl.replace tbl name (times, gc :: gcs, statuses) Tbl.replace tbl name (times, gc :: gcs, statuses)
| Some (times, gc, statuses), Status status -> | Some (times, gc, statuses), Status status ->
@ -35,10 +34,9 @@ type ('t, 'g) row =
; status: Report.status list ; status: Report.status list
; status_deltas: Report.status list option } ; status_deltas: Report.status list option }
let times_of_raw (etime, ptimes) = let times_of_raw {Report.etime; utime; stime; cutime; cstime} =
let {Unix.tms_utime; tms_cutime; tms_stime; tms_cstime} = ptimes in let utime = utime +. cutime in
let utime = tms_utime +. tms_cutime in let stime = stime +. cstime in
let stime = tms_stime +. tms_cstime in
let etime = etime in let etime = etime in
{etime; utime; stime} {etime; utime; stime}
@ -117,22 +115,21 @@ let combine name b_result c_result =
, Iter.empty , Iter.empty
, Iter.empty ) , Iter.empty )
~f:(fun (etimes, utimes, stimes, cutimes, cstimes) ~f:(fun (etimes, utimes, stimes, cutimes, cstimes)
( etime {Report.etime; utime; stime; cutime; cstime}
, {Unix.tms_utime; tms_cutime; tms_stime; tms_cstime} )
-> ->
( Iter.cons etime etimes ( Iter.cons etime etimes
, Iter.cons tms_utime utimes , Iter.cons utime utimes
, Iter.cons tms_stime stimes , Iter.cons stime stimes
, Iter.cons tms_cutime cutimes , Iter.cons cutime cutimes
, Iter.cons tms_cstime cstimes ) ) , Iter.cons cstime cstimes ) )
in in
Some Some
(times_of_raw (times_of_raw
( ave_floats etimes { etime= ave_floats etimes
, { tms_utime= ave_floats utimes ; utime= ave_floats utimes
; tms_stime= ave_floats stimes ; stime= ave_floats stimes
; tms_cutime= ave_floats cutimes ; cutime= ave_floats cutimes
; tms_cstime= ave_floats cstimes } )) ; cstime= ave_floats cstimes })
in in
let gcs = let gcs =
if List.is_empty gcs then None if List.is_empty gcs then None

@ -85,18 +85,27 @@ let safe_or_unsafe () =
type gc_stats = {allocated: float; promoted: float; peak_size: float} type gc_stats = {allocated: float; promoted: float; peak_size: float}
[@@deriving sexp] [@@deriving sexp]
type times =
{etime: float; utime: float; stime: float; cutime: float; cstime: float}
[@@deriving sexp]
type entry = type entry =
| ProcessTimes of float * Unix.process_times | ProcessTimes of times
| GcStats of gc_stats | GcStats of gc_stats
| Status of status | Status of status
[@@deriving sexp] [@@deriving sexp]
let process_times () = let process_times () =
let ptimes = Unix.times () in let {Unix.tms_utime; tms_stime; tms_cutime; tms_cstime} = Unix.times () in
let etime = let etime =
try Mtime.Span.to_s (Mtime_clock.elapsed ()) with Sys_error _ -> 0. try Mtime.Span.to_s (Mtime_clock.elapsed ()) with Sys_error _ -> 0.
in in
ProcessTimes (etime, ptimes) ProcessTimes
{ etime
; utime= tms_utime
; stime= tms_stime
; cutime= tms_cutime
; cstime= tms_cstime }
let gc_stats () = let gc_stats () =
let words_to_MB n = n /. float (Sys.word_size / 8) /. (1024. *. 1024.) in let words_to_MB n = n /. float (Sys.word_size / 8) /. (1024. *. 1024.) in

@ -35,8 +35,11 @@ val status : status -> unit
type gc_stats = {allocated: float; promoted: float; peak_size: float} type gc_stats = {allocated: float; promoted: float; peak_size: float}
[@@deriving sexp] [@@deriving sexp]
type times =
{etime: float; utime: float; stime: float; cutime: float; cstime: float}
type entry = type entry =
| ProcessTimes of float * Unix.process_times | ProcessTimes of times
| GcStats of gc_stats | GcStats of gc_stats
| Status of status | Status of status
[@@deriving sexp] [@@deriving sexp]

Loading…
Cancel
Save