Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add print PID option under MAGIC_TRACE_DEBUG (-z-print-pid) #266

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/backend_intf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/perf_tool_backend.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -392,6 +393,9 @@ 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);
(* No need to format `pid_opt` again, since it already is a list of comma separated PIDs *)
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
Expand Down
27 changes: 26 additions & 1 deletion src/trace.ml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ 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

Expand Down Expand Up @@ -314,6 +323,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
Expand Down Expand Up @@ -350,6 +360,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
Expand Down Expand Up @@ -436,6 +447,7 @@ module Make_commands (Backend : Backend_intf.S) = struct
record_opts
~elf
~debug_print_perf_commands
~debug_print_pid
~prog
~argv
~collection_mode
Expand All @@ -447,6 +459,7 @@ module Make_commands (Backend : Backend_intf.S) = struct
record_opts
~elf
~debug_print_perf_commands
~debug_print_pid
~subcommand:Run
~collection_mode
[ pid ]
Expand Down Expand Up @@ -482,12 +495,20 @@ 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
Expand Down Expand Up @@ -585,6 +606,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."
Expand All @@ -608,6 +630,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
Expand Down Expand Up @@ -680,6 +703,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"
Expand Down Expand Up @@ -719,6 +743,7 @@ module Make_commands (Backend : Backend_intf.S) = struct
opts
~elf
~debug_print_perf_commands
~debug_print_pid
~collection_mode
pids
in
Expand Down