mempulse
Tiny yet effective Python memory profiler/tracer. With minimized overhead with the C extension, mempulse gives you a holistic view of what's eating memory in your Python applications, on development and on production environments.
This package supports both Python 2.7 and Python >= 3.3 (tested with Python 3.13).
Install
Install from PyPI:
# Python-based `mempulse.MemoryUsageTracer` (depends on `psutil`, for Linux, macOS, Windows)
pip install mempulse[psutil]
# C-based `mempulse.cMemoryUsageTracer` (Linux only)
pip install mempulse
Install from source:
pip install setuptools
pip install .[psutil]
How to Use
Choose appropriate "tracing depth" (which slightly affects the overhead) then wrap the function you'd like to profile with a with statement:
import os
import sys
import mempulse
def application():
callback = lambda r: sys.stderr.write(mempulse.format_trace_result(r))
trace_depth = int(os.getenv('MEMORY_TRACE_DEPTH', '1')) # `0` disables tracing
with mempulse.cMemoryUsageTracer(callback, trace_depth):
the_workload()
Leavning the with scope will summarize line-by-line memory stats like belw:
Callsite Method Name USS Swap Peak RSS
--------------------------------------------------------------------
benchmark.py:53 run_mempulse_c 26,525,696 0 28,057,600
benchmark.py:29 workload 26,525,696 0 28,057,600
benchmark.py:30 workload 26,525,696 0 28,057,600
benchmark.py:31 workload 27,328,512 0 28,860,416
benchmark.py:32 workload 115,335,168 0 117,530,624
benchmark.py:33 workload 147,431,424 0 148,926,464
benchmark.py:34 workload 117,096,448 0 148,926,464
benchmark.py:35 workload 34,779,136 0 148,926,464
benchmark.py:36 workload 34,779,136 0 836,354,048
benchmark.py:37 workload 34,779,136 0 836,354,048
benchmark.py:38 workload 44,900,352 0 836,354,048
benchmark.py:39 workload 44,900,352 0 836,354,048
benchmark.py:52 run_mempulse_c 44,900,352 0 836,354,048
Benchmark
Running benchmark program examples/benchmark.py with Python 3.11 on macOS (with 8-core Intel Core i9 @ 3.6GHz) here showcases that mempulse outperforms similar tools such as memory_profiler, and tracemalloc, in terms of overhead:
| Tracer | Execution Time in Average | Overhead |
|---|---|---|
| - (without tracer) | 2.26s | - |
mempulse.cMemoryUsageTracer |
3.40s | 50.44% |
mempulse.MemoryUsageTracer |
3.62s | 60.18% |
memory_profiler |
8.31s | 268.58% |
tracemalloc |
11.02s | 387.61% |
Limitations
- Interoperability:
mempulsesets trace function thoughsys.settrace()(orPyEval_SetStrace()), therefore it cannot be used with other tracers (such as Coverage.py) at the same time. - Concurrency:
mempulsetraces current thread only. Functions run with other threads will not show in line-by-line trace records.
License
- This
mempulsesoftware is released under 3-Clause BSD License. - The file
mempulse/ext/uthash.hcomes from uthash which is under BSD revised license.
Metadata
Release files for mempulse 0.6.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mempulse-0.6.4.tar.gz | 22.6 kB | Without provenance | Details for mempulse-0.6.4.tar.gz |
Release files / mempulse-0.6.4.tar.gz
| Download URL | mempulse-0.6.4.tar.gz |
|---|---|
| Size | 22.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f91c73481483c603121aa0cd09c6364a227bf56d422194033e1a481c36a7ab5d
|
|
BLAKE2b-256 checksum How to use checksums |
c1abe090ed71aca6c7aa524a589423ad1a014ca9cedcb9644afd66c5c9879362
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.0 CPython/3.10.0
|
Security for mempulse 0.6.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.