Skip to content

Commit 2050cc8

Browse files
authored
Add a promotion trace event (#12949)
Use this event rather than adhoc parsing of --verbose output Signed-off-by: Rudi Grinberg <me@rgrinberg.com>
1 parent 018934a commit 2050cc8

File tree

11 files changed

+71
-18
lines changed

11 files changed

+71
-18
lines changed

bin/common.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1271,7 +1271,8 @@ let build (root : Workspace_root.t) (builder : Builder.t) =
12711271
Option.map builder.stats_trace_file ~f:(fun f ->
12721272
let cats =
12731273
match Sys.getenv_opt "DUNE_TRACE" with
1274-
| None -> Dune_trace.Category.[ Sandbox; Persistent; Process; Rules; Pkg ]
1274+
| None ->
1275+
Dune_trace.Category.[ Sandbox; Persistent; Process; Rules; Pkg; Promote ]
12751276
| Some s ->
12761277
String.split ~on:',' s
12771278
|> List.map ~f:(fun x ->

doc/changes/changed/12949.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Introduce a promotion trace event and remove the corresponding verbose log
2+
message. (#12949, @rgrinberg)

flake.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@
176176
mercurial
177177
unzip
178178
perl
179+
jq
179180
]
180181
++ lib.optionals stdenv.isLinux [ strace ];
181182
testNativeBuildInputs =

src/dune_engine/target_promotion.ml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,7 @@ let promote_target_if_not_up_to_date
7474
this, perhaps, by making artifact substitution a field of [promote]. *)
7575
Fiber.return false
7676
| _ ->
77-
Log.info
78-
[ Pp.textf
79-
"Promoting %S to %S"
80-
(Path.Build.to_string src)
81-
(Path.Source.to_string dst)
82-
];
77+
Dune_trace.emit Promote (fun () -> Dune_trace.Event.promote src dst);
8378
if promote_until_clean then To_delete.add dst;
8479
(* The file in the build directory might be read-only if it comes from the
8580
shared cache. However, we want the file in the source tree to be

src/dune_trace/category.ml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ type t =
1010
| Rules
1111
| Pkg
1212
| Scheduler
13+
| Promote
1314

14-
let all = [ Rpc; Gc; Fd; Sandbox; Persistent; Process; Rules; Pkg; Scheduler ]
15+
let all = [ Rpc; Gc; Fd; Sandbox; Persistent; Process; Rules; Pkg; Scheduler; Promote ]
1516

1617
let to_string = function
1718
| Rpc -> "rpc"
@@ -23,6 +24,7 @@ let to_string = function
2324
| Rules -> "rules"
2425
| Pkg -> "pkg"
2526
| Scheduler -> "scheduler"
27+
| Promote -> "promote"
2628
;;
2729

2830
let of_string =
@@ -48,5 +50,6 @@ module Set = Bit_set.Make (struct
4850
| Rules -> 6
4951
| Pkg -> 7
5052
| Scheduler -> 8
53+
| Promote -> 9
5154
;;
5255
end)

src/dune_trace/category.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ type t =
88
| Rules
99
| Pkg
1010
| Scheduler
11+
| Promote
1112

1213
val to_string : t -> string
1314
val of_string : string -> t option

src/dune_trace/dune_trace.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module Category : sig
1111
| Rules
1212
| Pkg
1313
| Scheduler
14+
| Promote
1415

1516
val of_string : string -> t option
1617
end
@@ -70,6 +71,7 @@ module Event : sig
7071
val config : version:string option -> t
7172
val gc : unit -> t
7273
val fd_count : unit -> t option
74+
val promote : Path.Build.t -> Path.Source.t -> t
7375

7476
module Rpc : sig
7577
type stage =

src/dune_trace/event.ml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,3 +340,17 @@ let fd_count () =
340340
let common = Event.common_fields ~cat:[ Category.to_string Fd ] ~name:"fds" ~ts () in
341341
Some (Event.counter common args)
342342
;;
343+
344+
let promote src dst =
345+
let module Event = Chrome_trace.Event in
346+
let common =
347+
let ts = Event.Timestamp.of_float_seconds (Time.now () |> Time.to_secs) in
348+
Event.common_fields ~cat:[ Category.to_string Promote ] ~name:"promote" ~ts ()
349+
in
350+
let args =
351+
[ "src", `String (Path.Build.to_string src)
352+
; "dst", `String (Path.Source.to_string dst)
353+
]
354+
in
355+
Event.instant ~args common
356+
;;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
(cram
2+
(applies_to promote-variables promote-only-when-needed)
3+
(deps %{bin:jq}))

test/blackbox-tests/test-cases/promote/promote-only-when-needed.t

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,16 @@ Test that targets aren't re-promoted if they are up to date.
88
> (action (with-stdout-to promoted (echo "Hello, world!"))))
99
> EOF
1010

11-
$ dune build promoted --verbose 2>&1 | grep "Promoting"
12-
Promoting "_build/default/promoted" to "promoted"
11+
$ showPromotions() {
12+
> jq '.[] | select(.name == "promote") | .args' trace.json
13+
> }
14+
15+
$ dune build promoted --trace-file trace.json
16+
$ showPromotions
17+
{
18+
"src": "_build/default/promoted",
19+
"dst": "promoted"
20+
}
1321
$ cat promoted
1422
Hello, world!
1523

@@ -23,8 +31,12 @@ Dune doesn't promote the file again if it's unchanged.
2331
Dune does promotes the file again if it's changed.
2432

2533
$ echo hi > promoted
26-
$ dune build promoted --verbose 2>&1 | grep "Promoting"
27-
Promoting "_build/default/promoted" to "promoted"
34+
$ dune build promoted --trace-file trace.json
35+
$ showPromotions
36+
{
37+
"src": "_build/default/promoted",
38+
"dst": "promoted"
39+
}
2840
$ cat promoted
2941
Hello, world!
3042

@@ -46,8 +58,14 @@ Now test behaviour for executables, which use artifact substitution.
4658
> | None -> print_endline "Has no version info")
4759
> EOF
4860

49-
$ dune build hello.exe --verbose 2>&1 | grep "Promoting"
50-
Promoting "_build/default/hello.exe" to "hello.exe"
61+
$ dune build hello.exe --trace-file trace.json
62+
63+
$ showPromotions
64+
{
65+
"src": "_build/default/hello.exe",
66+
"dst": "hello.exe"
67+
}
68+
5169
$ ./hello.exe
5270
Hello, World!
5371
Has version info
@@ -56,5 +74,12 @@ Bug: Dune currently re-promotes versioned executables on every restart.
5674

5775
# CR-someday amokhov: Fix this.
5876

59-
$ dune build hello.exe --verbose 2>&1 | grep "Promoting"
60-
Promoting "_build/default/hello.exe" to "hello.exe"
77+
$ dune build hello.exe --trace-file trace.json
78+
79+
$ showPromotions
80+
{
81+
"src": "_build/default/hello.exe",
82+
"dst": "hello.exe"
83+
}
84+
85+
$ jq '.[] | select(.name == "promote") | .args'

0 commit comments

Comments
 (0)