more docs

This commit is contained in:
Simon Cruanes 2024-09-10 10:43:44 -04:00
parent d8059e9aa0
commit cc6c311b45
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
2 changed files with 19 additions and 4 deletions

View file

@ -1,8 +1,10 @@
open Trace_core open Trace_core
open Types open Types
(** First class module signature for callbacks *)
module type S = sig module type S = sig
type st type st
(** Type of the state passed to every callback. *)
val on_init : st -> time_ns:float -> unit val on_init : st -> time_ns:float -> unit
(** Called when the subscriber is initialized in a collector *) (** Called when the subscriber is initialized in a collector *)
@ -85,10 +87,14 @@ module type S = sig
end end
type 'st t = (module S with type st = 'st) type 'st t = (module S with type st = 'st)
(** Callbacks for a subscriber. There is one callback per event
in {!Trace}. The type ['st] is the state that is passed to
every single callback. *)
(** Callbacks for a subscriber *) (** Dummy callbacks.
It can be useful to reuse some of these functions in a
(** Dummy callbacks *) real subscriber that doesn't want to handle {b all}
events, but only some of them. *)
module Dummy = struct module Dummy = struct
let on_init _ ~time_ns:_ = () let on_init _ ~time_ns:_ = ()
let on_shutdown _ ~time_ns:_ = () let on_shutdown _ ~time_ns:_ = ()
@ -113,6 +119,7 @@ module Dummy = struct
() ()
end end
(** Dummy callbacks, do nothing. *)
let dummy (type st) () : st t = let dummy (type st) () : st t =
let module M = struct let module M = struct
type nonrec st = st type nonrec st = st

View file

@ -1,4 +1,9 @@
(** A trace subscriber *) (** A trace subscriber. It pairs a set of callbacks
with the state they need (which can contain a file handle,
a socket, config, etc.).
The design goal for this is that it should be possible to avoid allocations
when the trace collector calls the callbacks. *)
type t = type t =
| Sub : { | Sub : {
st: 'st; st: 'st;
@ -6,6 +11,7 @@ type t =
} }
-> t -> t
(** Dummy subscriber that ignores every call. *)
let dummy : t = Sub { st = (); callbacks = Callbacks.dummy () } let dummy : t = Sub { st = (); callbacks = Callbacks.dummy () }
open struct open struct
@ -91,6 +97,8 @@ open struct
end end
end end
(** [tee s1 s2] is a subscriber that forwards every
call to [s1] and [s2] both. *)
let tee (s1 : t) (s2 : t) : t = let tee (s1 : t) (s2 : t) : t =
let st = s1, s2 in let st = s1, s2 in
Sub { st; callbacks = (module Tee_cb) } Sub { st; callbacks = (module Tee_cb) }