Skip to main content

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 Characteristics

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

https://img.shields.io/pypi/v/pymemtrace.svg https://img.shields.io/travis/paulross/pymemtrace.svg Documentation Status Updates

Licence

Python memory tracing.

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.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

pymemtrace-0.1.3.tar.gz (375.5 kB view details)

Uploaded Source

Built Distributions

pymemtrace-0.1.3-cp39-cp39-macosx_10_9_x86_64.whl (60.3 kB view details)

Uploaded CPython 3.9 macOS 10.9+ x86-64

pymemtrace-0.1.3-cp38-cp38-macosx_10_9_x86_64.whl (60.3 kB view details)

Uploaded CPython 3.8 macOS 10.9+ x86-64

pymemtrace-0.1.3-cp37-cp37m-macosx_10_9_x86_64.whl (60.1 kB view details)

Uploaded CPython 3.7m macOS 10.9+ x86-64

File details

Details for the file pymemtrace-0.1.3.tar.gz.

File metadata

  • Download URL: pymemtrace-0.1.3.tar.gz
  • Upload date:
  • Size: 375.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 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.9.7

File hashes

Hashes for pymemtrace-0.1.3.tar.gz
Algorithm Hash digest
SHA256 a4fe7cd9d08a7b6f750c0a5c689d97bc6480e7103f4ad301aed1fa9f85fdec41
MD5 2a43e7798d1c61553852f6fec1623c19
BLAKE2b-256 9bf80f22839fabf6af0257176050291c321b5cd500d9e1e9b3817a19cb524998

See more details on using hashes here.

File details

Details for the file pymemtrace-0.1.3-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: pymemtrace-0.1.3-cp39-cp39-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 60.3 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.27.1 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.9.7

File hashes

Hashes for pymemtrace-0.1.3-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 d3dc51bf81b660ecbf2c1f142552d3ce532730bb67b95be7651f21ccc541d715
MD5 ca6a425a8ef0766fc87858375e308396
BLAKE2b-256 17ae608aa3fbce4d0a7ab2d65c57041d1322de241bb5f1f0af915535657c15d3

See more details on using hashes here.

File details

Details for the file pymemtrace-0.1.3-cp38-cp38-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: pymemtrace-0.1.3-cp38-cp38-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 60.3 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.27.1 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.9.7

File hashes

Hashes for pymemtrace-0.1.3-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 598258a91c930fb5b3a26965a2cb44af38da4caa4e8aefc42fc91a3ef338c229
MD5 7c8dc6ebb97c758964fca324105ce1a5
BLAKE2b-256 7939b17979e062a210f6f7be33d685990e52405601a17ac40c34d872d992803f

See more details on using hashes here.

File details

Details for the file pymemtrace-0.1.3-cp37-cp37m-macosx_10_9_x86_64.whl.

File metadata

  • Download URL: pymemtrace-0.1.3-cp37-cp37m-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 60.1 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.27.1 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.9.7

File hashes

Hashes for pymemtrace-0.1.3-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 0bb8f917fbaca1267474c5dd191c2059548106fb4fdc853cfd323a856c633c3a
MD5 91027485d3cfc81160ffc172cd4b24e0
BLAKE2b-256 f686da83f8bcbdb33c4f42224aa9a0fe651f28abb9e51e025a99076e8431d977

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page