@@ -892,12 +892,16 @@ Some code to analyze the list of executed commands:
892
892
{[
893
893
(** Return the list of executed commands where the first argument was [cmd]. *)
894
894
let filter_commands cmd =
895
- List.filter
896
- (fun c ->
897
- match Bos.Cmd.to_list c.cmd with
898
- | _ :: cmd' :: _ -> cmd = cmd'
899
- | _ -> false)
900
- !commands
895
+ match
896
+ List.filter
897
+ (fun c ->
898
+ match Bos.Cmd.to_list c.cmd with
899
+ | _ :: cmd' :: _ -> cmd = cmd'
900
+ | _ -> false)
901
+ !commands
902
+ with
903
+ | [] -> failwith ("No commands run for " ^ cmd)
904
+ | (_ :: _) as cmds -> cmds
901
905
902
906
(** Returns the [k] commands that took the most time for a given subcommand. *)
903
907
let k_longest_commands cmd k =
@@ -932,80 +936,79 @@ This last block analyze the running times so that they can be submitted to
932
936
(* *)
933
937
#require "yojson" ;;
934
938
939
+ let rec compute_min_max_avg min_ max_ total count = function
940
+ | [] -> (min_, max_, total /. float count, count)
941
+ | hd :: tl ->
942
+ compute_min_max_avg (min min_ hd) (max max_ hd) (total +. hd) (count + 1) tl
943
+
944
+ let compute_min_max_avg = function
945
+ | [] -> assert false
946
+ | hd :: tl -> compute_min_max_avg hd hd hd 1 tl
947
+
935
948
(** Analyze the running time of a command. *)
936
949
let compute_metric_cmd cmd =
937
- let rec compute min_ max_ total count = function
938
- | [] -> (min_, max_, total /. float count, count)
939
- | hd :: tl ->
940
- compute (min min_ hd.time) (max max_ hd.time) (total +. hd.time) (count + 1) tl
941
- in
942
- match filter_commands cmd with
943
- | [] -> failwith ("No commands run for " ^ cmd)
944
- | hd :: tl ->
945
- let min, max, avg, count = compute hd.time hd.time hd.time 1 tl in
950
+ let cmds = filter_commands cmd in
951
+ let times = List.map (fun c -> c.time) cmds in
952
+ let min, max, avg, count = compute_min_max_avg times in
953
+ [
954
+ `Assoc
946
955
[
947
- `Assoc
948
- [
949
- ("name", `String ("total-" ^ cmd));
950
- ("value", `Int count);
951
- ( "description",
952
- `String ("Number of time 'odoc " ^ cmd ^ "' has run.") );
953
- ];
954
- `Assoc
955
- [
956
- ("name", `String ("time-" ^ cmd));
957
- ( "value",
958
- `Assoc
959
- [
960
- ("min", `Float min); ("max", `Float max); ("avg", `Float avg);
961
- ] );
962
- ("units", `String "s");
963
- ("description", `String ("Time taken by 'odoc " ^ cmd ^ "'"));
964
- ("trend", `String "lower-is-better");
965
- ];
966
- ]
956
+ ("name", `String ("total-" ^ cmd));
957
+ ("value", `Int count);
958
+ ( "description",
959
+ `String ("Number of time 'odoc " ^ cmd ^ "' has run.") );
960
+ ];
961
+ `Assoc
962
+ [
963
+ ("name", `String ("time-" ^ cmd));
964
+ ( "value",
965
+ `Assoc
966
+ [
967
+ ("min", `Float min); ("max", `Float max); ("avg", `Float avg);
968
+ ] );
969
+ ("units", `String "s");
970
+ ("description", `String ("Time taken by 'odoc " ^ cmd ^ "'"));
971
+ ("trend", `String "lower-is-better");
972
+ ];
973
+ ]
967
974
968
975
(** Analyze the size of files produced by a command. *)
969
976
let compute_produced_cmd cmd =
970
977
let output_file_size c =
971
978
match c.output_file with
972
979
| Some f -> (
973
980
match Bos.OS.Path.stat f with
974
- | Ok st -> Some st.Unix.st_size
981
+ | Ok st -> Some (float st.Unix.st_size)
975
982
| Error _ -> None)
976
983
| None -> None
977
984
in
978
- let rec compute min_ max_ total count = function
979
- | [] -> (min_, max_, int_of_float (total /. float count), count)
980
- | size :: tl ->
981
- compute (min min_ size) (max max_ size) (total +. float size) (count + 1) tl
982
- in
983
- match List.filter_map output_file_size (filter_commands cmd) with
984
- | [] -> failwith ("No commands run for " ^ cmd)
985
- | size0 :: tl ->
986
- let min, max, avg, count = compute size0 size0 (float size0) 1 tl in
985
+ let sizes = List.filter_map output_file_size (filter_commands cmd) in
986
+ let min, max, avg, count = compute_min_max_avg sizes in
987
+ let min = int_of_float min in
988
+ let max = int_of_float max in
989
+ let avg = int_of_float avg in
990
+ [
991
+ `Assoc
987
992
[
988
- `Assoc
989
- [
990
- ("name", `String ("produced-total-" ^ cmd));
991
- ("value", `Int count);
992
- ( "description",
993
- `String ("Number of file produced by 'odoc " ^ cmd ^ "'") );
994
- ];
995
- `Assoc
996
- [
997
- ("name", `String ("produced-size-" ^ cmd));
998
- ( "value",
999
- `Assoc
1000
- [
1001
- ("min", `Int min); ("max", `Int max); ("avg", `Int avg);
1002
- ] );
1003
- ("units", `String "b");
1004
- ( "description",
1005
- `String ("Size of file produced by 'odoc " ^ cmd ^ "'") );
1006
- ("trend", `String "lower-is-better");
1007
- ];
1008
- ]
993
+ ("name", `String ("produced-total-" ^ cmd));
994
+ ("value", `Int count);
995
+ ( "description",
996
+ `String ("Number of file produced by 'odoc " ^ cmd ^ "'") );
997
+ ];
998
+ `Assoc
999
+ [
1000
+ ("name", `String ("produced-size-" ^ cmd));
1001
+ ( "value",
1002
+ `Assoc
1003
+ [
1004
+ ("min", `Int min); ("max", `Int max); ("avg", `Int avg);
1005
+ ] );
1006
+ ("units", `String "b");
1007
+ ( "description",
1008
+ `String ("Size of file produced by 'odoc " ^ cmd ^ "'") );
1009
+ ("trend", `String "lower-is-better");
1010
+ ];
1011
+ ]
1009
1012
1010
1013
(** Analyze the size of files produced by a command. *)
1011
1014
let compute_longest_cmd cmd =
0 commit comments