From d008c3b9a3d0231d96388b3e33027b718df7c498 Mon Sep 17 00:00:00 2001 From: Ambre Austen Suhamy Date: Fri, 2 Sep 2022 17:16:59 +0200 Subject: [PATCH 1/3] Fix name printing not conform with old usage of orun (basename without extension) --- bin/olly.ml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bin/olly.ml b/bin/olly.ml index 2704963..ce6d24d 100644 --- a/bin/olly.ml +++ b/bin/olly.ml @@ -153,9 +153,11 @@ let latency json exec_args = | _ -> () in let init = Fun.id in - let cleanup () = - print_percentiles (List.hd @@ String.split_on_char ' ' exec_args) json hist + let name = + exec_args |> String.split_on_char ' ' |> List.hd |> Filename.basename + |> Filename.remove_extension in + let cleanup () = print_percentiles name json hist in olly ~runtime_begin ~runtime_end ~init ~cleanup exec_args let help man_format cmds topic = From b98b4730a9f2bb25f658a24ca6e48ac52e0d0506 Mon Sep 17 00:00:00 2001 From: Ambre Austen Suhamy Date: Fri, 2 Sep 2022 17:21:13 +0200 Subject: [PATCH 2/3] Added --output option to redirect printing to specific file --- bin/olly.ml | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/bin/olly.ml b/bin/olly.ml index ce6d24d..002d6a7 100644 --- a/bin/olly.ml +++ b/bin/olly.ml @@ -2,7 +2,7 @@ module H = Hdr_histogram module Ts = Runtime_events.Timestamp open Cmdliner -let print_percentiles name json hist = +let print_percentiles name json output hist = let ms ns = ns /. 1000000. in let mean_latency = H.mean hist |> ms and max_latency = float_of_int (H.max hist) |> ms in @@ -28,6 +28,7 @@ let print_percentiles name json hist = 100.0; |] in + let oc = match output with Some s -> open_out s | None -> stderr in if json then let distribs = List.init (Array.length percentiles) (fun i -> @@ -35,24 +36,23 @@ let print_percentiles name json hist = |> float_of_int |> ms |> string_of_float) |> String.concat "," in - Printf.printf - {|{"name": "%s", "mean_latency": %d, "max_latency: %d, "distr_latency": [%s]} - |} + Printf.fprintf oc + {|{"name": "%s", "mean_latency": %d, "max_latency: %d, "distr_latency": [%s]}|} name (int_of_float mean_latency) (int_of_float max_latency) distribs else ( - Printf.eprintf "\n"; - Printf.eprintf "GC latency profile:\n"; - Printf.eprintf "#[Mean (ms):\t%.2f,\t Stddev (ms):\t%.2f]\n" mean_latency + Printf.fprintf oc "\n"; + Printf.fprintf oc "GC latency profile:\n"; + Printf.fprintf oc "#[Mean (ms):\t%.2f,\t Stddev (ms):\t%.2f]\n" mean_latency (H.stddev hist |> ms); - Printf.eprintf "#[Min (ms):\t%.2f,\t max (ms):\t%.2f]\n" + Printf.fprintf oc "#[Min (ms):\t%.2f,\t max (ms):\t%.2f]\n" (float_of_int (H.min hist) |> ms) max_latency; - Printf.eprintf "\n"; - Printf.eprintf "Percentile \t Latency (ms)\n"; + Printf.fprintf oc "\n"; + Printf.fprintf oc "Percentile \t Latency (ms)\n"; Fun.flip Array.iter percentiles (fun p -> - Printf.eprintf "%.4f \t %.2f\n" p + Printf.fprintf oc "%.4f \t %.2f\n" p (float_of_int (H.value_at_percentile hist p) |> ms))) let lost_events ring_id num = @@ -133,7 +133,7 @@ let trace trace_filename exec_args = let cleanup () = close_out trace_file in olly ~runtime_begin ~runtime_end ~init ~cleanup exec_args -let latency json exec_args = +let latency json output exec_args = let current_event = Hashtbl.create 13 in let hist = H.init ~lowest_discernible_value:10 ~highest_trackable_value:10_000_000_000 @@ -157,7 +157,7 @@ let latency json exec_args = exec_args |> String.split_on_char ' ' |> List.hd |> Filename.basename |> Filename.remove_extension in - let cleanup () = print_percentiles name json hist in + let cleanup () = print_percentiles name json output hist in olly ~runtime_begin ~runtime_end ~init ~cleanup exec_args let help man_format cmds topic = @@ -227,6 +227,17 @@ let () = Arg.(value & flag & info [ "json" ] ~docv:"json" ~doc) in + let output_option = + let doc = + "Redirect the output of `olly` to specified file. The output of the \ + command is not redirected." + in + Arg.( + value + & opt (some string) None + & info [ "o"; "output" ] ~docv:"output" ~doc) + in + let latency_cmd = let man = [ @@ -237,7 +248,7 @@ let () = in let doc = "Report the GC latency profile." in let info = Cmd.info "latency" ~doc ~sdocs ~man in - Cmd.v info Term.(const latency $ json_option $ exec_args 0) + Cmd.v info Term.(const latency $ json_option $ output_option $ exec_args 0) in let help_cmd = From 1114d6b06fe66e32c2e4af1a4dd88e42775fce8f Mon Sep 17 00:00:00 2001 From: Ambre Austen Suhamy Date: Fri, 2 Sep 2022 18:17:09 +0200 Subject: [PATCH 3/3] Removed name handling in json as it could not be generalized --- bin/olly.ml | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/bin/olly.ml b/bin/olly.ml index 002d6a7..669352e 100644 --- a/bin/olly.ml +++ b/bin/olly.ml @@ -2,7 +2,7 @@ module H = Hdr_histogram module Ts = Runtime_events.Timestamp open Cmdliner -let print_percentiles name json output hist = +let print_percentiles json output hist = let ms ns = ns /. 1000000. in let mean_latency = H.mean hist |> ms and max_latency = float_of_int (H.max hist) |> ms in @@ -37,8 +37,7 @@ let print_percentiles name json output hist = |> String.concat "," in Printf.fprintf oc - {|{"name": "%s", "mean_latency": %d, "max_latency: %d, "distr_latency": [%s]}|} - name + {|{"mean_latency": %d, "max_latency": %d, "distr_latency": [%s]}|} (int_of_float mean_latency) (int_of_float max_latency) distribs else ( @@ -153,11 +152,7 @@ let latency json output exec_args = | _ -> () in let init = Fun.id in - let name = - exec_args |> String.split_on_char ' ' |> List.hd |> Filename.basename - |> Filename.remove_extension - in - let cleanup () = print_percentiles name json output hist in + let cleanup () = print_percentiles json output hist in olly ~runtime_begin ~runtime_end ~init ~cleanup exec_args let help man_format cmds topic =