v3: Sample allocations using the built-in pprof-compatible profiler or custom profiling hooks. More...
Typedefs | |
| typedef struct mi_profiler_s | mi_profiler_t |
| Profiler type. Custom profiler fields and callback types are defined in <mimalloc-profile.h>. | |
Functions | |
| mi_profiler_t * | mi_pprof_profiler_new (size_t initial_threshold, const char *base_file_name, size_t alloc_interval_size, size_t inuse_interval_size, size_t time_interval_secs) |
| experimental: Create the built-in pprof-compatible profiler. | |
| void | mi_pprof_profiler_delete (mi_profiler_t *profiler) |
| experimental: Delete a built-in profiler created by mi_pprof_profiler_new(). | |
| bool | mi_profile (mi_profiler_t *profiler) |
| experimental: Attach a profiler to the current and future heaps of the main subprocess. | |
| bool | mi_subproc_profile (mi_subproc_id_t subproc_id, mi_profiler_t *profiler) |
| experimental: Attach a profiler to the current and future heaps of a particular subprocess. | |
| bool | mi_heap_profile (mi_heap_t *heap, mi_profiler_t *profiler) |
| experimental: Attach a profiler to a particular heap, or pass NULL as the profiler to detach. | |
| void | mi_heap_profile_disable (mi_heap_t *heap) |
| experimental: Exclude a heap from profiling, even when a profiler is subsequently attached to its subprocess. | |
| bool | mi_profiler_start (mi_profiler_t *profiler) |
| experimental: Start sampling with an attached profiler. | |
| bool | mi_profiler_stop (mi_profiler_t *profiler) |
| experimental: Stop sampling. | |
| void | mi_profiler_snapshot (mi_profiler_t *profiler) |
| experimental: Take a snapshot of the current profile. | |
v3: Sample allocations using the built-in pprof-compatible profiler or custom profiling hooks.
Include <mimalloc-profile.h> and build with profiling support (-DMI_PROFILE=ON). The profiling API is experimental and may still change.
Programmatic profiling
Explicit profiler APIs remain available in secure builds and when environment-based activation is disabled. Create a profiler, attach it, and then start sampling:
Stopping sampling does not detach the profiler: its on_free callback can still be invoked for sampled allocations. Before deleting a profiler, detach it from all associated heaps and subprocesses, and ensure no other thread can still invoke its callbacks.
Environment-based profiling
When both MI_SECURE=0 and MI_SECURE_ENV=0, MIMALLOC_PROFILE=<basename> activates the built-in profiler for the main subprocess. Elevated processes ignore this environment variable regardless of build settings.
Snapshots use protobuf format by default. A basename ending in .Heaps or .text selects the text heap-profile format instead.
| typedef struct mi_profiler_s mi_profiler_t |
Profiler type. Custom profiler fields and callback types are defined in <mimalloc-profile.h>.
| bool mi_heap_profile | ( | mi_heap_t * | heap, |
| mi_profiler_t * | profiler ) |
experimental: Attach a profiler to a particular heap, or pass NULL as the profiler to detach.
Attaching stops sampling. The on_free callback is only invoked for allocations sampled by this profiler since it was last attached.
| void mi_heap_profile_disable | ( | mi_heap_t * | heap | ) |
experimental: Exclude a heap from profiling, even when a profiler is subsequently attached to its subprocess.
Useful for a heap used by a custom profiler to allocate its own metadata.
| void mi_pprof_profiler_delete | ( | mi_profiler_t * | profiler | ) |
experimental: Delete a built-in profiler created by mi_pprof_profiler_new().
First detach the profiler and ensure no other thread can still invoke its callbacks. Deleting a profiler does not take a final snapshot; use mi_profiler_snapshot() explicitly.
| mi_profiler_t * mi_pprof_profiler_new | ( | size_t | initial_threshold, |
| const char * | base_file_name, | ||
| size_t | alloc_interval_size, | ||
| size_t | inuse_interval_size, | ||
| size_t | time_interval_secs ) |
experimental: Create the built-in pprof-compatible profiler.
| initial_threshold | Approximate number of allocated bytes between samples (for example, 512 * 1024). |
| base_file_name | Output basename. A .Heaps or .text extension selects text format; any other extension, or none, selects protobuf format. A filename extension is stripped. |
| alloc_interval_size | Allocated bytes between automatic snapshots, or 0 to disable. |
| inuse_interval_size | Growth in in-use bytes between automatic snapshots, or 0 to disable. |
| time_interval_secs | Seconds between automatic snapshots, or 0 to disable. Time intervals are checked on allocation events, not by a background timer. |
| bool mi_profile | ( | mi_profiler_t * | profiler | ) |
experimental: Attach a profiler to the current and future heaps of the main subprocess.
Heaps excluded by mi_heap_profile_disable() remain excluded. Pass NULL to detach. Attaching stops sampling; use mi_profiler_start() to start it.
| void mi_profiler_snapshot | ( | mi_profiler_t * | profiler | ) |
experimental: Take a snapshot of the current profile.
May be called while sampling is stopped. Concurrent calls may skip a snapshot if another snapshot callback is already running.
| bool mi_profiler_start | ( | mi_profiler_t * | profiler | ) |
experimental: Start sampling with an attached profiler.
| bool mi_profiler_stop | ( | mi_profiler_t * | profiler | ) |
experimental: Stop sampling.
The on_free callback can still run until the profiler is detached.
| bool mi_subproc_profile | ( | mi_subproc_id_t | subproc_id, |
| mi_profiler_t * | profiler ) |
experimental: Attach a profiler to the current and future heaps of a particular subprocess.
Heaps excluded by mi_heap_profile_disable() remain excluded. Pass NULL as the profiler to detach. Attaching stops sampling.