Skip to content

Commit

Permalink
Track maximum resident size of individual owi runs
Browse files Browse the repository at this point in the history
  • Loading branch information
filipeom committed Feb 24, 2025
1 parent df16c2a commit 61e50b3
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 28 deletions.
37 changes: 22 additions & 15 deletions bench/report/parse.ml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,18 @@ let from_file file =
| Some f -> Ok f
in

let parse_time t1 t2 t3 =
let parse_int64 s =
match Int64.of_string_opt s with
| None -> ksprintf error "malformed int64 %S" s
| Some i -> Ok i
in

let parse_rusage t1 t2 t3 rss =
let* clock = parse_float t1 in
let* utime = parse_float t2 in
let+ stime = parse_float t3 in
{ Rusage.clock; utime; stime }
let* stime = parse_float t3 in
let+ maxrss = parse_int64 rss in
{ Rusage.clock; utime; stime; maxrss }
in

let parse_int s =
Expand All @@ -62,25 +69,25 @@ let from_file file =
in
let+ res =
match String.split_on_char ' ' result |> rm_empty_str with
| [ "Reached"; "in"; t1; t2; t3 ] ->
let+ rusage = parse_time t1 t2 t3 in
| [ "Reached"; "in"; t1; t2; t3; rss ] ->
let+ rusage = parse_rusage t1 t2 t3 rss in
Run_result.Reached rusage
| [ "Timeout"; "in"; t1; t2; t3 ] ->
let+ rusage = parse_time t1 t2 t3 in
| [ "Timeout"; "in"; t1; t2; t3; rss ] ->
let+ rusage = parse_rusage t1 t2 t3 rss in
Run_result.Timeout rusage
| [ "Other"; n; "in"; t1; t2; t3 ] ->
| [ "Other"; n; "in"; t1; t2; t3; rss ] ->
let* n = parse_int n in
let+ rusage = parse_time t1 t2 t3 in
let+ rusage = parse_rusage t1 t2 t3 rss in
Run_result.Other (rusage, n)
| [ "Nothing"; "in"; t1; t2; t3 ] ->
let+ rusage = parse_time t1 t2 t3 in
| [ "Nothing"; "in"; t1; t2; t3; rss ] ->
let+ rusage = parse_rusage t1 t2 t3 rss in
Run_result.Nothing rusage
| [ "Signaled"; n; "in"; t1; t2; t3 ] ->
let* rusage = parse_time t1 t2 t3 in
| [ "Signaled"; n; "in"; t1; t2; t3; rss ] ->
let* rusage = parse_rusage t1 t2 t3 rss in
let+ n = parse_int n in
Run_result.Stopped (rusage, n)
| [ "Stopped"; n; "in"; t1; t2; t3 ] ->
let* rusage = parse_time t1 t2 t3 in
| [ "Stopped"; n; "in"; t1; t2; t3; rss ] ->
let* rusage = parse_rusage t1 t2 t3 rss in
let+ n = parse_int n in
Run_result.Signaled (rusage, n)
| _ -> ksprintf error "malformed result: %S" result
Expand Down
2 changes: 2 additions & 0 deletions bench/report/run.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ let utime run = (rusage run).utime

let stime run = (rusage run).stime

let maxrss run = (rusage run).maxrss

let is_reached { res; _ } = Run_result.is_reached res

let is_timeout { res; _ } = Run_result.is_timeout res
Expand Down
2 changes: 2 additions & 0 deletions bench/report/run.mli
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ val utime : t -> float

val stime : t -> float

val maxrss : t -> int64

val is_nothing : t -> bool

val is_killed : t -> bool
Expand Down
17 changes: 6 additions & 11 deletions bench/report/run_result.ml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,10 @@ let is_timeout = function Timeout _ -> true | _ -> false
let is_other = function Other _ -> true | _ -> false

let pp fmt = function
| Timeout t ->
Format.fprintf fmt "Timeout in %g %g %g" t.clock t.utime t.stime
| Nothing t ->
Format.fprintf fmt "Nothing in %g %g %g" t.clock t.utime t.stime
| Reached t ->
Format.fprintf fmt "Reached in %g %g %g" t.clock t.utime t.stime
| Other (t, code) ->
Format.fprintf fmt "Other %i in %g %g %g" code t.clock t.utime t.stime
| Timeout t -> Format.fprintf fmt "Timeout in %a" Rusage.pp t
| Nothing t -> Format.fprintf fmt "Nothing in %a" Rusage.pp t
| Reached t -> Format.fprintf fmt "Reached in %a" Rusage.pp t
| Other (t, code) -> Format.fprintf fmt "Other %i in %a" code Rusage.pp t
| Signaled (t, code) ->
Format.fprintf fmt "Signaled %i in %g %g %g" code t.clock t.utime t.stime
| Stopped (t, code) ->
Format.fprintf fmt "Stopped %i in %g %g %g" code t.clock t.utime t.stime
Format.fprintf fmt "Signaled %i in %a" code Rusage.pp t
| Stopped (t, code) -> Format.fprintf fmt "Stopped %i in %a" code Rusage.pp t
4 changes: 4 additions & 0 deletions bench/report/rusage.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ type t =
{ clock : float
; utime : float
; stime : float
; maxrss : int64
}

let pp fmt { clock; utime; stime; maxrss } =
Fmt.pf fmt "%4.2f %4.2f %4.2f %Ld" clock utime stime maxrss
3 changes: 3 additions & 0 deletions bench/report/rusage.mli
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ type t =
{ clock : float
; utime : float
; stime : float
; maxrss : int64
}

val pp : t Fmt.t
4 changes: 2 additions & 2 deletions bench/tool/tool.ml
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ let wait_pid ~pid ~timeout ~tool ~dst_stderr =
with Sigchld -> ()
end;
Sys.set_signal Sys.sigchld Signal_default;
let waited_pid, status, { Rusage.utime; stime; _ } = wait4 [] ~-pid in
let waited_pid, status, { Rusage.utime; stime; maxrss; _ } = wait4 [] ~-pid in
let end_time = Unix.gettimeofday () in
assert (waited_pid = pid);

let clock = end_time -. start_time in

(* Sometimes the clock goes a little bit above the allowed timeout... *)
let clock = min clock timeout in
let rusage = { Report.Rusage.clock; utime; stime } in
let rusage = { Report.Rusage.clock; utime; stime; maxrss } in

if !did_timeout || Float.equal clock timeout then
Report.Run_result.Timeout rusage
Expand Down

0 comments on commit 61e50b3

Please sign in to comment.