| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
let die fmt = Printf.kfprintf (fun _ -> exit 1) stderr (fmt^^"\n%!") |
| 12 |
|
| 13 |
let usage () = die "Usage: rocq timelog2html [options] VFILE DATAFILES\n\n%a\n%s" |
| 14 |
(fun fmt len -> Printf.fprintf fmt "1 to %d data files are supported." len) |
| 15 |
Htmloutput.max_data_count |
| 16 |
"Data files may be .json or .json.gz profile files (as produced by rocq c -profile),\ |
| 17 |
\nor timing files (as produced by rocq c -time-file).\ |
| 18 |
\n\ |
| 19 |
\nOptions:\ |
| 20 |
\n -o FILE: output to FILE (default is - meaning stdout)\ |
| 21 |
\n -raw-o FILE: output machine readable data to FILE (default off, - means stdout)\ |
| 22 |
\n (only supported with 2 data files)\ |
| 23 |
\n -min-diff DIFF: in -raw-o, only output lines with time diff greater than DIFF\ |
| 24 |
\n (DIFF in OCaml float format, default 1e-4)" |
| 25 |
|
| 26 |
let parse_files = function |
| 27 |
| [] | [_] -> usage () |
| 28 |
| vfile :: data_files -> |
| 29 |
let data_files = Array.of_list data_files in |
| 30 |
let () = if Array.length data_files > Htmloutput.max_data_count |
| 31 |
then usage () |
| 32 |
in |
| 33 |
vfile, data_files |
| 34 |
|
| 35 |
type output = Stdout | File of string |
| 36 |
|
| 37 |
type opts = { |
| 38 |
output : output; |
| 39 |
raw_output : output option; |
| 40 |
min_diff : Q.t; |
| 41 |
} |
| 42 |
|
| 43 |
let defaults = { |
| 44 |
output = Stdout; |
| 45 |
raw_output = None; |
| 46 |
min_diff = Q.(one / of_int 10_000); |
| 47 |
} |
| 48 |
|
| 49 |
let with_output f out = |
| 50 |
match out with |
| 51 |
| Stdout -> f stdout |
| 52 |
| File fname -> |
| 53 |
let ch = open_out fname in |
| 54 |
Fun.protect ~finally:(fun () -> close_out ch) (fun () -> f ch) |
| 55 |
|
| 56 |
let parse_output = function |
| 57 |
| "-" -> Stdout |
| 58 |
| f -> File f |
| 59 |
|
| 60 |
let parse_min_diff d = |
| 61 |
try Q.of_float @@ float_of_string d |
| 62 |
with Failure _ -> usage () |
| 63 |
|
| 64 |
let rec parse_args opts = function |
| 65 |
| "-o" :: f :: args -> parse_args { opts with output = parse_output f } args |
| 66 |
| "-raw-o" :: f :: args -> parse_args { opts with raw_output = Some (parse_output f) } args |
| 67 |
| "-min-diff" :: d :: args -> parse_args { opts with min_diff = parse_min_diff d } args |
| 68 |
| ["-o"|"-raw-o"|"-min-diff"] -> usage() |
| 69 |
| args -> opts, parse_files args |
| 70 |
|
| 71 |
let file_data data_file = |
| 72 |
if List.exists (fun suf -> CString.is_suffix suf data_file) [".json"; ".json.gz"] then |
| 73 |
let data = Profparser.parse ~file:data_file in |
| 74 |
data_file, CArray.of_list data |
| 75 |
else |
| 76 |
let data = Timelogparser.parse ~file:data_file in |
| 77 |
data_file, data |> CArray.map_of_list (fun (loc, time) -> loc, { BenchUtil.time; memory = None; instructions = None }) |
| 78 |
|
| 79 |
let main args = |
| 80 |
let opts, (vfile, data_files) = parse_args defaults args in |
| 81 |
|
| 82 |
let source = BenchUtil.read_whole_file vfile in |
| 83 |
|
| 84 |
let all_data = Array.map file_data data_files in |
| 85 |
|
| 86 |
let all_data = BenchUtil.combine_related_data all_data in |
| 87 |
|
| 88 |
let dummy = Array.make (Array.length data_files) BenchUtil.dummy_data in |
| 89 |
|
| 90 |
let all_data = Array.of_list (Sourcehandler.join_to_source ~dummy ~source (Array.to_list all_data)) in |
| 91 |
|
| 92 |
let vname = Filename.basename vfile in |
| 93 |
|
| 94 |
let () = opts.raw_output |> Option.iter @@ with_output @@ fun ch -> |
| 95 |
Htmloutput.raw_output ch ~min_diff:opts.min_diff all_data |
| 96 |
in |
| 97 |
let () = opts.output |> with_output @@ fun ch -> |
| 98 |
Htmloutput.output ch ~vname ~data_files all_data |
| 99 |
in |
| 100 |
() |