Module Nested_profile.Profile
This is a library for time profiling sequential or Async code.
Wrap interesting places in your code with calls to profile
:
open! Nested_profile;;
profile "do_thing" (fun () ->
profile "foo" foo;
profile "bar" bar;
...)
Then each top-level call to profile
will output a hierarchical display of all profile calls beneath it:
1.284s -- do_thing 209.266ms -- foo 1.074s -- bar
module Sync_or_async : sig ... end
A
Sync_or_async.t
specifies whether the computation being profiled is synchronous or asynchronous.
val profile : ?hide_if_less_than:Core_kernel.Time_ns.Span.t -> 'a Sync_or_async.t -> Core_kernel.Sexp.t Core_kernel.Lazy.t -> (unit -> 'a) -> 'a
profile sync_or_async message f
measures the time taken to runf
, and outputs the result. Nested calls to profile are displayed as a tree. UseAsync
to profile Async code. It is safe to nest calls toprofile
inside calls toprofile Async
.profile Async
does have some restrictions in order to get valid results:- a nested call to
profile Async
must exit before its parent does - there cannot be multiple sibling calls to
profile Async
running concurrently
- a nested call to
val am_forcing_message : unit -> bool
am_forcing_message ()
returns true when profiling is callingforce
on a message supplied toprofile
. This is useful if you want to have asexp_of_t
function behave differently when producing messages.
val approximate_line_length_limit : int Core_kernel.ref
val should_profile : bool Core_kernel.ref
val hide_if_less_than : Core_kernel.Time_ns.Span.t Core_kernel.ref
val hide_top_level_if_less_than : Core_kernel.Time_ns.Span.t Core_kernel.ref
val sexp_of_time_ns : (Core_kernel.Time_ns.t -> Core_kernel.Sexp.t) Core_kernel.ref
val tag_frames_with : (unit -> Core_kernel.Sexp.t option) option Core_kernel.ref
val output_profile : (string -> unit) Core_kernel.ref
profile
callsoutput_profile
to display the profile to the user. It isprint_string
by default.
module Start_location : sig ... end
val start_location : Start_location.t Core_kernel.ref
start_location
specifies where in a profile the start time is rendered.
val backtrace : unit -> Core_kernel.Sexp.t list option
Return the current stack of
profile
messages, sorted inner profile frames first. ReturnsNone
ifshould_profile
is false.
val disown : (unit -> 'a) -> 'a
disown f
runsf
as though it were at top level, rather than whatever the current context is. In other words, it causes the parent (current) context to disown children created byf
. This is useful for background jobs that might outlive their parents, since Nested_profile requires that parents wait for their children.
module Private : sig ... end