Skip to main content

A memory profiler for Python. As easy as adding a decorator.

Project description

# 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
sudo pip install --upgrade memprof


sudo easy_install --upgrade memprof

or (Debian testing/unstable)

sudo apt-get install python-memprof

### Development

git clone git://
cd memprof
sudo python install

## Usage

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

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`):


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


mp_plot -t 1024 *.log


## Contact

### Mailing list

* Subscribe by sending a message to <>
* Once subscribed, you can send emails to <>
* List archives at

Copyright 2013-2015, Jose M. Dana

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
memprof-0.3.4.tar.gz (19.4 kB) Copy SHA256 hash SHA256 Source None Aug 19, 2015

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page