diff --git a/src/fuchsia/fcollector.ml b/src/fuchsia/fcollector.ml index c2fc367..35c7925 100644 --- a/src/fuchsia/fcollector.ml +++ b/src/fuchsia/fcollector.ml @@ -5,6 +5,19 @@ module Int_map = Map.Make (Int) let pid = Unix.getpid () +module Mock_ = struct + let enabled = ref false + let now = ref 0 + + (* used to mock timing *) + let get_now_ns () : float = + let x = !now in + incr now; + float_of_int x *. 1000. + + let get_tid_ () : int = 3 +end + (** Thread-local stack of span info *) module Span_info_stack : sig type t @@ -408,3 +421,10 @@ let create ~out () : collector = () in (module Coll) + +module Internal_ = struct + let mock_all_ () = + Mock_.enabled := true; + Sub.Private_.get_now_ns_ := Some Mock_.get_now_ns; + Sub.Private_.get_tid_ := Some Mock_.get_tid_ +end diff --git a/src/fuchsia/fcollector.mli b/src/fuchsia/fcollector.mli index 780b3f1..2ba03e9 100644 --- a/src/fuchsia/fcollector.mli +++ b/src/fuchsia/fcollector.mli @@ -1,3 +1,11 @@ open Trace_core val create : out:Bg_thread.out -> unit -> collector + +(**/**) + +module Internal_ : sig + val mock_all_ : unit -> unit +end + +(**/**) diff --git a/src/fuchsia/trace_fuchsia.ml b/src/fuchsia/trace_fuchsia.ml index 102a744..f6b2b14 100644 --- a/src/fuchsia/trace_fuchsia.ml +++ b/src/fuchsia/trace_fuchsia.ml @@ -34,5 +34,6 @@ let with_setup ?out () f = Fun.protect ~finally:Trace_core.shutdown f module Internal_ = struct + let mock_all_ = Fcollector.Internal_.mock_all_ let on_tracing_error = on_tracing_error end diff --git a/src/fuchsia/trace_fuchsia.mli b/src/fuchsia/trace_fuchsia.mli index eaf1847..d28111a 100644 --- a/src/fuchsia/trace_fuchsia.mli +++ b/src/fuchsia/trace_fuchsia.mli @@ -45,6 +45,9 @@ val with_setup : ?out:[ output | `Env ] -> unit -> (unit -> 'a) -> 'a module Internal_ : sig val on_tracing_error : (string -> unit) ref + + val mock_all_ : unit -> unit + (** use fake, deterministic timestamps, TID, PID *) end (**/**)