Skip to content

Commit

Permalink
Allow Marvin to inform us of memory statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
filipeom committed Feb 23, 2025
1 parent 86bea7e commit 461b929
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 7 deletions.
35 changes: 35 additions & 0 deletions bench/report/runs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,30 @@ let sum_stime runs = List.fold_left (fun sum r -> Run.stime r +. sum) 0. runs

let mean_stime runs = sum_stime runs /. (count_all runs |> float_of_int)

let sum_maxrss runs =
List.fold_left (fun sum r -> Int64.add (Run.maxrss r) sum) 0L runs

let mean_maxrss runs =
Int64.to_float (sum_maxrss runs) /. (count_all runs |> float)

let median_maxrss runs =
let runs = Array.of_list @@ List.map Run.maxrss runs in
let n = Array.length runs in
Array.fast_sort compare runs;
if n = 0 then 0.
else if n mod 2 = 0 then
let left = Array.get runs (n / 2) in
let right = Array.get runs ((n / 2) + 1) in
Int64.(to_float (add left right)) /. 2.
else Int64.to_float @@ Array.get runs (n / 2)

let min_max_maxrss runs =
List.fold_left
(fun (curr_min, curr_max) r ->
let maxrss = Run.maxrss r in
(min curr_min maxrss, max curr_max maxrss) )
(Int64.max_int, 0L) runs

let to_distribution ~max_time runs =
List.init max_time (fun i ->
List.fold_left
Expand Down Expand Up @@ -133,6 +157,17 @@ let pp_table_statistics fmt results =
| %0.2f | %0.2f | %0.2f | %0.2f | %0.2f |@\n"
total mean median min max

let pp_table_memory fmt results =
let total = sum_maxrss results in
let mean = mean_maxrss results in
let median = median_maxrss results in
let min, max = min_max_maxrss results in
Format.fprintf fmt
"| Total | Mean | Median | Min | Max |@\n\
|:-----:|:----:|:------:|:---:|:---:|@\n\
| %Ld | %0.2f | %0.2f | %Ld | %Ld |@\n"
total mean median min max

let map = List.map

let files = List.map (fun run -> run.Run.file)
12 changes: 9 additions & 3 deletions bench/report/runs.mli
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,19 @@ val sum_stime : t -> float

val mean_stime : t -> float

val sum_maxrss : t -> int64

val mean_maxrss : t -> float

val to_distribution : max_time:int -> t -> float list

val pp_quick_results : Format.formatter -> t -> unit
val pp_quick_results : t Fmt.t

val pp_table_results : t Fmt.t

val pp_table_results : Format.formatter -> t -> unit
val pp_table_statistics : t Fmt.t

val pp_table_statistics : Format.formatter -> t -> unit
val pp_table_memory : t Fmt.t

val map : (Run.t -> 'a) -> t -> 'a list

Expand Down
6 changes: 3 additions & 3 deletions bench/report/rusage.mli
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
type t =
{ clock : float
; utime : float
; stime : float
; maxrss : int64
; utime : float (** user CPU time used *)
; stime : float (** system CPU time used *)
; maxrss : int64 (** Maximum resident size (in kilobytes) *)
}

val pp : t Fmt.t
6 changes: 5 additions & 1 deletion bench/testcomp/testcomp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,13 @@ let notify_finished runs =
@\n\
Time stats (in seconds):@\n\
@\n\
%a@\n\
@\n\
Memory stats (in kilobytes):@\n\
@\n\
%a@."
reference_name timeout Fpath.pp output_dir Report.Runs.pp_table_results
runs Report.Runs.pp_table_statistics runs
runs Report.Runs.pp_table_statistics runs Report.Runs.pp_table_memory runs
in
(* Notify on `ZULIP_WEBHOOK` *)
match Bos.OS.Env.var "ZULIP_WEBHOOK" with
Expand Down

0 comments on commit 461b929

Please sign in to comment.