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 optional command arguments in the end for "attach" command #267

Open
wants to merge 2 commits 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 @@ -20,6 +20,7 @@ module type S = sig

val attach_and_record
: Record_opts.t
-> cmd:string list
-> debug_print_perf_commands:bool
-> subcommand:Subcommand.t
-> when_to_snapshot:When_to_snapshot.t
Expand Down
2 changes: 2 additions & 0 deletions src/perf_tool_backend.ml
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ module Recording = struct

let attach_and_record
{ Record_opts.multi_thread; full_execution; snapshot_size; callgraph_mode }
~(cmd : string list)
~debug_print_perf_commands
~(subcommand : Subcommand.t)
~(when_to_snapshot : When_to_snapshot.t)
Expand Down Expand Up @@ -388,6 +389,7 @@ module Recording = struct
; kcore_opts
; snapshot_size_opt
; Callgraph_mode.to_perf_record_args selected_callgraph_mode
; cmd
]
in
if debug_print_perf_commands then Core.printf "%s\n%!" (String.concat ~sep:" " argv);
Expand Down
13 changes: 11 additions & 2 deletions src/trace.ml
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ module Make_commands (Backend : Backend_intf.S) = struct

let attach
(opts : Record_opts.t)
~cmd
~elf
~debug_print_perf_commands
~subcommand
Expand Down Expand Up @@ -349,6 +350,7 @@ module Make_commands (Backend : Backend_intf.S) = struct
let%map.Deferred.Or_error recording, recording_data =
Backend.Recording.attach_and_record
opts.backend_opts
~cmd
~debug_print_perf_commands
~subcommand
~when_to_snapshot:opts.when_to_snapshot
Expand Down Expand Up @@ -442,9 +444,11 @@ module Make_commands (Backend : Backend_intf.S) = struct
=
let open Deferred.Or_error.Let_syntax in
let pid = Ptrace.fork_exec_stopped ~prog ~argv () in
let cmd = [] in
let%bind attachment =
attach
record_opts
~cmd
~elf
~debug_print_perf_commands
~subcommand:Run
Expand Down Expand Up @@ -482,10 +486,11 @@ 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 ~cmd ~elf ~debug_print_perf_commands ~collection_mode pids =
let%bind.Deferred.Or_error attachment =
attach
record_opts
~cmd
~elf
~debug_print_perf_commands
~subcommand:Attach
Expand Down Expand Up @@ -676,10 +681,13 @@ module Make_commands (Backend : Backend_intf.S) = struct
magic-trace attach\n\n\
# Fuzzy-find to select a running process and symbol to trigger on, snapshotting \
the next time the symbol is called\n\
magic-trace attach -trigger ?\n")
magic-trace attach -trigger ?\n\n\
# Add a command in the end to forward it to perf\n\
magic-trace attach -trigger sym sleep 5\n\n")
(let%map_open.Command record_opt_fn = record_flags
and decode_opts = decode_flags
and debug_print_perf_commands = debug_print_perf_commands
and cmd = (anon (sequence ("command" %: string )))
and pids =
flag
"-pid"
Expand Down Expand Up @@ -717,6 +725,7 @@ module Make_commands (Backend : Backend_intf.S) = struct
let%bind () =
attach_and_record
opts
~cmd
~elf
~debug_print_perf_commands
~collection_mode
Expand Down