Skip to main content

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

or

sudo easy_install --upgrade memprof

or (Debian testing/unstable)

sudo apt-get install python-memprof

Development

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

or

sudo pip install git+https://github.com/jmdana/memprof

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 memprof

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

Example plot

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

etc.

Contact

Mailing list


Copyright 2013-2019, Jose M. Dana

Release files for memprof 0.3.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for memprof 0.3.6
File Size Uploaded
memprof-0.3.6.tar.gz 19.4 kB Details

Release files / memprof-0.3.6.tar.gz

Download URL memprof-0.3.6.tar.gz
Size 19.4 kB
Tags Source
SHA-256 checksum
How to use checksums
a8376ce476bf82a5eb465d1a30b8ffc86cc55b0b6de7aa4cdeccb4c99586d967
BLAKE2b-256 checksum
How to use checksums
a3d043cb11c8394b1a741e5f2f5601add8cd2694f7d87ca6762ab64f0a2fcdd4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Python-urllib/2.7

Release history Release notifications | RSS feed

This release

0.3.6 This release

1 release file

0.3.5

1 release file

0.3.4

1 release file

0.3.3

1 release file

0.3.2

1 release file

0.3.1

1 release file

0.3

1 release file

0.2.4

1 release file

0.2.3

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page