Module Utils.Profiler

Wall-clock profiler for the four algorithmic phases: TeacherMem, TeacherEq, LearnerEnc, LearnerSolve. on ctx f runs f under ctx, restoring the previous context on exit.

module Log : sig ... end
type t = {
  1. teacher_mem : Base.float;
  2. teacher_eq : Base.float;
  3. learner_enc : Base.float;
  4. learner_solve : Base.float;
  5. misc : Base.float;
  6. combined : Base.float;
}

Per-phase wall-clock times (seconds) for one learning run. combined is the sum of the four named phases; misc covers everything not attributed to a specific phase (e.g. WFA construction, statistics collection).

val pp : Ppx_deriving_runtime.Format.formatter -> t -> Ppx_deriving_runtime.unit
val show : t -> Ppx_deriving_runtime.string
val yojson_of_t : t -> Ppx_yojson_conv_lib.Yojson.Safe.t
val zero_stats : t
type context =
  1. | TeacherMem
  2. | TeacherEq
  3. | LearnerEnc
  4. | LearnerSolve
  5. | Misc

Identifies which phase of the algorithm is currently executing. Switching context via switch or on causes elapsed time since the last switch to be charged to the departing phase.

type state = {
  1. mutable ctx : context;
  2. mutable last_ts : Base.float;
  3. mutable stats : t;
}

Global mutable profiler state. A single-threaded design is intentional: the learner is sequential and nesting on calls correctly restores the previous context via Stdlib.Fun.protect.

val state : state
val add : t -> t -> t
val charge : now:Base__Float.t -> unit

Charge elapsed time now - last_ts to the current context.

val switch : context -> unit

switch ctx charges elapsed time to the current context, then transitions to ctx and records the new timestamp.

val lap : unit -> t

Snapshot current stats and reset counters to zero

val on : context -> (unit -> 'a) -> 'a

on ctx f runs f () while attributing elapsed time to ctx. Restores the previous context even if f raises, via Fun.protect.