Skip to content
Merged
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
41 changes: 32 additions & 9 deletions bin/trace.ml
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,17 @@ let cat =
value
& flag
& info [ "follow"; "f" ] ~doc:(Some "follow the trace file until the exit event"))
and+ action_events =
Arg.(
value
& vflag
`All
[ ( `Exclude
, info [ "no-actions" ] ~doc:(Some "exclude events emitted by actions") )
; ( `Only
, info [ "only-actions" ] ~doc:(Some "print only events emitted by actions")
)
])
in
Common.No_build.set_debug_backtraces debug_backtraces;
let mode =
Expand All @@ -246,38 +257,50 @@ let cat =
| true, false -> `Chrome
| false, false -> `Json
in
let first_chrome_event = ref true in
let print =
match mode with
| `Sexp -> fun sexp -> print_endline (Sexp.to_string sexp)
| `Json ->
fun sexp -> print_endline (Json.to_string (json_of_event ~chrome:false sexp))
| `Chrome ->
let first = ref true in
fun sexp ->
let char =
if !first
if !first_chrome_event
then (
let () = first := false in
let () = first_chrome_event := false in
'[')
else ','
in
print_char char;
print_endline (Json.to_string (json_of_event ~chrome:true sexp))
in
let print_with_flush sexp =
print sexp;
if follow then flush stdout
let print_if_selected sexp =
let selected =
match action_events with
| `All -> true
| (`Exclude | `Only) as action_events ->
let _, _, _, _, digest = base_of_sexp sexp in
let is_action = Option.is_some digest in
(match action_events with
| `Exclude -> not is_action
| `Only -> is_action)
in
if selected
then (
print sexp;
if follow then flush stdout)
in
let trace_file =
match trace_file with
| Some s -> s
| None -> Common.find_default_trace_file ()
in
if follow
then iter_sexps_follow trace_file ~f:print_with_flush
else iter_sexps trace_file ~f:print;
then iter_sexps_follow trace_file ~f:print_if_selected
else iter_sexps trace_file ~f:print_if_selected;
match mode with
| `Chrome -> print_endline "]"
| `Chrome -> print_endline (if !first_chrome_event then "[]" else "]")
| `Json | `Sexp -> ()
in
Cmd.v info term
Expand Down
2 changes: 2 additions & 0 deletions doc/changes/added/16245.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Add `--no-actions` and `--only-actions` to `dune trace cat` to filter
events collected from actions. (#16245, @rgrinberg)
73 changes: 73 additions & 0 deletions test/blackbox-tests/test-cases/trace/action-traces/basic.t
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,76 @@ Dune's actions may produce trace events
"digest": "REDACTED"
}
}

Action events may be selected explicitly.

$ dune trace cat --only-actions | jq_dune -s 'redactedActionTraces'
{
"cat": "bar",
"name": "foo",
"ts": 0,
"args": {
"arg": "baz",
"digest": "REDACTED"
}
}

Chrome output applies the same selection.

$ dune trace cat --only-actions --chrome-trace | jq '
> .[] | .ts = 0 | .pid = 0 | .args.digest = "REDACTED"
> '
{
"cat": "bar",
"name": "foo",
"ts": 0,
"args": {
"arg": "baz",
"digest": "REDACTED"
},
"ph": "i",
"pid": 0
}

Excluding action events retains Dune's own trace events.

$ dune trace cat --no-actions | jq -s '
> first
> | .ts = 0
> | .args.argv = ["REDACTED"]
> | .args.env = ["REDACTED"]
> | .args.root = "REDACTED"
> | .args.pid = 0
> | .args.initial_cwd = "REDACTED"
> | .args.start = 0
> '
{
"cat": "config",
"name": "init",
"ts": 0,
"args": {
"build_dir": "_build",
"argv": [
"REDACTED"
],
"env": [
"REDACTED"
],
"root": "REDACTED",
"pid": 0,
"initial_cwd": "REDACTED",
"start": 0
}
}

There are no action events in the filtered output.

$ dune trace cat --no-actions | jq_dune -s 'redactedActionTraces'

The selection flags are mutually exclusive.

$ dune trace cat --no-actions --only-actions
Usage: dune trace cat [--help] [OPTION]…
dune: options '--no-actions' and '--only-actions' cannot be present at the
same time
[1]
Loading