diff --git a/core/backend_intf.ml b/core/backend_intf.ml index f3148f72d9..f384d01ab3 100644 --- a/core/backend_intf.ml +++ b/core/backend_intf.ml @@ -21,6 +21,7 @@ module type S = sig val attach_and_record : Record_opts.t -> debug_print_perf_commands:bool + -> debug_print_pid:bool -> subcommand:Subcommand.t -> when_to_snapshot:When_to_snapshot.t -> trace_scope:Trace_scope.t diff --git a/src/perf_tool_backend.ml b/src/perf_tool_backend.ml index 2ee32d916c..60625c58dc 100644 --- a/src/perf_tool_backend.ml +++ b/src/perf_tool_backend.ml @@ -216,6 +216,7 @@ module Recording = struct let attach_and_record { Record_opts.multi_thread; full_execution; snapshot_size; callgraph_mode } ~debug_print_perf_commands + ~debug_print_pid ~(subcommand : Subcommand.t) ~(when_to_snapshot : When_to_snapshot.t) ~(trace_scope : Trace_scope.t) @@ -392,6 +393,7 @@ module Recording = struct in if debug_print_perf_commands then Core.printf "%s\n%!" (String.concat ~sep:" " argv); (* Perf prints output we don't care about and --quiet doesn't work for some reason *) + if debug_print_pid then Core.printf "Passed PIDs to perf: %s\n%!" (String.concat~sep:"" pid_opt); let perf_pid = perf_fork_exec ~env:perf_env ~prog:"perf" ~argv () in (* This detaches the perf process from our "process group" but not our session. This makes it so that when Ctrl-C is sent to magic_trace in the terminal to end an attach diff --git a/src/trace.ml b/src/trace.ml index 7b73bd41db..41244d51af 100644 --- a/src/trace.ml +++ b/src/trace.ml @@ -75,6 +75,12 @@ let debug_print_perf_commands = |> debug_flag ;; +let debug_print_pid = + let open Command.Param in + flag "-z-print-pid" no_arg ~doc:"Prints the PIDs of the processes magic-trace attaches to." + |> debug_flag +;; + module Null_writer : Trace_writer_intf.S_trace = struct type thread = unit @@ -314,6 +320,7 @@ module Make_commands (Backend : Backend_intf.S) = struct (opts : Record_opts.t) ~elf ~debug_print_perf_commands + ~debug_print_pid ~subcommand ~collection_mode pids @@ -350,6 +357,7 @@ module Make_commands (Backend : Backend_intf.S) = struct Backend.Recording.attach_and_record opts.backend_opts ~debug_print_perf_commands + ~debug_print_pid ~subcommand ~when_to_snapshot:opts.when_to_snapshot ~trace_scope:opts.trace_scope @@ -436,6 +444,7 @@ module Make_commands (Backend : Backend_intf.S) = struct record_opts ~elf ~debug_print_perf_commands + ~debug_print_pid ~prog ~argv ~collection_mode @@ -447,6 +456,7 @@ module Make_commands (Backend : Backend_intf.S) = struct record_opts ~elf ~debug_print_perf_commands + ~debug_print_pid ~subcommand:Run ~collection_mode [ pid ] @@ -482,12 +492,13 @@ module Make_commands (Backend : Backend_intf.S) = struct return pid ;; - let attach_and_record record_opts ~elf ~debug_print_perf_commands ~collection_mode pids = + let attach_and_record record_opts ~elf ~debug_print_perf_commands ~debug_print_pid ~collection_mode pids = let%bind.Deferred.Or_error attachment = attach record_opts ~elf ~debug_print_perf_commands + ~debug_print_pid ~subcommand:Attach ~collection_mode pids @@ -585,6 +596,7 @@ module Make_commands (Backend : Backend_intf.S) = struct (let%map_open.Command record_opt_fn = record_flags and decode_opts = decode_flags and debug_print_perf_commands = debug_print_perf_commands + and debug_print_pid = debug_print_pid and prog = anon ("COMMAND" %: string) and argv = flag "--" escape ~doc:"ARGS Arguments for the command. Ignored by magic-trace." @@ -608,6 +620,7 @@ module Make_commands (Backend : Backend_intf.S) = struct opts ~elf ~debug_print_perf_commands + ~debug_print_pid ~prog ~argv ~collection_mode:opts.collection_mode @@ -680,6 +693,7 @@ module Make_commands (Backend : Backend_intf.S) = struct (let%map_open.Command record_opt_fn = record_flags and decode_opts = decode_flags and debug_print_perf_commands = debug_print_perf_commands + and debug_print_pid = debug_print_pid and pids = flag "-pid" @@ -719,6 +733,7 @@ module Make_commands (Backend : Backend_intf.S) = struct opts ~elf ~debug_print_perf_commands + ~debug_print_pid ~collection_mode pids in