mirror of
https://github.com/ocaml-tracing/ocaml-trace.git
synced 2026-03-08 03:47:57 -04:00
perf: make with_ inlinable in case there is no collector
This commit is contained in:
parent
ab8e8bd9c2
commit
0707d932bc
1 changed files with 18 additions and 12 deletions
18
src/trace.ml
18
src/trace.ml
|
|
@ -22,19 +22,25 @@ let[@inline] exit_span span : unit =
|
||||||
| None -> ()
|
| None -> ()
|
||||||
| Some (module C) -> C.exit_span span
|
| Some (module C) -> C.exit_span span
|
||||||
|
|
||||||
let with_ ?__FUNCTION__ ~__FILE__ ~__LINE__ name f =
|
let with_collector_ (module C : Collector.S) ?__FUNCTION__ ~__FILE__ ~__LINE__
|
||||||
match A.get collector with
|
name f =
|
||||||
| None -> f Collector.dummy_span
|
|
||||||
| Some (module C) ->
|
|
||||||
let sp = C.create_span ?__FUNCTION__ ~__FILE__ ~__LINE__ name in
|
let sp = C.create_span ?__FUNCTION__ ~__FILE__ ~__LINE__ name in
|
||||||
(match f sp with
|
match f sp with
|
||||||
| x ->
|
| x ->
|
||||||
C.exit_span sp;
|
C.exit_span sp;
|
||||||
x
|
x
|
||||||
| exception exn ->
|
| exception exn ->
|
||||||
let bt = Printexc.get_raw_backtrace () in
|
let bt = Printexc.get_raw_backtrace () in
|
||||||
C.exit_span sp;
|
C.exit_span sp;
|
||||||
Printexc.raise_with_backtrace exn bt)
|
Printexc.raise_with_backtrace exn bt
|
||||||
|
|
||||||
|
let[@inline] with_ ?__FUNCTION__ ~__FILE__ ~__LINE__ name f =
|
||||||
|
match A.get collector with
|
||||||
|
| None ->
|
||||||
|
(* fast path: no collector, no span *)
|
||||||
|
f Collector.dummy_span
|
||||||
|
| Some collector ->
|
||||||
|
with_collector_ collector ?__FUNCTION__ ~__FILE__ ~__LINE__ name
|
||||||
|
|
||||||
let[@inline] message ?__FUNCTION__ ~__FILE__ ~__LINE__ msg : unit =
|
let[@inline] message ?__FUNCTION__ ~__FILE__ ~__LINE__ msg : unit =
|
||||||
match A.get collector with
|
match A.get collector with
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue