Registry / observability / mprofile

mprofile

JSON →
library0.0.15pypypi✓ verified 85d ago

mprofile is a low-overhead sampling memory profiler for Python, derived from heapprof, with an interface similar to tracemalloc. It attempts to give results comparable to tracemalloc, but uses statistical sampling to lower memory and CPU overhead. The sampling algorithm is the one used by tcmalloc and Golang heap profilers. The current version is 0.0.15, and it is compatible with Python >= 3.4.

pip install mprofile
INSTALL
IMPORT
SIG · MPROFILE
M
mprofile
observabilitypythonv0.0.15
Install
1.7s avg
Import
Disk
20MB
Pass rate
4/ 10
Env Coverage4 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.0.15 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✕ build_error
✓ 1.78s
py 3.11
✕ build_error
✓ 1.7s
py 3.12
✕ build_error
✓ 1.63s
py 3.13
✕ build_error
✕ build_error
py 3.9
✕ build_error
✓ 1.85s
20MB installed
● package 20MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

mprofile
import mprofile

This quickstart demonstrates how to initialize `mprofile`, simulate some memory allocation, take a snapshot of the current memory usage, and print the top memory-consuming lines. The `sample_rate` is set to the recommended 128KB for a balance between overhead and precision.

import mprofile import os # Start profiling with a recommended sample rate (128KB) for low overhead mprofile.start(sample_rate=128 * 1024) # Simulate some memory allocation data = [] for i in range(100_000): data.append(os.urandom(100)) # Allocate 100 bytes per iteration # Take a snapshot of memory usage snapshot = mprofile.take_snapshot() # Print top 5 memory consuming lines and their statistics print("Top 5 memory consuming lines:") for stat in snapshot.statistics(key_type='lineno')[:5]: print(stat) # Stop profiling mprofile.stop()
mprofile --version
Debug
Known issues
gotchamprofile is compatible with Python >= 3.4. Using it with earlier versions of Python (< 3.4) requires building CPython from source and manually applying `pytracemalloc` patches, which is a complex setup.
fix
Use Python 3.4 or newer, or follow the complex manual build process for older Python versions.
affects: < 3.4
gotchamprofile uses statistical sampling for memory profiling, not comprehensive tracing like `tracemalloc`. This design choice prioritizes low overhead, meaning the reported memory usage is an estimate and may not be an exact, byte-for-byte measurement. Interpret results with this in mind.
fix
Understand that mprofile provides sampled estimates, which are generally sufficient for identifying memory hotspots but may not be suitable for precise memory accounting.
affects: All versions
deprecatedVersions of mprofile prior to 0.0.13 caused a `DeprecationWarning` in Python 3.8+ due to changes in the `collections.abc` module.
fix
Upgrade to mprofile version 0.0.13 or newer (`pip install --upgrade mprofile`).
affects: < 0.0.13 (on Python 3.8+)
gotchaVersions of mprofile prior to 0.0.12 were known to cause segmentation faults when used on Ubuntu 20.04.
fix
Upgrade to mprofile version 0.0.12 or newer (`pip install --upgrade mprofile`).
affects: < 0.0.12 (on Ubuntu 20.04)
Errors
Common errors & fixes
DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated
Running mprofile on Python 3.8+ with a version of mprofile older than 0.0.13.
fix
Upgrade mprofile to version 0.0.13 or newer: `pip install --upgrade mprofile`.
Segmentation fault (core dumped)
This error specifically occurred on Ubuntu 20.04 with mprofile versions older than 0.0.12.
fix
Upgrade mprofile to version 0.0.12 or newer: `pip install --upgrade mprofile`.
ModuleNotFoundError: No module named 'mprofile'
The mprofile package is not installed in the current Python environment.
fix
Install the package using pip: `pip install mprofile`.
Upgrade
Version history
0.0.15latest on PyPI · released Jan 2, 2023
Audit
Dependencies

No dependency data recorded yet.

Agent activity
14 hits · last 30 days
node
10
OpenAI (training)
2
Resources
mprofile — pip install mprofile · libregistry