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
1 change: 1 addition & 0 deletions bin/common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1312,6 +1312,7 @@ let init_with_root ~(root : Workspace_root.t) (builder : Builder.t) =
; File_watcher
; Diagnostics
; Cram
; Action
]
| Some s ->
String.split ~on:',' s
Expand Down
1 change: 1 addition & 0 deletions doc/changes/added/13265.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Add trace events for custom actions (#13265, @rgrinberg)
3 changes: 3 additions & 0 deletions src/action_ext/action_ext.ml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ struct

let action a ~ectx ~eenv =
let open Fiber.O in
let start = Time.now () in
Dune_trace.emit Action (fun () -> Dune_trace.Event.Action.start ~name ~start);
let+ () = action a ~ectx ~eenv in
Dune_trace.emit Action (fun () -> Dune_trace.Event.Action.finish ~name ~start);
Done_or_more_deps.Done
;;
end
Expand Down
2 changes: 1 addition & 1 deletion src/action_ext/dune
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
(library
(name action_ext)
(libraries dune_engine fiber stdune))
(libraries dune_engine dune_trace fiber stdune))
4 changes: 4 additions & 0 deletions src/dune_trace/category.ml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type t =
| Diagnostics
| Log
| Cram
| Action

let all =
[ Rpc
Expand All @@ -37,6 +38,7 @@ let all =
; Diagnostics
; Log
; Cram
; Action
]
;;

Expand All @@ -58,6 +60,7 @@ let to_string = function
| Diagnostics -> "diagnostics"
| Log -> "log"
| Cram -> "cram"
| Action -> "action"
;;

let of_string =
Expand Down Expand Up @@ -91,5 +94,6 @@ module Set = Bit_set.Make (struct
| Diagnostics -> 14
| Log -> 15
| Cram -> 16
| Action -> 17
;;
end)
1 change: 1 addition & 0 deletions src/dune_trace/category.mli
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type t =
| Diagnostics
| Log
| Cram
| Action

val to_string : t -> string
val of_string : string -> t option
Expand Down
6 changes: 6 additions & 0 deletions src/dune_trace/dune_trace.mli
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module Category : sig
| Diagnostics
| Log
| Cram
| Action

val of_string : string -> t option
end
Expand Down Expand Up @@ -165,6 +166,11 @@ module Event : sig

val test : test:Path.t -> command list -> t
end

module Action : sig
val start : name:string -> start:Time.t -> t
val finish : name:string -> start:Time.t -> t
end
end

module Out : sig
Expand Down
11 changes: 11 additions & 0 deletions src/dune_trace/event.ml
Original file line number Diff line number Diff line change
Expand Up @@ -569,3 +569,14 @@ module Cram = struct
Event.instant ~args ~name:"cram" now Cram
;;
end

module Action = struct
let start ~name ~start =
Event.instant ~args:[ "name", Arg.string name ] ~name:"start" start Action
;;

let finish ~name ~start =
let dur = Time.diff (Time.now ()) start in
Event.complete ~args:[ "name", Arg.string name ] ~name:"finish" ~start ~dur Action
;;
end
Loading