Python memory tracing.
Project description
pymemtrace provides tools for tracking and understanding Python memory usage at different levels, at different granularities and with different runtime costs.
Full documentation: https://pymemtrace.readthedocs.io
pymemtrace Tools
The tools provided by pymemtrace:
process is a very lightweight way of logging the total memory usage at regular time intervals. It can plot memory over time with plotting programs such as gnuplot. See some process examples
cPyMemTrace is a memory tracer written in C that can report total memory usage for every function call/return for both C and Python sections. See some cPyMemTrace examples and a technical note on cPyMemTrace.
DTrace: Here are a number of D scripts that can trace the low level malloc() and free() system calls and report how much memory was allocated and by whom. See some DTrace examples and a technical note on DTrace.
trace_malloc is a convenience wrapper around the Python standard library tracemalloc module. This can report Python memory usage by module and line compensating for the cost of tracemalloc. This can take memory snapshots before and after code blocks and show the change on memory caused by that code. See some trace_malloc examples
debug_malloc_stats is a wrapper around the sys._debugmallocstats function that can take snapshots of memory before and after code execution and report the significant differences of the Python small object allocator. See some debug_malloc_stats examples
Tool Characteristics
Each tool can be characterised by:
Memory Granularity: In how much detail is a memory change is observed. An example of coarse memory granularity is measuring the Resident Set Size which is normally in chunks of 4096 bytes. An example of fine memory granularity is recording every malloc() and free().
Execution Granularity: In how much code detail is the memory change observed. An example of coarse execution granularity is measuring the memory usage every second. An example of fine execution granularity is recording the memory usage every Python line.
Memory Cost: How much extra memory the tool needs.
Execution Cost: How much the execution time is increased.
Clearly there are trade-offs between these depending on the problem you are trying to solve.
Tool |
Memory Granularity |
Execution Granularity |
Memory Cost |
Execution Cost |
---|---|---|---|---|
process |
RSS (total Python and C memory). |
Regular time intervals. |
Near zero. |
Near zero. |
cPyMemTrace |
RSS (total Python and C memory). |
Per Python line, Python function and C function call. |
Near zero. |
x10 to x20. |
DTrace |
Every malloc() and free(). |
Per function call and return. |
Minimal. |
x90 to x100. |
trace_malloc |
Every Python object. |
Per Python line, per function call. |
Significant but compensated. |
x900 for small objects, x6 for large objects. |
debug_malloc_stats |
Python memory pool. |
Snapshots the CPython memory pool either side of a block of code. |
Minimal. |
x2000+ for small objects, x12 for large objects. |
Package Metadata
Licence
Python memory tracing.
Free software: MIT license
Documentation: https://pymemtrace.readthedocs.io.
Project: https://github.com/paulross/pymemtrace.
Credits
Phil Smith (AHL) with whom a casual lunch time chat lead to the creation of an earlier, but quite different implementation, of cPyMemTrace in pure Python.
This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.
History
0.1.5 (2023-06-21)
Add support for Python versions 3.10, 3.11. Now supports Python versions 3.7, 3.8, 3.9, 3.10, 3.11.
0.1.4 (2022-03-19)
Fix Linux build.
0.1.3 (2022-03-17)
Fix some tests.
0.1.2 (2022-03-17)
Fix source distribution that had missing headers.
0.1.1 (2020-11-17)
Add cPyMemTrace the C level profiler.
Add DTrace scripts for low level tracing.
Add debug_malloc_stats the wrapper around sys._debugmallocstats.
Add process from the TotalDepth project.
Add redirect_stdout for debug_malloc_stats.
Add trace_malloc, a wrapper around the tracemalloc module.
Includes extensive documentation and performance measurement.
First release on PyPI.
0.1.0 (2017-12-04)
Initial idea and implementation, never released.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file pymemtrace-0.1.5.tar.gz
.
File metadata
- Download URL: pymemtrace-0.1.5.tar.gz
- Upload date:
- Size: 376.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.31.0 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9ea84032cb3821225acc494d3cad133e176a24a4b7f00fc4e07b7bf8185e7611 |
|
MD5 | 039bffdc6edc63b1b385bd404f43a265 |
|
BLAKE2b-256 | a48e0c3645874cc529f2dd51e033dd7741d13ea206539c18653ee320255bbad9 |
File details
Details for the file pymemtrace-0.1.5-cp311-cp311-macosx_10_9_universal2.whl
.
File metadata
- Download URL: pymemtrace-0.1.5-cp311-cp311-macosx_10_9_universal2.whl
- Upload date:
- Size: 60.6 kB
- Tags: CPython 3.11, macOS 10.9+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.31.0 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3750640326efaed60556a0aabb1cb434c0714341c71feccbcce5fa1699428556 |
|
MD5 | 037ac448f5c2ff9ccb0d2ae2009b6a3e |
|
BLAKE2b-256 | 9524a268a133ffd6f740617bf082cb453277484fa32b726db85d0ead39195c5e |
File details
Details for the file pymemtrace-0.1.5-cp310-cp310-macosx_10_9_universal2.whl
.
File metadata
- Download URL: pymemtrace-0.1.5-cp310-cp310-macosx_10_9_universal2.whl
- Upload date:
- Size: 60.6 kB
- Tags: CPython 3.10, macOS 10.9+ universal2 (ARM64, x86-64)
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.31.0 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ff239bf8d944751f579e9955dda56730733beae9212acf21077fc82e1a3d90a |
|
MD5 | d66b7b53d46a05b4205c4779dac67206 |
|
BLAKE2b-256 | 59f3153b235ece0874007bd6be68ff8b81178a70fb0d06428837285b3df4a7c8 |
File details
Details for the file pymemtrace-0.1.5-cp39-cp39-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: pymemtrace-0.1.5-cp39-cp39-macosx_10_9_x86_64.whl
- Upload date:
- Size: 60.6 kB
- Tags: CPython 3.9, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.31.0 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d04b3ce2153d591d5be63d2c674b98c06919467bda81e0150438f683c3c1bd2e |
|
MD5 | bbc22c3a2c98063ff1c1d3047e8e3654 |
|
BLAKE2b-256 | 370c50edaeac21bb9553f857c132aebceb0e30b9dccdd285d28e90a9a154a9ed |
File details
Details for the file pymemtrace-0.1.5-cp38-cp38-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: pymemtrace-0.1.5-cp38-cp38-macosx_10_9_x86_64.whl
- Upload date:
- Size: 60.6 kB
- Tags: CPython 3.8, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.31.0 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fae21cc8bece6cbce24b127c557fbff09b04d5b4e495ba81462cf651a91388a6 |
|
MD5 | 5d35e1ec06c90f03404681886c3a3d14 |
|
BLAKE2b-256 | 2208c5570c08a2a80afb6c1e9bb5e2e6b91c7cbfaa47e6d22f728ad744f68683 |
File details
Details for the file pymemtrace-0.1.5-cp37-cp37m-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: pymemtrace-0.1.5-cp37-cp37m-macosx_10_9_x86_64.whl
- Upload date:
- Size: 60.3 kB
- Tags: CPython 3.7m, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.31.0 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 176bee8fd7cf61aa14a5e0a9f8d1e6b21fad6cdb06b1b8644554c92b9eb2c177 |
|
MD5 | 57c4298957393d90326b8c38b9aafdf6 |
|
BLAKE2b-256 | 12cb972e8356c294c4ab64e57c9458659b08af55d43519d7722c6534ce16b6e5 |