(** PROFILING *)
+(* we should use a key in te registry, but we can't see the registry.. *)
let profiling_enabled = true
+let profiling_printings = ref (fun () -> true)
+let set_profiling_printings f = profiling_printings := f
+
type profiler = { profile : 'a 'b. ('a -> 'b) -> 'a -> 'b }
let profile ?(enable = true) =
- if profiling_enabled && enable then
+ if profiling_enabled && enable then
function s ->
let total = ref 0.0 in
let profile f x =
in
at_exit
(fun () ->
- print_endline
- ("!! TOTAL TIME SPENT IN " ^ s ^ ": " ^ string_of_float !total));
+ if !profiling_printings () then
+ prerr_endline
+ ("!! TOTAL TIME SPENT IN " ^ s ^ ": " ^ string_of_float !total));
{ profile = profile }
else
function _ -> { profile = fun f x -> f x }
(** @return a profiling function; [s] is used for labelling the total time at
* the end of the execution *)
val profile : ?enable:bool -> string -> profiler
+val set_profiling_printings : (unit -> bool) -> unit