Debian Codegraph @

dev/bench/benchUtil.ml

raw symbols SCIP
1 (************************************************************************)
2 (* * The Rocq Prover / The Rocq Development Team *)
3 (* v * Copyright INRIA, CNRS and contributors *)
4 (* <O___,, * (see version control and CREDITS file for authors & dates) *)
5 (* \VV/ **************************************************************)
6 (* // * This file is distributed under the terms of the *)
7 (* * GNU Lesser General Public License Version 2.1 *)
8 (* * (see LICENSE file for the text of the license) *)
9 (************************************************************************)
10
11 let die fmt = Printf.kfprintf (fun _ -> exit 1) stderr fmt
12
13 type char_loc = {
14 start_char : int;
15 stop_char : int;
16 }
17
18 type source_loc = {
19 chars : char_loc;
20 line : int;
21 text : string;
22 }
23
24 let same_char_locs a b = a.start_char = b.start_char && a.stop_char = b.stop_char
25
26 type measure = { str: string; q: Q.t; }
27
28 let dummy_measure = { str="0"; q=Q.zero; }
29
30 type memory = {
31 major_words : string;
32 minor_words : string;
33 major_collect : int;
34 minor_collect : int;
35 }
36
37 type data = { time : measure; memory : memory option; instructions : int option }
38
39 let dummy_data = { time = dummy_measure; memory = None; instructions = None }
40
41 let combine_related_data data =
42 let nvals = Array.length (snd (data.(0))) in
43 let fname0, data0 = data.(0) in
44 let () =
45 Array.iter (fun (fname, v) ->
46 if nvals <> Array.length v
47 then die "Mismatch between %s and %s: different measurement counts\n" fname0 fname)
48 data
49 in
50 Array.init nvals (fun i ->
51 let loc0, _ = data0.(i) in
52 let data = data |> Array.map (fun (fname, fdata) ->
53 let floc, v = fdata.(i) in
54 if same_char_locs loc0 floc then v
55 else die "Mismatch between %s and %s (measurement %d)\n" fname0 fname (i+1))
56 in
57 loc0, data)
58
59 let read_whole_file f =
60 let sourcelen = (Unix.stat f).st_size in
61 let ch = try open_in f with Sys_error e -> die "Could not open %s: %s" f e in
62 let s = really_input_string ch sourcelen in
63 close_in ch;
64 s