Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

Download
ActivePython

memprof is unavailable in PyPM, because there aren't any builds for it in the package repositories. Click the linked icons to find out why.

 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
Windows (64-bit)
Mac OS X (10.5+)
Linux (32-bit)
Linux (64-bit)
 
Links
Author
License
GNU General Public License v3 (GPLv3)
Dependencies

# memprof

memprof is a memory profiler for Python.

It logs and plots the memory usage of all the variables during the execution of the decorated methods.

## Installation ### Stable

System Message: ERROR/3 (<string>, line 9)

Unexpected indentation.
sudo pip install --upgrade memprof

or

sudo easy_install --upgrade memprof

### Development

git clone git://github.com/jmdana/memprof.git cd memprof sudo python setup.py install

## Usage

Using memprof is as easy as adding a decorator to the methods that you want to profile:

@memprof def foo():

And importing the module just by including the line below at the beginning of your Python file:

from memprof import *

Now you can run as usual and logfiles with the names of your methods will be created (e.g. foo.log).

### Generating plots

The logfiles are not very interesting so you might prefer to use the -p/--plot flag:

python -m memprof --plot <python_file> python -m memprof -p <python_file>

Which, in addition to the logfile, will generate a plot (foo.png):

![Image](examples/foo.png)

The grey bar indicates that the foo method wasn't running at that point.

The flag may also be passed as an argument to the decorator:

@memprof(plot = True)

Please keep in mind that the former takes precedence over the latter.

### Adjusting the threshold

You may also want to specify a threshold. The value will be the minimum size for a variable to appear in the plot (but it will always appear in the logfile!). The default value is 1048576 (1 MB) but you can specify a different threshold (in bytes) with the -t/--threshold flag:

python -m memprof --threshold 1024 <python_file> python -m memprof -t 1024 <python_file>

The threshold may also be passed as an argument to the decorator:

@memprof(threshold = 1024)

Please keep in mind that the former takes precedence over the latter.

### mp_plot

If, after running memprof, you want to change the threshold and generate a new plot (or you forgot to use the -p/--plot flag with memprof), you don't have to re-run! Just call the command:

mp_plot [-h] [-t THRESHOLD] logfiles [logfiles ...]

and generate the plots again doing something like:

mp_plot -t 128 logfile1.log logfile2.log

or:

mp_plot -t 1024 *.log

System Message: WARNING/2 (<string>, line 78); backlink

Inline emphasis start-string without end-string.

etc.

## Contact

### Mailing list

--- Copyright 2013, Jose M. Dana

Subscribe to package updates

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.