| 1 |
|
| 2 |
|
| 3 |
let list_timediff_files dir = |
| 4 |
let rec loop result = function |
| 5 |
| f :: fs when Sys.is_directory f -> |
| 6 |
Sys.readdir f |
| 7 |
|> Array.to_list |
| 8 |
|> CList.map (Filename.concat f) |
| 9 |
|> CList.append fs |
| 10 |
|> loop result |
| 11 |
| f :: fs -> |
| 12 |
if Filename.check_suffix f ".rocq-timediff" then |
| 13 |
loop (f::result) fs |
| 14 |
else |
| 15 |
loop result fs |
| 16 |
| [] -> result |
| 17 |
in |
| 18 |
Sys.readdir dir |
| 19 |
|> Array.to_list |
| 20 |
|> loop [] |
| 21 |
|
| 22 |
type one_data = { |
| 23 |
time1 : string; |
| 24 |
time2 : string; |
| 25 |
diff : string; |
| 26 |
pdiff : string; |
| 27 |
lnum : string; |
| 28 |
file : string; |
| 29 |
} |
| 30 |
|
| 31 |
exception UnableToParse |
| 32 |
|
| 33 |
|
| 34 |
let read_timing_lines file = |
| 35 |
let ic = open_in file in |
| 36 |
let html_file = (Filename.chop_extension file) ^ ".html" in |
| 37 |
|
| 38 |
let rec read_lines_aux acc = |
| 39 |
match input_line ic with |
| 40 |
| exception End_of_file -> acc |
| 41 |
| "" -> read_lines_aux acc |
| 42 |
| line -> |
| 43 |
match String.split_on_char ' ' line with |
| 44 |
| [time1; time2; diff; pdiff; lnum] -> |
| 45 |
{time1; time2; diff; pdiff; lnum; file=html_file} :: acc |> read_lines_aux |
| 46 |
| _ -> raise UnableToParse |
| 47 |
in |
| 48 |
let lines = |
| 49 |
try Some (read_lines_aux []) |
| 50 |
with End_of_file -> |
| 51 |
Printf.eprintf "*** Error: Could not read file %s.\n" file; None |
| 52 |
in |
| 53 |
close_in ic; lines |
| 54 |
|
| 55 |
type html_data = { link_prefix : string } |
| 56 |
|
| 57 |
let get_html_data () = |
| 58 |
match Sys.getenv_opt "CI_PAGES_DOMAIN", |
| 59 |
Sys.getenv_opt "CI_PROJECT_NAMESPACE", |
| 60 |
Sys.getenv_opt "CI_PROJECT_NAME", |
| 61 |
Sys.getenv_opt "CI_JOB_ID" with |
| 62 |
| Some domain, Some ns, Some project, Some id -> |
| 63 |
Some { link_prefix = |
| 64 |
Printf.sprintf "https://%s.%s/-/%s/-/jobs/%s/artifacts/_bench/html/" |
| 65 |
ns domain project id } |
| 66 |
| None, _, _, _ | _, None, _, _ | _, _, None, _ | _, _, _, None -> None |
| 67 |
|
| 68 |
let html_str ?html lnum s = match html with |
| 69 |
| None -> Table.raw_str s |
| 70 |
| Some html -> |
| 71 |
let size = String.length s in |
| 72 |
let s = Printf.sprintf "<a href=\"%s%s#L%s\">%s</a>" html.link_prefix s lnum s in |
| 73 |
{ Table.str = s; size } |
| 74 |
|
| 75 |
let list_timing_data ?html {time1; time2; diff; pdiff; lnum; file} = |
| 76 |
List.append |
| 77 |
(List.map Table.raw_str [ time1; time2; diff; pdiff; lnum]) |
| 78 |
[ html_str ?html lnum file ] |
| 79 |
|
| 80 |
let render_table ?(reverse=false) title num table = |
| 81 |
let open Table.Align in |
| 82 |
let headers = [Table.raw_str title] in |
| 83 |
let top = Table.raw_row [["OLD"; "NEW"; "DIFF"; "%DIFF"; "Ln"; "FILE"]] in |
| 84 |
let align_top = [[Middle; Middle; Middle; Middle; Middle; MidLeft]] in |
| 85 |
let align_rows = [[Right; Right; Right; Right; Right; Left]] in |
| 86 |
(if reverse then CList.rev table else table) |
| 87 |
|> CList.firstn num |
| 88 |
|> fun x -> Table.print headers top x ~align_top ~align_rows () |
| 89 |
|
| 90 |
let to_file fname fmt = |
| 91 |
Printf.kfprintf close_out (open_out fname) fmt |
| 92 |
|
| 93 |
let main () = |
| 94 |
let () = Printexc.record_backtrace true in |
| 95 |
let data = |
| 96 |
Unix.getcwd () |
| 97 |
|> list_timediff_files |
| 98 |
|> CList.filter_map read_timing_lines |
| 99 |
|> CList.flatten |
| 100 |
|> CList.sort (fun x y -> Float.compare (float_of_string x.diff) (float_of_string y.diff)) |
| 101 |
in |
| 102 |
let table = |
| 103 |
data |
| 104 |
|> CList.map list_timing_data |
| 105 |
|> CList.map (fun x -> [ x ]) |
| 106 |
in |
| 107 |
|
| 108 |
let num = 25 in |
| 109 |
let num = min num (CList.length table) in |
| 110 |
let slow_table = render_table (Printf.sprintf "TOP %d SLOW DOWNS" num) ~reverse:true num table in |
| 111 |
let fast_table = render_table (Printf.sprintf "TOP %d SPEED UPS" num) num table in |
| 112 |
let timings_table = render_table "Significant line time changes in bench" (CList.length table) table in |
| 113 |
|
| 114 |
Printf.printf "%s\n%s\n" slow_table fast_table; |
| 115 |
|
| 116 |
to_file "slow_table" "%s\n" slow_table; |
| 117 |
to_file "fast_table" "%s\n" fast_table; |
| 118 |
to_file "timings_table" "%s\n" timings_table; |
| 119 |
|
| 120 |
match get_html_data () with |
| 121 |
| None -> () |
| 122 |
| Some html -> |
| 123 |
let table = |
| 124 |
data |
| 125 |
|> CList.map (list_timing_data ~html) |
| 126 |
|> CList.map (fun x -> [ x ]) |
| 127 |
in |
| 128 |
let slow_table = render_table (Printf.sprintf "TOP %d SLOW DOWNS" num) ~reverse:true num table in |
| 129 |
let fast_table = render_table (Printf.sprintf "TOP %d SPEED UPS" num) num table in |
| 130 |
let timings_table = render_table "Significant line time changes in bench" (CList.length table) table in |
| 131 |
to_file "slow_table.html" "<pre>%s</pre>\n" slow_table; |
| 132 |
to_file "fast_table.html" "<pre>%s</pre>\n" fast_table; |
| 133 |
to_file "timings_table.html" "<pre>%s</pre>\n" timings_table; |
| 134 |
() |
| 135 |
|
| 136 |
|
| 137 |
let () = main () |