feat(trace): add Source, to read traces

This commit is contained in:
Simon Cruanes 2022-09-25 21:28:10 -04:00
parent ca3262eac3
commit f2471fd78c
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
3 changed files with 38 additions and 0 deletions

View file

@ -23,6 +23,7 @@ open Sidekick_sigs
module Entry_view = Entry_view module Entry_view = Entry_view
module Entry_read = Entry_read module Entry_read = Entry_read
module Sink = Sink module Sink = Sink
module Source = Source
module Entry_id = Entry_id module Entry_id = Entry_id
type entry_id = Entry_id.t type entry_id = Entry_id.t

15
src/trace/source.ml Normal file
View file

@ -0,0 +1,15 @@
type tag = string
module type S = sig
val get_entry : Entry_id.t -> tag * Ser_value.t
val iter_all : (Entry_id.t -> tag:tag -> Ser_value.t -> unit) -> unit
end
type t = (module S)
let get_entry_exn (module S : S) id = S.get_entry id
let get_entry (module S : S) id : _ option =
try Some (S.get_entry id) with Not_found -> None
let iter_all (module S : S) f : unit = S.iter_all f

22
src/trace/source.mli Normal file
View file

@ -0,0 +1,22 @@
(** Source to read a trace.
A source is an IO input source that allows the read of individual
entries of the trace, by providing their entry ID. It also allows to
iterate on entries in chronological order.
*)
type tag = string
module type S = sig
val get_entry : Entry_id.t -> tag * Ser_value.t
(** @raise Not_found if there is no such entry *)
val iter_all : (Entry_id.t -> tag:tag -> Ser_value.t -> unit) -> unit
(** Iterate on all entries *)
end
type t = (module S)
val get_entry : t -> Entry_id.t -> (tag * Ser_value.t) option
val get_entry_exn : t -> Entry_id.t -> tag * Ser_value.t
val iter_all : t -> (Entry_id.t -> tag:tag -> Ser_value.t -> unit) -> unit