-
Notifications
You must be signed in to change notification settings - Fork 95
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 use-trace-processor-shell flag to automate large trace processing #248
base: master
Are you sure you want to change the base?
Add use-trace-processor-shell flag to automate large trace processing #248
Conversation
salaast
commented
Jul 18, 2022
- Add use-processor-exe and open-url flags to run_command in trace.ml to automate large trace file processing and ui url opening
4b1ee1e
to
08e21a9
Compare
Signed-off-by: Abena Laast <[email protected]>
… to allow large trace processing and url opening automation Signed-off-by: Abena Laast <[email protected]>
Signed-off-by: Abena Laast <[email protected]>
08e21a9
to
39fc733
Compare
src/trace.ml
Outdated
@@ -561,6 +561,32 @@ module Make_commands (Backend : Backend_intf.S) = struct | |||
{ Decode_opts.output_config; decode_opts; print_events } | |||
;; | |||
|
|||
let open_url_flags = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should allow configuration of this through envvars in env_vars.ml
, rather than as commandline parameters. These choices tend to be sticky, so it's nicer to not have users have to specify them over and over.
I'd say a MAGIC_TRACE_WEB_UI_URL
that can be any string, and which defaults to https://magic-trace.org
, would be sufficient here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once I implement the Env_vars configuration, should I use the commandline flag to indicate whether the user wants to display the ui, or should it always be displayed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think for now, we should have a separate flag for if the trace processor shell should be used, if available. Maybe in the future we can make the selection automatic using some heuristic based on the size of the trace file (and whether we expect a browser to safely open it), but let's hold off on that bit for now.
src/trace.ml
Outdated
| _ -> raise_s [%message "unkown user input" (user_choice : string)])) | ||
;; | ||
|
||
let use_processor_flag = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should take the path via an envvar, e.g. MAGIC_TRACE_PROCESSOR_SHELL_PATH
; then we can have an optional -use-trace-processor-shell
flag if that envvar is set. See
magic-trace/src/tracing_tool_output.ml
Line 15 in 872c648
match Env_vars.perfetto_dir with |
We may also want to consider just using the trace processor shell automatically, past a certain filesize, but I haven't given that much thought.
src/trace.ml
Outdated
| None -> | ||
print_endline "warning: must use local processor on large trace files"; | ||
Deferred.return () | ||
| Some processor_path -> Async_shell.run processor_path [ "-D"; output_file ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use something like
magic-trace/src/perf_tool_backend.ml
Line 70 in 872c648
let perf_fork_exec ?env ~prog ~argv () = |
process.ml
or something.
src/trace.ml
Outdated
decode_opts)) | ||
decode_opts) | ||
in | ||
let%bind.Deferred () = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I don't think we should do this. Oftentimes we'll run magic-trace attach ... -serve
through SSH, so there'd be no browser to open and this'd fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you recommend catching an error here or something else? I was unable to find a way to detect from inside the function whether there is actually a browser available.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we just shouldn't be opening the user's browser. We already print a link to the terminal for where the user should go to view their trace, and many terminals just allow clicking into it directly.
remove open_url flag, add processor_path env var and remove arg for use_processor_shell_path flag, create Enable module for processor_path param Signed-off-by: Abena Laast <[email protected]>
Signed-off-by: Abena Laast <[email protected]>
Signed-off-by: Abena Laast <[email protected]>
src/env_vars.ml
Outdated
(* Points to a filesystem path with a trace processor executable. | ||
If provided, the flag can be indicated to automatically run the processor | ||
at the path once the trace file is created *) | ||
let processor_path = Unix.getenv "MAGIC_TRACE_PROCESSOR_SHELL_PATH" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let processor_path = Unix.getenv "MAGIC_TRACE_PROCESSOR_SHELL_PATH" | |
let processor_path = Unix.getenv "MAGIC_TRACE_TRACE_PROCESSOR_SHELL_PATH" |
src/env_vars.mli
Outdated
@@ -4,3 +4,4 @@ val debug : bool | |||
val perf_is_privileged : bool | |||
val perfetto_dir : string option | |||
val no_dlfilter : bool | |||
val processor_path : string option |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
val processor_path : string option | |
val trace_processor_shell_path : string option |
to be explicit
@@ -8,8 +8,10 @@ let supports_command command = | |||
Lazy.from_fun (fun () -> | |||
match Core_unix.fork () with | |||
| `In_the_child -> | |||
Core_unix.close Core_unix.stdout; | |||
Core_unix.close Core_unix.stderr; | |||
(* gracefully hide perf outputs *) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should leave a comment here about what versions of perf we observed breakages when close-ing and under what circumstances, because it was surprising.
src/trace.ml
Outdated
@@ -561,6 +563,41 @@ module Make_commands (Backend : Backend_intf.S) = struct | |||
{ Decode_opts.output_config; decode_opts; print_events } | |||
;; | |||
|
|||
module Enable = struct |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
module Enable = struct | |
module Enable = struct |
Nit: we should give this module a more descriptive name.
src/trace.ml
Outdated
|
||
type t = | ||
| Disabled | ||
| Enabled of enabled |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Enabled of enabled | |
| Enabled of { value : string } |
Let's inline this type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's also give value
a better name, like trace_processor_shell_path
.
(* Same as [Caml.exit] but does not run at_exit handlers *) | ||
external sys_exit : int -> 'a = "caml_sys_exit" | ||
|
||
let call_trace_processor ?env ~prog ~argv () = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's either generalize this with the perf
version, or leave a CR-someday
to do this later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am unsure which part of this function is perf-specific.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
None of it is, so ideally this'd be the same function as
magic-trace/src/perf_tool_backend.ml
Line 70 in d51d797
let perf_fork_exec ?env ~prog ~argv () = |
You don't need to do this in this PR, but it would be good to leave a note for the future.
magic-trace run -full-execution ./program\n") | ||
magic-trace run -full-execution ./program\n\ | ||
# Run a process that generates a large trace file, magic-trace run ./program \ | ||
-use-trace-processor-shell\n") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should leave this out of the documentation for now, or maybe make the -use-trace-processor-shell
part of it conditional on the environment variable being present. Definitely don't want to give help text for a flag that doesn't exist.
change processor_path to trace_processor_shell_path, add comment about closing stdout and stderr breaking things, better name for Enable module, inline Enabled, better name for value, CR-someday for generalizing call_trace_processor with the perf version, update processor flag doc to clarify conditional existence Signed-off-by: Abena Laast <[email protected]>
match Env_vars.trace_processor_shell_path with | ||
| None -> Command.Param.return Disabled | ||
| Some processor_shell_path -> | ||
let%map_open.Command processor = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let%map_open.Command processor = | |
let%map_open.Command use_trace_processor_shell = |
Nit: descriptive variable names.
let param = | ||
match Env_vars.trace_processor_shell_path with | ||
| None -> Command.Param.return Disabled | ||
| Some processor_shell_path -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Some processor_shell_path -> | |
| Some trace_processor_shell_path -> |
Nit: avoid having multiple variable names for the semantically-same thing. It's best to shadow the previously-declared name in such cases.
flag | ||
"use-trace-processor-shell" | ||
no_arg | ||
~doc:[%string "use the trace processor set in environment variables"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
~doc:[%string "use the trace processor set in environment variables"] | |
~doc:[%string "use trace processor shell to view trace"] |
There seem to be some conflicts with the base branch, could you please try rebasing to resolve them? |