Skip to content

Commit

Permalink
CP-45795: Decompress compressed trace files without Forkexecd
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.

Signed-off-by: Steven Woods <steven.woods@citrix.com>
  • Loading branch information
snwoods committed Feb 11, 2025
1 parent 132efb9 commit 69bb471
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions ocaml/xs-trace/xs_trace.ml
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,16 @@ 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 ic = Unix.open_process_in (Printf.sprintf "zstdcat %s" path) 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" 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 69bb471

Please # to comment.