Skip to content

Commit

Permalink
v0.15~preview.126.09+332
Browse files Browse the repository at this point in the history
  • Loading branch information
aalekseyev committed Feb 15, 2022
1 parent ffdb310 commit 2b5c4ac
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
2 changes: 2 additions & 0 deletions bin/magic_trace_bin-help-for-review.org
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
: [-executable-override FILE]
: . executable to extract information from, default
: is to use the first part of COMMAND
: [-full-execution] . record full program execution
: [-http-port PORT] . http server port
: [-immediate-stop] . stop immediately on snapshot, may crash kernel on
: EL8
Expand Down Expand Up @@ -195,6 +196,7 @@
: [-executable-override FILE]
: . executable to extract information from, default
: is to use the first part of COMMAND
: [-full-execution] . record full program execution
: [-http-port PORT] . http server port
: [-immediate-stop] . stop immediately on snapshot, may crash kernel on
: EL8
Expand Down
4 changes: 2 additions & 2 deletions magic-trace.opam
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
opam-version: "2.0"
maintainer: "[email protected]"
authors: ["Jane Street Group, LLC <[email protected]>"]
maintainer: "Jane Street developers"
authors: ["Jane Street Group, LLC"]
homepage: "https://github.com/janestreet/magic-trace"
bug-reports: "https://github.com/janestreet/magic-trace/issues"
dev-repo: "git+https://github.com/janestreet/magic-trace.git"
Expand Down
29 changes: 20 additions & 9 deletions src/perf_tool_backend.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,24 @@ open! Core
open! Async
open! Import

type record_opts = { multi_thread : bool }
type record_opts =
{ multi_thread : bool
; full_execution : bool
}

let record_param =
let%map_open.Command multi_thread =
flag "-multi-thread" no_arg ~doc:"record multiple threads"
and full_execution =
flag "-full-execution" no_arg ~doc:"record full program execution"
in
{ multi_thread }
{ multi_thread; full_execution }
;;

type recording = Pid.t
type recording =
{ can_snapshot : bool
; pid : Pid.t
}

let debug_perf_commands = false

Expand All @@ -34,7 +42,7 @@ let supports_cyc () =
supports_cyc
;;

let attach_and_record { multi_thread } ~record_dir ?filter pid =
let attach_and_record { multi_thread; full_execution } ~record_dir ?filter pid =
let opts =
match filter with
| None -> []
Expand All @@ -55,7 +63,8 @@ let attach_and_record { multi_thread } ~record_dir ?filter pid =
let argv =
[ "perf"; "record"; "-o"; record_dir ^/ "perf.data"; ev_arg; "--timestamp" ]
@ thread_opts
@ [ Pid.to_int pid |> Int.to_string; "--snapshot" ]
@ [ Pid.to_int pid |> Int.to_string ]
@ (if full_execution then [] else [ "--snapshot" ])
@ opts
in
if debug_perf_commands then Core.printf "%s\n%!" (String.concat ~sep:" " argv);
Expand All @@ -75,15 +84,17 @@ let attach_and_record { multi_thread } ~record_dir ?filter pid =
| Some (_, exit) -> perf_exit_to_or_error exit
| _ -> Ok ()
in
perf_pid
{ can_snapshot = not full_execution; pid = perf_pid }
;;

let take_snapshot pid =
Signal_unix.send_i Signal.usr2 (`Pid pid);
let take_snapshot { pid; can_snapshot } =
if can_snapshot
then Signal_unix.send_i Signal.usr2 (`Pid pid)
else Core.eprintf "[Warning: Snapshotting during a full-execution tracing]\n%!";
Or_error.return ()
;;

let finish_recording pid =
let finish_recording { pid; _ } =
Signal_unix.send_i Signal.term (`Pid pid);
(* This should usually be a signal exit, but we don't really care, if it didn't produce
a good perf.data file the next step will fail. *)
Expand Down

0 comments on commit 2b5c4ac

Please sign in to comment.