Module Stats.As_ctx

Module for manipulating statistics as a context using algebraic effects (that are hidden). All calls to any function in this module should happen only inside a function wrapped with with_stats, ensuring that the statistics are properly passed around.

val with_stats : unit -> (unit -> 'a) -> 'a with_stats

with_stats () f runs function f and handles effects raised by the functions of this module such as push_entry, and returns a record containing the result of executing f together with the obtained statistics.

val with_stats_ignored : unit -> (unit -> 'a) -> 'a

with_stats_ignored () f runs function f and handles effects raised by the functions of this module, but ignores their effect. This is to be used when the user does not wish to pay the (minor) performance cost of stats bookkeeping.

val with_stats_dumped : unit -> (unit -> 'a) -> 'a

with_stats_dumped () f runs function f and handles effects raised by the functions of this module such as push_entry, and dumps the stats to the file specified by the current Config.output_stats if it is set, or ignores them otherwise.

val push_entry : string -> stat_entry -> unit

push_entry name entry adds the given statistic entry under the given name name to the current statistics context.

val add_int : string -> int -> unit

push_int name n is push_entry name (Int n).

val incr : string -> unit

incr name is add_int name 1.

val add_float : string -> float -> unit

push_float name f is push_entry name (Float f).

val add_time_of_to : string -> (unit -> 'a) -> 'a

add_time_of_to name f measures the execution time of function f in seconds, and adds it as a float statistic under the given name name. It returns the result of executing f.

val push_str : string -> string -> unit

push_str name s adds the given string s as a single entry in a string sequence statistic under the given name name.

val push_binding : string -> string -> stat_entry -> unit

push_binding name key entry adds the given statistic entry under the given key key in a map statistic under the given name name.

val push_string_binding : string -> string -> string -> unit

push_string_binding name key s adds the given string s as a single entry in a string sequence statistic under the given key key in a map statistic under the given name name.

val get_copy : unit -> t

get_copy () retrieves a copy of the statistics aggregated in the current environment