`type t = Stdlib.Gc.Memprof.t`
`type allocation_source = Stdlib.Gc.Memprof.allocation_source =`

1. `| Normal`
2. `| Marshal`
3. `| Custom`
4. `| Map_file`

`val string_of_allocation_source : allocation_source -> string`
`type allocation = private Stdlib.Gc.Memprof.allocation = {`

1. `n_samples : int;`
   (*

   The number of samples in this block (>= 1).

   *)
2. `size : int;`
   (*

   The size of the block, in words, excluding the header.

   *)
3. `source : allocation_source;`
   (*

   The type of the allocation.

   *)
4. `callstack : Stdlib.Printexc.raw_backtrace;`
   (*

   The callstack for the allocation.

   *)

`}`

The type of metadata associated with allocations. This is the type of records passed to the callback triggered by the sampling of an allocation.

`type ('minor, 'major) tracker = ('minor, 'major) Stdlib.Gc.Memprof.tracker = {`

1. `alloc_minor : allocation -> 'minor option;`
2. `alloc_major : allocation -> 'major option;`
3. `promote : 'minor -> 'major option;`
4. `dealloc_minor : 'minor -> unit;`
5. `dealloc_major : 'major -> unit;`

`}`

A `('minor, 'major) tracker` describes how memprof should track sampled blocks over their lifetime, keeping a user-defined piece of metadata for each of them: `'minor` is the type of metadata to keep for minor blocks, and `'major` the type of metadata for major blocks.

If an allocation-tracking or promotion-tracking function returns `None`, memprof stops tracking the corresponding value.

`val null_tracker : ('minor, 'major) tracker`

Default callbacks simply return `None` or `()`

`val start : sampling_rate:float -> ?callstack_size:int -> ('minor, 'major) tracker -> t`

Start the sampling with the given parameters. Fails if sampling is already active.

The parameter `sampling_rate` is the sampling rate in samples per word (including headers). Usually, with cheap callbacks, a rate of 1e-4 has no visible effect on performance, and 1e-3 causes the program to run a few percent slower

The parameter `callstack_size` is the length of the callstack recorded at every sample. Its default is `max_int`.

The parameter `tracker` determines how to track sampled blocks over their lifetime in the minor and major heap.

Sampling is temporarily disabled when calling a callback for the current thread. So they do not need to be reentrant if the program is single-threaded. However, if threads are used, it is possible that a context switch occurs during a callback, in this case the callback functions must be reentrant.

Note that the callback can be postponed slightly after the actual event. The callstack passed to the callback is always accurate, but the program state may have evolved.

Calling `Thread.exit` in a callback is currently unsafe and can result in undefined behavior.

`val stop : unit -> unit`

Stop the sampling. Fails if sampling is not active.

This function does not allocate memory, but tries to run the postponed callbacks for already allocated memory blocks (of course, these callbacks may allocate).

All the already tracked blocks are discarded.

Calling `stop` when a callback is running can lead to callbacks not being called even though some events happened.

`val discard : t -> unit`

Stop the sampling. Fails if sampling is not active.

This function does not allocate memory, but tries to run the postponed callbacks for already allocated memory blocks (of course, these callbacks may allocate).

All the already tracked blocks are discarded.

Calling `stop` when a callback is running can lead to callbacks not being called even though some events happened.