diff --git a/src/tef/dune b/src/tef/dune index acacd95..89b8e9a 100644 --- a/src/tef/dune +++ b/src/tef/dune @@ -3,7 +3,4 @@ (name trace_tef) (public_name trace-tef) (synopsis "Simple and lightweight tracing using TEF/Catapult format, in-process") - (libraries trace.core mtime mtime.clock.os atomic unix threads - (select relax_.ml from - (base-domain -> relax_.real.ml) - ( -> relax_.dummy.ml)))) + (libraries trace.core trace.private.util mtime mtime.clock.os atomic unix threads)) diff --git a/src/tef/trace_tef.ml b/src/tef/trace_tef.ml index aed6653..bd36ecb 100644 --- a/src/tef/trace_tef.ml +++ b/src/tef/trace_tef.ml @@ -1,4 +1,5 @@ open Trace_core +open Trace_private_util module A = Trace_core.Internal_.Atomic_ module Mock_ = struct @@ -14,7 +15,7 @@ end let counter = Mtime_clock.counter () (** Now, in microseconds *) -let now_us () : float = +let[@inline] now_us () : float = if !Mock_.enabled then Mock_.now_us () else ( @@ -22,16 +23,6 @@ let now_us () : float = Mtime.Span.to_float_ns t /. 1e3 ) -let protect ~finally f = - try - let x = f () in - finally (); - x - with exn -> - let bt = Printexc.get_raw_backtrace () in - finally (); - Printexc.raise_with_backtrace exn bt - let on_tracing_error = ref (fun s -> Printf.eprintf "trace-tef error: %s\n%!" s) type event = @@ -144,7 +135,7 @@ module Writer = struct let with_ ~out f = let writer = create ~out () in - protect ~finally:(fun () -> close writer) (fun () -> f writer) + Fun.protect ~finally:(fun () -> close writer) (fun () -> f writer) let[@inline] flush (self : t) : unit = flush self.oc @@ -499,7 +490,7 @@ let setup ?(out = `Env) () = let with_setup ?out () f = setup ?out (); - protect ~finally:Trace_core.shutdown f + Fun.protect ~finally:Trace_core.shutdown f module Internal_ = struct let mock_all_ () = Mock_.enabled := true diff --git a/src/tef/b_queue.ml b/src/util/b_queue.ml similarity index 100% rename from src/tef/b_queue.ml rename to src/util/b_queue.ml diff --git a/src/tef/b_queue.mli b/src/util/b_queue.mli similarity index 100% rename from src/tef/b_queue.mli rename to src/util/b_queue.mli diff --git a/src/tef/relax_.dummy.ml b/src/util/cpu_relax.dummy.ml similarity index 100% rename from src/tef/relax_.dummy.ml rename to src/util/cpu_relax.dummy.ml diff --git a/src/util/cpu_relax.mli b/src/util/cpu_relax.mli new file mode 100644 index 0000000..17542a8 --- /dev/null +++ b/src/util/cpu_relax.mli @@ -0,0 +1 @@ +val cpu_relax : unit -> unit diff --git a/src/tef/relax_.real.ml b/src/util/cpu_relax.real.ml similarity index 100% rename from src/tef/relax_.real.ml rename to src/util/cpu_relax.real.ml diff --git a/src/util/dune b/src/util/dune new file mode 100644 index 0000000..fc5fb6f --- /dev/null +++ b/src/util/dune @@ -0,0 +1,9 @@ + +(library + (public_name trace.private.util) + (synopsis "internal utilities for trace. No guarantees of stability.") + (name trace_private_util) + (libraries trace.core mtime mtime.clock.os atomic unix threads + (select cpu_relax.ml from + (base-domain -> cpu_relax.real.ml) + ( -> cpu_relax.dummy.ml)))) diff --git a/src/tef/mpsc_bag.ml b/src/util/mpsc_bag.ml similarity index 95% rename from src/tef/mpsc_bag.ml rename to src/util/mpsc_bag.ml index 004e8f5..453357f 100644 --- a/src/tef/mpsc_bag.ml +++ b/src/util/mpsc_bag.ml @@ -11,7 +11,7 @@ module Backoff = struct let once (b : t) : t = for _i = 1 to b do - Relax_.cpu_relax () + Cpu_relax.cpu_relax () done; min (b * 2) 256 end diff --git a/src/tef/mpsc_bag.mli b/src/util/mpsc_bag.mli similarity index 100% rename from src/tef/mpsc_bag.mli rename to src/util/mpsc_bag.mli