Module Profiler_intf.Delta_probe
Delta_probe
is an optimized two-probe group to track changes to some counter.
val create : name:string -> units:Profiler_units.t -> t
val start : t -> int -> unit
To measure changes in a value, one can call
start
followed by a callstop
after some time. The call tostop
will record the delta. Calls tostart
/stop
must be interleaved for eacht
.Calling
pause
in place ofstop
causest
to accumulate, but not record, the delta.start
andpause
can then be interleaved multiple times. Afterwards, callingrecord
will record the sum of the deltas between eachstart
/pause
, and resett
.Valid sequences should satisfy this regular expression:
start;(pause;start;)*((pause;record;)|stop;)
Calling these functions out of order will cause bad data to be recorded. This API does not raise exceptions, so one will not be warned of errors.
For each
t
, there are two valid sequences of calls. The first is callingstart
thenstop
. The second is callingstart
thenpause
an arbitrary number of times, and ending withrecord
.
val stop : t -> int -> unit
val pause : t -> int -> unit
val record : t -> unit
val stateless_start : t -> int -> state
These are non-stateful and can be used in Async, wherein multiple jobs might call
stateless_start
before the correspondingstop_async
is called. One can usestateless_start
andstateless_stop
to wrap async functions roughly like the following. This function cannot be provided as part of theCore_profiler
library because we'd like the library to be usable inAsync
and hence now depend on it.let wrap_async t f x = let state = stateless_start t (Gc.minor_words ()) in try_with ~run:`Now (fun () -> f x) >>= fun res -> stateless_stop t state (Gc.minor_words ()); match res with | Ok x -> return x | Error ex -> Exn.reraise ex "Core_profiler wrap_async"
The stateless API does not support pausing. This is because state would require memory allocation if it supported accumulating the counter.