Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements to benchmarks and profiling #1012

Merged
merged 3 commits into from
Oct 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 45 additions & 13 deletions doc/driver.mld
Original file line number Diff line number Diff line change
Expand Up @@ -169,23 +169,34 @@ type executed_command = {
the produced file. *)
let commands = ref [ ]

let instrument_dir =
lazy (
let dir = Fpath.v "landmarks" in
OS.Dir.delete dir |> get_ok;
OS.Dir.create dir |> get_ok |> ignore;
dir
)

(* Environment variables passed to commands. *)
let env =
let env = OS.Env.current () |> get_ok in
let env = OS.Env.current () |> get_ok

let run ?output_file cmd =
let t_start = Unix.gettimeofday () in
let env =
if instrument then (
let instrument_dir = Fpath.v "landmarks" in
OS.Dir.delete instrument_dir |> get_ok;
OS.Dir.create instrument_dir |> get_ok |> ignore;
if instrument then
let lazy instrument_dir = instrument_dir in
let instrument_out =
match output_file with
| Some outf ->
Fpath.(/) instrument_dir (Fpath.basename outf ^ ".json")
|> Fpath.to_string
| None -> "temporary:" ^ Fpath.to_string instrument_dir
in
Astring.String.Map.add "OCAML_LANDMARKS"
("time,allocation,format=json,output=temporary:" ^ Fpath.to_string instrument_dir)
("time,allocation,format=json,output=" ^ instrument_out)
env
) else env
else env
in
env

let run ?output_file cmd =
let t_start = Unix.gettimeofday () in
let r = OS.Cmd.(run_out ~env ~err:OS.Cmd.err_run_out cmd |> to_lines) |> get_ok in
let t_end = Unix.gettimeofday () in
let time = t_end -. t_start in
Expand Down Expand Up @@ -793,7 +804,7 @@ If needed, the list of the slowest commands for each subcommands can be shown by
(for the record, these commands are run from directory `_build/default/doc`)

{[
# List.iter print_cmd (k_longest_commands "compile" 5)
# (* List.iter print_cmd (k_longest_commands "compile" 5) *)
# (* List.iter print_cmd (k_longest_commands "link" 5) *)
# (* List.iter print_cmd (k_longest_commands "html-generate" 5) *)
]}
Expand Down Expand Up @@ -880,11 +891,32 @@ let compute_produced_cmd cmd =
];
]

(** Analyze the size of files produced by a command. *)
let compute_longest_cmd cmd =
match k_longest_commands cmd 1 with
| hd :: _ ->
[
`Assoc
[
("name", `String ("longest-" ^ cmd));
("value", `Float hd.time);
("units", `String "s");
( "description",
`String
("Time taken by the longest invokation of 'odoc " ^ cmd ^ "'")
);
("trend", `String "lower-is-better");
];
]
| [] -> []

let metrics =
compute_metric_cmd "compile"
@ compute_metric_cmd "compile-deps"
@ compute_metric_cmd "link"
@ compute_metric_cmd "html-generate"
@ compute_longest_cmd "compile"
@ compute_longest_cmd "link"
@ compute_produced_cmd "compile"
@ compute_produced_cmd "link"

Expand Down
Loading