Skip to content

Commit f146978

Browse files
authored
CP-45795: Decompress compressed trace files without Forkexecd (#6293)
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).
2 parents abd993a + c608902 commit f146978

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

ocaml/xs-trace/xs_trace.ml

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module Exporter = struct
2020
if json <> "" then
2121
match Tracing_export.Destination.Http.export ~url json with
2222
| Error err ->
23-
Printf.eprintf "Error: %s" (Printexc.to_string err) ;
23+
Printf.eprintf "Error: %s\n" (Printexc.to_string err) ;
2424
exit 1
2525
| _ ->
2626
()
@@ -34,18 +34,17 @@ module Exporter = struct
3434
(* Recursively export trace files. *)
3535
Sys.readdir path
3636
|> Array.iter (fun f -> Filename.concat path f |> export_file)
37-
| path when Filename.check_suffix path ".zst" ->
38-
(* Decompress compressed trace file and decide whether to
39-
treat it as line-delimited or not. *)
40-
let ( let@ ) = ( @@ ) in
41-
let@ compressed = Unixext.with_file path [O_RDONLY] 0o000 in
42-
let@ decompressed = Zstd.Fast.decompress_passive compressed in
43-
if Filename.check_suffix path ".ndjson.zst" then
44-
let ic = Unix.in_channel_of_descr decompressed in
45-
Unixext.lines_iter submit_json ic
46-
else
47-
let json = Unixext.string_of_fd decompressed in
48-
submit_json json
37+
| path when Filename.check_suffix path ".zst" -> (
38+
(* Decompress compressed trace file and submit each line iteratively *)
39+
let args = [|"zstdcat"; path|] in
40+
let ic = Unix.open_process_args_in args.(0) args in
41+
Unixext.lines_iter submit_json ic ;
42+
match Unix.close_process_in ic with
43+
| Unix.WEXITED 0 ->
44+
()
45+
| _ ->
46+
Printf.eprintf "File %s exited with non-zero\n" path
47+
)
4948
| path when Filename.check_suffix path ".ndjson" ->
5049
(* Submit traces line by line. *)
5150
Unixext.readfile_line submit_json path

0 commit comments

Comments
 (0)