From c608902e910e340a4d2eefbed329737bb631651f Mon Sep 17 00:00:00 2001 From: Steven Woods Date: Mon, 10 Feb 2025 17:03:42 +0000 Subject: [PATCH] CP-45795: Decompress compressed trace files without Forkexecd This allows an xs_trace.exe to be run on any linux machine, whereas previously the use of forkexecd meant that it had to be run on a XS host. Signed-off-by: Steven Woods --- ocaml/xs-trace/xs_trace.ml | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/ocaml/xs-trace/xs_trace.ml b/ocaml/xs-trace/xs_trace.ml index e51847c9256..6360649fb20 100644 --- a/ocaml/xs-trace/xs_trace.ml +++ b/ocaml/xs-trace/xs_trace.ml @@ -20,7 +20,7 @@ module Exporter = struct if json <> "" then match Tracing_export.Destination.Http.export ~url json with | Error err -> - Printf.eprintf "Error: %s" (Printexc.to_string err) ; + Printf.eprintf "Error: %s\n" (Printexc.to_string err) ; exit 1 | _ -> () @@ -34,18 +34,17 @@ module Exporter = struct (* Recursively export trace files. *) Sys.readdir path |> Array.iter (fun f -> Filename.concat path f |> export_file) - | path when Filename.check_suffix path ".zst" -> - (* Decompress compressed trace file and decide whether to - treat it as line-delimited or not. *) - let ( let@ ) = ( @@ ) in - let@ compressed = Unixext.with_file path [O_RDONLY] 0o000 in - let@ decompressed = Zstd.Fast.decompress_passive compressed in - if Filename.check_suffix path ".ndjson.zst" then - let ic = Unix.in_channel_of_descr decompressed in - Unixext.lines_iter submit_json ic - else - let json = Unixext.string_of_fd decompressed in - submit_json json + | path when Filename.check_suffix path ".zst" -> ( + (* Decompress compressed trace file and submit each line iteratively *) + let args = [|"zstdcat"; path|] in + let ic = Unix.open_process_args_in args.(0) args in + Unixext.lines_iter submit_json ic ; + match Unix.close_process_in ic with + | Unix.WEXITED 0 -> + () + | _ -> + Printf.eprintf "File %s exited with non-zero\n" path + ) | path when Filename.check_suffix path ".ndjson" -> (* Submit traces line by line. *) Unixext.readfile_line submit_json path