Skip to main content

A module for monitoring memory usage of a python program

Project description

Memory Profiler

This is a python module for monitoring memory consumption of a process as well as line-by-line analysis of memory consumption for python programs.

Installation

To install through easy_install or pip:

$ easy_install -U memory_profiler # pip install -U memory_profiler

To install from source, download the package, extract and type:

$ python setup.py install

Usage

The line-by-line profiler is used much in the same way of the line_profiler: you must first decorate the function you would like to profile with @profile:

@profile
def my_func():
    a = np.zeros((100, 100))
    b = np.zeros((1000, 1000))
    c = np.zeros((10000, 1000))
    return a, b, c

then execute the code passing the option “-m memory_profiler” to the python interpreter to load the memory_profiler module and “-l -v” to do a line-by-line analysis and print the result. If the file name was example.py, this would result in:

$ python -m memory_profiler -l -v example.py

Output will follow:

Line #    Mem usage   Line Contents
===================================
     3                @profile
     4     14.19 MB   def my_func():
     5     14.27 MB       a = np.zeros((100, 100))
     6     21.91 MB       b = np.zeros((1000, 1000))
     7     98.20 MB       c = np.zeros((10000, 1000))
     8     98.20 MB       return a, b, c

Bugs & wishlist

Maybe also print the increment in memory consumption.

Development

Latest sources are available from github:

https://github.com/fabianp/memory_profiler

Author: Fabian Pedregosa <fabian@fseoane.net> License: Simplified BSD

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

memory_profiler-0.8.tar.gz (4.5 kB view details)

Uploaded Source

File details

Details for the file memory_profiler-0.8.tar.gz.

File metadata

  • Download URL: memory_profiler-0.8.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for memory_profiler-0.8.tar.gz
Algorithm Hash digest
SHA256 e7e52a91227e0eb01ff8c362951100f1061c8177c91159c029f81636299143c4
MD5 a591efe2da645e9087faf89df4a41170
BLAKE2b-256 06071831ae6beafc57d7d53b186f1066db8bdfd07a455507fef901d72533e6bc

See more details on using hashes here.

Supported by

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