Module memory_profiler

Module memory_profiler 

Source
Expand description

Heap memory usage profiling.

Build with debug symbols and "memory_profiler" feature to record heap allocations.

Instrumentation and recording is done with the dhat crate. Recorded profiles can be visualized using the online DHAT Viewer. Stack traces are captured for each significant allocation.

§Config

The "ZNG_MEMORY_PROFILER_DIR" variable can be set to define a custom output directory path, relative to the current dir. The default dir is "./zng-dhat/".

§Output

The recorded data is saved to "{ZNG_MEMORY_PROFILER_DIR}/{timestamp}/{pname}-{pid}.json".

The timestamp is in microseconds from Unix epoch and is defined by the first process that runs. All processes are recorded to the same timestamp folder, even worker processes started later.

The primary process is named "app-process". See zng::env::process_name for more details about the default processes.

§Limitations

Only heap allocations using the #[global_allocator] are captured, some dependencies can skip the allocator, for example, the view-process only traces a fraction of allocations because most of its heap usage comes from the graphics driver.

Compiling with "memory_profiler" feature replaces the global allocator, so if you use a custom allocator you need to setup a feature that disables it, otherwise it will not compile. The instrumented allocator also has an impact in performance so it is only recommended for test builds.

As an alternative on Unix you can use the external Valgrind DHAT tool. On Windows you can Record a Heap Snapshot.

§Full API

See zng_app::memory_profiler for the full API.

Functions§

stop_recording
Stop recording earlier.