@@ -24,12 +24,21 @@ let tracefile =
2424 Arg. (value @@ opt string " trace.fxt" @@ info [" f" ; " tracefile" ] ~docv: " PATH" ~doc )
2525
2626let tracefiles =
27- let doc = " The path of the trace file(s)." in
27+ let doc = " The path of the trace file(s). The default is trace.fxt. " in
2828 Arg. (value @@ pos_all string [" trace.fxt" ] @@ info [] ~docv: " PATH" ~doc )
2929
3030let imagefile =
31- let doc = " The path of the output image." in
32- Arg. (required @@ pos 0 (some string ) None @@ info [] ~docv: " OUTPUT" ~doc )
31+ let doc = " The path of the output image. The default is the input path with the new type extension." in
32+ Arg. (value @@ opt (some string ) None @@ info [" o" ; " output" ] ~docv: " OUTPUT" ~doc )
33+
34+ let fmt =
35+ let doc = " Output image file-type." in
36+ let formats = Arg. enum [
37+ " png" , " .png" ;
38+ " svg" , " .svg" ;
39+ ]
40+ in
41+ Arg. (value @@ opt (some formats) None @@ info [" T" ; " format" ] ~docv: " TYPE" ~doc )
3342
3443let freq =
3544 let doc = " How many times per second to check for events." in
@@ -80,29 +89,39 @@ let run ~fs ~proc_mgr freq args =
8089
8190let record ~fs ~proc_mgr freq tracefile args =
8291 Record. run ~fs ~proc_mgr ~freq ~tracefile args
83-
84- let render tracefile output start_time duration =
85- match Filename. extension output with
86- | "" -> Fmt. error " No extension on %S; can't determine format" output
87- | " .svg"
88- | ".png" as format ->
89- let start_time = Option. value start_time ~default: 0.0 |> string_of_float in
90- let duration = Option. map string_of_float duration |> Option. value ~default: " " in
91- exec_gtk [" render-svg" ; tracefile; format; output; start_time; duration]
92- | _ ->
93- Fmt. error " Unknown file extension in %S (should end in e.g. '.svg')" output
92+
93+ let ( let * ) = Result. bind
94+
95+ let render tracefiles output fmt start_time duration =
96+ let * fmt =
97+ match fmt, output with
98+ | None , None -> Ok " .svg"
99+ | _ , Some _ when List. length tracefiles > 1 -> Error " Can't use --output with multiple input files"
100+ | Some x , _ -> Ok x
101+ | None , Some output ->
102+ match Filename. extension output with
103+ | "" -> Fmt. error " No extension on %S; can't determine format" output
104+ | " .svg"
105+ | ".png" as f -> Ok f
106+ | _ ->
107+ Fmt. error " Unknown file extension in %S (should end in e.g. '.svg')" output
108+ in
109+ let start_time = Option. value start_time ~default: 0.0 |> string_of_float in
110+ let duration = Option. map string_of_float duration |> Option. value ~default: " " in
111+ let output = Option. value output ~default: " " in
112+ exec_gtk @@ " render-svg" :: fmt :: output :: start_time :: duration :: tracefiles
94113
95114let cmd env =
96115 let fs = Eio.Stdenv. fs env in
97116 let proc_mgr = Eio.Stdenv. process_mgr env in
98- let path x = Eio.Path. ( / ) fs $$ x in
117+ let path = Eio.Path. ( / ) fs in
99118 Cmd. group (Cmd. info " eio-trace" )
100119 @@ List. map (fun (name , term ) -> Cmd. v (Cmd. info name) term) [
101- " record" , record ~fs ~proc_mgr $$ freq $ path tracefile $ child_args;
102- " dump" , Dump. main Format. std_formatter $$ path tracefile ;
120+ " record" , record ~fs ~proc_mgr $$ freq $ ( path $$ tracefile) $ child_args;
121+ " dump" , Dump. main Format. std_formatter $$ ( List. map path $$ tracefiles) ;
103122 " run" , run ~fs ~proc_mgr $$ freq $ child_args;
104123 " show" , show $$ tracefiles;
105- " render" , render $$ tracefile $ imagefile $ start_time $ duration;
124+ " render" , render $$ tracefiles $ imagefile $ fmt $ start_time $ duration;
106125 ]
107126
108127let () =
0 commit comments