pax_global_header00006660000000000000000000000064124207065620014516gustar00rootroot0000000000000052 comment=43393405ca0e8e5cf549a9358382287d0c93df6d python-memory-profiler-0.31+git20141019/000077500000000000000000000000001242070656200175115ustar00rootroot00000000000000python-memory-profiler-0.31+git20141019/.gitignore000066400000000000000000000000431242070656200214760ustar00rootroot00000000000000.idea dist build *.pyc MANIFEST *~ python-memory-profiler-0.31+git20141019/COPYING000066400000000000000000000030161242070656200205440ustar00rootroot00000000000000New BSD License Copyright (c) 2007–2014 Fabian Pedregosa. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: a. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. b. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. c. Neither the name of the memory_profiler developers nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. python-memory-profiler-0.31+git20141019/MANIFEST.in000066400000000000000000000000231242070656200212420ustar00rootroot00000000000000include README.rst python-memory-profiler-0.31+git20141019/Makefile000066400000000000000000000006251242070656200211540ustar00rootroot00000000000000PYTHON ?= python .PHONY: test test: $(PYTHON) -m memory_profiler test/test_func.py $(PYTHON) -m memory_profiler test/test_loop.py $(PYTHON) -m memory_profiler test/test_as.py $(PYTHON) -m memory_profiler test/test_global.py $(PYTHON) -m memory_profiler test/test_precision_command_line.py $(PYTHON) test/test_import.py $(PYTHON) test/test_memory_usage.py $(PYTHON) test/test_precision_import.py python-memory-profiler-0.31+git20141019/README.rst000066400000000000000000000273011242070656200212030ustar00rootroot00000000000000================= 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. It is a pure python module and has the `psutil `_ module as optional (but highly recommended) dependencies. ============== 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 `_: first decorate the function you would like to profile with ``@profile`` and then run the script with a special script (in this case with specific arguments to the Python interpreter). In the following example, we create a simple function ``my_func`` that allocates lists ``a``, ``b`` and then deletes ``b``:: @profile def my_func(): a = [1] * (10 ** 6) b = [2] * (2 * 10 ** 7) del b return a if __name__ == '__main__': my_func() Execute the code passing the option ``-m memory_profiler`` to the python interpreter to load the memory_profiler module and print to stdout the line-by-line analysis. If the file name was example.py, this would result in:: $ python -m memory_profiler example.py Output will follow:: Line # Mem usage Increment Line Contents ============================================== 3 @profile 4 5.97 MB 0.00 MB def my_func(): 5 13.61 MB 7.64 MB a = [1] * (10 ** 6) 6 166.20 MB 152.59 MB b = [2] * (2 * 10 ** 7) 7 13.61 MB -152.59 MB del b 8 13.61 MB 0.00 MB return a The first column represents the line number of the code that has been profiled, the second column (*Mem usage*) the memory usage of the Python interpreter after that line has been executed. The third column (*Increment*) represents the difference in memory of the current line with respect to the last one. The last column (*Line Contents*) prints the code that has been profiled. Decorator ========= A function decorator is also available. Use as follows:: from memory_profiler import profile @profile def my_func(): a = [1] * (10 ** 6) b = [2] * (2 * 10 ** 7) del b return a In this case the script can be run without specifying ``-m memory_profiler`` in the command line. In function decorator, you can specify the precision as an argument to the decorator function. Use as follows:: from memory_profiler import profile @profile(precision=4) def my_func(): a = [1] * (10 ** 6) b = [2] * (2 * 10 ** 7) del b return a If a python script with decorator ``@profile`` is called using ``-m memory_profiler`` in the command line, the ``precision`` parameter is ignored. Executing external scripts ========================== Sometimes it is useful to have full memory usage reports as a function of time (not line-by-line) of external processes (be it Python scripts or not). In this case the executable ``mprof`` might be useful. Use it like:: mprof run mprof plot The first line run the executable and record memory usage along time, in a file written in the current directory. Once it's done, a graph plot can be obtained using the second line. The recorded file contains a timestamps, that allows for several profiles to be kept at the same time. Help on each `mprof` subcommand can be obtained with the `-h` flag, e.g. `mprof run -h`. In the case of a Python script, using the previous command does not give you any information on which function is executed at a given time. Depending on the case, it can be difficult to identify the part of the code that is causing the highest memory usage. Adding the `profile` decorator to a function and running the Python script with mprof run --python