@@ -561,6 +561,32 @@ module Make_commands (Backend : Backend_intf.S) = struct
561
561
{ Decode_opts. output_config; decode_opts; print_events }
562
562
;;
563
563
564
+ let open_url_flags =
565
+ let open Command.Param in
566
+ flag
567
+ " open-url"
568
+ (optional string )
569
+ ~doc:
570
+ " opens a url to display trace. options are local, magic, or android to open \
571
+ http://localhost:10000, https://magic-trace.org, or https://ui.perfetto.dev \
572
+ respectively"
573
+ |> map ~f: (fun user_input ->
574
+ Option. map user_input ~f: (fun user_choice ->
575
+ match user_choice with
576
+ | "local" -> " http://localhost:10000"
577
+ | "magic" -> " https://magic-trace.org"
578
+ | "android" -> " https://ui.perfetto.dev"
579
+ | _ -> raise_s [% message " unkown user input" (user_choice : string )]))
580
+ ;;
581
+
582
+ let use_processor_flag =
583
+ let open Command.Param in
584
+ flag
585
+ " use-processor-exe"
586
+ (optional string )
587
+ ~doc: " path for processor exe to use to process trace file"
588
+ ;;
589
+
564
590
let run_command =
565
591
Command. async_or_error
566
592
~summary: " Runs a command and traces it."
@@ -573,16 +599,16 @@ module Make_commands (Backend : Backend_intf.S) = struct
573
599
magic-trace run -multi-thread ./program -- arg1 arg2\n\n \
574
600
# Run a process, tracing its entire execution (only practical for short-lived \
575
601
processes)\n \
576
- magic-trace run -full-execution ./program\n " )
602
+ magic-trace run -full-execution ./program\n \
603
+ # Run a process that generates a large trace file, and view it on \
604
+ magic-trace.org magic-trace run ./program -open-url magic -use-processor-exe \
605
+ ~/local-trace-processor\n " )
577
606
(let % map_open.Command record_opt_fn = record_flags
578
607
and decode_opts = decode_flags
579
608
and debug_print_perf_commands = debug_print_perf_commands
580
609
and prog = anon (" COMMAND" %: string )
581
- and _local_view =
582
- flag
583
- " local-view"
584
- no_arg
585
- ~doc: " uses local trace processor binary, for use in large trace files"
610
+ and trace_processor_exe = use_processor_flag
611
+ and url = open_url_flags
586
612
and argv =
587
613
flag " --" escape ~doc: " ARGS Arguments for the command. Ignored by magic-trace."
588
614
in
@@ -594,31 +620,53 @@ module Make_commands (Backend : Backend_intf.S) = struct
594
620
| Some path -> path
595
621
| None -> failwithf " Can't find executable for %s" prog ()
596
622
in
597
- record_opt_fn ~executable ~f: (fun opts ->
598
- let elf = Elf. create opts.executable in
599
- let % bind range_symbols =
600
- evaluate_trace_filter ~trace_filter: opts.trace_filter ~elf
601
- in
602
- let % bind pid =
603
- let argv = prog :: List. concat (Option. to_list argv) in
604
- run_and_record
605
- opts
623
+ let % bind () =
624
+ record_opt_fn ~executable ~f: (fun opts ->
625
+ let elf = Elf. create opts.executable in
626
+ let % bind range_symbols =
627
+ evaluate_trace_filter ~trace_filter: opts.trace_filter ~elf
628
+ in
629
+ let % bind pid =
630
+ let argv = prog :: List. concat (Option. to_list argv) in
631
+ run_and_record
632
+ opts
633
+ ~elf
634
+ ~debug_print_perf_commands
635
+ ~prog
636
+ ~argv
637
+ ~collection_mode: opts.collection_mode
638
+ in
639
+ let % bind.Deferred perf_maps = Perf_map.Table. load_by_pids [ pid ] in
640
+ decode_to_trace
641
+ ~perf_maps
642
+ ?range_symbols
606
643
~elf
644
+ ~trace_scope: opts.trace_scope
607
645
~debug_print_perf_commands
608
- ~prog
609
- ~argv
646
+ ~record_dir: opts.record_dir
610
647
~collection_mode: opts.collection_mode
611
- in
612
- let % bind.Deferred perf_maps = Perf_map.Table. load_by_pids [ pid ] in
613
- decode_to_trace
614
- ~perf_maps
615
- ?range_symbols
616
- ~elf
617
- ~trace_scope: opts.trace_scope
618
- ~debug_print_perf_commands
619
- ~record_dir: opts.record_dir
620
- ~collection_mode: opts.collection_mode
621
- decode_opts))
648
+ decode_opts)
649
+ in
650
+ let % bind.Deferred () =
651
+ match url with
652
+ | None -> Deferred. return ()
653
+ | Some url -> Async_shell. run " open" [ url ]
654
+ in
655
+ let output_config = decode_opts.Decode_opts. output_config in
656
+ let output = Tracing_tool_output. output output_config in
657
+ let output_file =
658
+ match output with
659
+ | `Sexp _ -> failwith " unimplemented"
660
+ | `Fuchsia store_path -> store_path
661
+ in
662
+ let % bind.Deferred () =
663
+ match trace_processor_exe with
664
+ | None ->
665
+ print_endline " warning: must use local processor on large trace files" ;
666
+ Deferred. return ()
667
+ | Some processor_path -> Async_shell. run processor_path [ " -D" ; output_file ]
668
+ in
669
+ return () )
622
670
;;
623
671
624
672
let select_pid () =
@@ -769,83 +817,8 @@ module Make_commands (Backend : Backend_intf.S) = struct
769
817
decode_opts)
770
818
;;
771
819
772
- let auto_command =
773
- (* mostly copied from run_command *)
774
- Command. async_or_error
775
- ~summary: " Does work of run command and then calls trace_processor"
776
- ~readme: (fun () ->
777
- " === examples ===\n\n \
778
- # Run a process, snapshotting at ^C or exit\n \
779
- magic-trace run ./program -- arg1 arg2\n\n \
780
- # Run and trace all threads of a process, not just the main one, snapshotting \
781
- at ^C or exit\n \
782
- magic-trace run -multi-thread ./program -- arg1 arg2\n\n \
783
- # Run a process, tracing its entire execution (only practical for short-lived \
784
- processes)\n \
785
- magic-trace run -full-execution ./program\n " )
786
- (let % map_open.Command record_opt_fn = record_flags
787
- and decode_opts = decode_flags
788
- and debug_print_perf_commands = debug_print_perf_commands
789
- and prog = anon (" COMMAND" %: string )
790
- and _local_view =
791
- flag
792
- " local-view"
793
- no_arg
794
- ~doc: " uses local trace processor binary, for use in large trace files"
795
- and argv =
796
- flag " --" escape ~doc: " ARGS Arguments for the command. Ignored by magic-trace."
797
- in
798
- fun () ->
799
- let open Deferred.Or_error.Let_syntax in
800
- let % bind () = check_for_perf () in
801
- let executable =
802
- match Shell. which prog with
803
- | Some path -> path
804
- | None -> failwithf " Can't find executable for %s" prog ()
805
- in
806
- let % bind () =
807
- record_opt_fn ~executable ~f: (fun opts ->
808
- let elf = Elf. create opts.executable in
809
- let % bind range_symbols =
810
- evaluate_trace_filter ~trace_filter: opts.trace_filter ~elf
811
- in
812
- let % bind pid =
813
- let argv = prog :: List. concat (Option. to_list argv) in
814
- run_and_record
815
- opts
816
- ~elf
817
- ~debug_print_perf_commands
818
- ~prog
819
- ~argv
820
- ~collection_mode: opts.collection_mode
821
- in
822
- let % bind.Deferred perf_maps = Perf_map.Table. load_by_pids [ pid ] in
823
- decode_to_trace
824
- ~perf_maps
825
- ?range_symbols
826
- ~elf
827
- ~trace_scope: opts.trace_scope
828
- ~debug_print_perf_commands
829
- ~record_dir: opts.record_dir
830
- ~collection_mode: opts.collection_mode
831
- decode_opts)
832
- in
833
- (* let%bind.Deferred () =
834
- Async_shell.run "scp" [ "MAGICTRACE:/home/abena/magic-trace/trace.fxt"; "." ]
835
- in *)
836
- (* let%bind.Deferred () = Async_shell.run "open" [ "http://localhost:9001" ] in
837
- let%bind.Deferred () =
838
- Async_shell.run "~/trace_processor" [ "-D"; "trace.fxt" ]
839
- in *)
840
- return () )
841
- ;;
842
-
843
820
let commands =
844
- [ " run" , run_command
845
- ; " attach" , attach_command
846
- ; " decode" , decode_command
847
- ; " auto" , auto_command
848
- ]
821
+ [ " run" , run_command; " attach" , attach_command; " decode" , decode_command ]
849
822
;;
850
823
end
851
824
0 commit comments