Skip to content

Commit

Permalink
CP-45795: Decompress compressed trace files without Forkexecd (#6293)
Browse files Browse the repository at this point in the history
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. It also allows the logic to be simplified (json and ndjson can be
handled in the same way).
  • Loading branch information
lindig authored Feb 20, 2025
2 parents abd993a + c608902 commit f146978
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions ocaml/xs-trace/xs_trace.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
| _ ->
()
Expand All @@ -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
Expand Down

0 comments on commit f146978

Please # to comment.