Tezos_profiler.ProfilerThis profiling library declares a high-level interface meant to be used to instrument code in order to measure the time spent in the different parts in such a way to yield a (human-)processable report. This module declares a generic interface (driver) that will provide an API to the developer to instrument the code. When the profiling data is recorded, the abstracted profiler will feed it to its "plugged" backend (instance) which will process the different profiler's nodes in order to produce the reports. Reports may also be combined to interwine different components' traces.
The provided API is intentionally simplistic to simplify its usage. The basic usage is to call record <symbol> before the desired section to profile and stop () when we exit it. Nested calls are also supported and, given that the backend supports it, will be displayed as a callgraph. The API is also augmented with higher-level combinators in order to avoid mismatched stops and to support Lwt function calls.
Type used in order to (optionally) add information to a profiling call in the most generic way possible, allowing for different backends to need different data.
For instance, a prometheus-based profiler (which can't handle as many different metrics as the file-based ones) would rely on the "prometheus" key being present or not in metadata in order to determine if the function should be monitored or not.
type id = string * metadataName of a metric, with (possibly empty) metadata attached.
type ids = string list * metadataStack of names used for nested metrics (the head is the name of the metric, the second element is the name of the parent section, the third element the parent of the parent, etc...) with (possibly empty) metadata attached.
compute_cpu ~cpu returns true if CPU profiling should be enabled.
Computing CPU times is slow, if the overhead when profiling is too important, consider disabling cpu profiling globally or locally on functions that are called a lot.
This depends on the value of the CPU_PROFILING environment variable and cpu.
CPU_PROFILING value dictates what kind of value is returned:
true means cpu profiling will be enabled everywherefalse means cpu profiling will be disabled everywheredefault_true means cpu profiling will be enabled except for the profiling parts where cpu:false is explicitdefault_false means cpu profiling will be disabled except for the profiling parts where cpu:true is explicit.val zero_time : cpu:bool option -> spanThe level of detail of report sections. The driver can choose to use this information to skip or aggregate sections below a given level. The driver could also record everything, including the level of detail, and let a post processor skip or aggregate at display time.
type aggregated_node = {count : int;total : span;children : aggregated_node IdMap.t;node_verbosity : verbosity;}An aggregate node registers multiple calls to a section and sum their occurences and time. It also recursively aggregate its sub-aggregation nodes.
A sequence item registers one section with potential sub-reports and registers elapsed-time.
val report_encoding : report Data_encoding.tmodule type DRIVER = sig ... endInstance
A specific instance of a Driver implementation.
Example: this driver that writes text files in a unix filesystem will write them in this specific file with this specific level of details
instance driver params will instantiate the driver with the given params
val close : instance -> unitclose_and_unplug profiler instance closes profiler and unplugs it from instance
val close_and_unplug_all : profiler -> unitclose_and_unplug_all profiler closes profiler and unplugs it from all instances it was plugged to
plugged profiler returns all the instances plugged to profiler
Open a sequence in the current sequence. If currently aggregating (not all aggregation scopes are closed), this has the same semantics as aggregate instead.
Open an aggregation node in the current sequence.
val stop : profiler -> unitClose the most recently opened sequence or aggregation scope.
Record a timestamp in the most recently opened sequence.
Count this event's occurences in the most recent sequence.
Sum the time spent in this event in the most recent sequence.
record_f profiler verbosity label f will call:
record profiler verbosity name;
f ();
stop ();Same as record_f but for Lwt function
aggregate_f profiler verbosity label f will call:
aggregate profiler verbosity name;
f ();
stop ();Same as aggregate_f but for Lwt functions
span_f profiler verbosity label_list f will compute span but specifically around f
Same as span_f but for Lwt functions
val unplugged : unit -> profilerunplugged () returns a new profiler
val main : profilermodule type GLOBAL_PROFILER = sig ... endval wrap : profiler -> (module GLOBAL_PROFILER)wrap profiler stores profiler in a GLOBAL_PROFILER module allowing to use the profiler functions without having to provide it as a parameter
type 'a section_maker = ('a * metadata) -> unitval section_maker :
?verbosity:verbosity ->
?cpu:bool ->
('a -> 'a -> bool) ->
('a -> string) ->
profiler ->
'a section_makersection_maker equal to_string profiler Creates a function to open a new section (and close the one opened before) using record function when a new entity is encountered.