Introduction
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
The tools provided by pymemtrace
:
process
is a very lightweight way of logging the total memory usage at regular time intervals.gnuplot
.some process examples <https://pymemtrace.readthedocs.io/en/latest/examples/process.html>
_cPyMemTrace
is a memory tracer written in C that can report total memory usage for every function call/return forcPyMemTrace examples <https://pymemtrace.readthedocs.io/en/latest/examples/c_py_mem_trace.html>
_technical note on cPyMemTrace <https://pymemtrace.readthedocs.io/en/latest/tech_notes/cPyMemTrace.html>
_.malloc()
and free()
system calls andDTrace examples <https://pymemtrace.readthedocs.io/en/latest/examples/dtrace.html>
_technical note on DTrace <https://pymemtrace.readthedocs.io/en/latest/tech_notes/dtrace.html>
_.trace_malloc
is a convenience wrapper around the Python standard library tracemalloc
module.tracemalloc
.trace_malloc examples <https://pymemtrace.readthedocs.io/en/latest/examples/trace_malloc.html>
_debug_malloc_stats
is a wrapper around the sys._debugmallocstats
function that can take snapshots ofdebug_malloc_stats examples <https://pymemtrace.readthedocs.io/en/latest/examples/debug_malloc_stats.html>
_Each tool can be characterised by:
Resident Set Size <https://en.wikipedia.org/wiki/Resident_set_size>
_ which is normally in chunks of 4096 bytes.malloc()
and free()
.Clearly there are trade-offs between these depending on the problem you are trying to solve.
.. list-table:: Tool Characteristics :widths: 15 30 30 30 30 :header-rows: 1
process
cPyMemTrace
malloc()
and free()
.trace_malloc
debug_malloc_stats
.. image:: https://img.shields.io/pypi/v/pymemtrace.svg :target: https://pypi.python.org/pypi/pymemtrace
.. image:: https://img.shields.io/travis/paulross/pymemtrace.svg :target: https://travis-ci.org/paulross/pymemtrace
.. image:: https://readthedocs.org/projects/pymemtrace/badge/?version=latest :target: https://pymemtrace.readthedocs.io/en/latest/?badge=latest :alt: Documentation Status
.. image:: https://pyup.io/repos/github/paulross/pymemtrace/shield.svg :target: https://pyup.io/repos/github/paulross/pymemtrace/ :alt: Updates
Python memory tracing.
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.
.. _Cookiecutter: https://github.com/audreyr/cookiecutter
.. _audreyr/cookiecutter-pypackage
: https://github.com/audreyr/cookiecutter-pypackage