eio
eio copied to clipboard
Ctf tracing: extend the `Fiber` API to allow labelling fibers
Similarly to how Promise.create
has an optional label
argument, we could have a similar feature for labelling tasks that are spawned using functions from the Fiber
module.
For fork
, the signature could be val fork : ?label:string -> sw:Switch.t -> (unit -> unit) -> unit
.
For combinators we can choose between:
-
val any : ?label:string -> (unit -> 'a) list -> 'a
: label all tasks with the same name -
val any_labelled : (string * (unit -> 'a)) list -> 'a
: new function to label each task separately
I have a small implementation for this be cause it's very useful to have this when tracing complex Eio programs.
Is this different to calling Ctf.label
in the new thread? Originally, Ctf
was supposed to be a user-facing API, but it's hidden inside Eio.Private
for now because the API is likely to change.
For a label on any
, it would be useful instead to label the cancellation context tree (shown with e.g. Cancel.dump
).
Looking at the implementation it's indeed equivalent, thanks for the pointer.
But yes labelling the cancellation context remains useful.