
In this case the script can be run without specifying -m memory_profiler in the command line. Use as follows: from memory_profiler import my_func(): DecoratorĪ function decorator is also available. The last column ( Line Contents) prints the code that has been profiled. The third column ( Increment) represents the difference in memory of the current line with respect to the last one.

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. If the file name was example.py, this would result in: $ python -m memory_profiler example.py In the following example, we create a simple function my_func that allocates lists a, b and then deletes b: my_func():Įxecute 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. The line-by-line memory usage mode is used much in the same way of the line_profiler: first decorate the function you would like to profile with and then run the script with a special script (in this case with specific arguments to the Python interpreter).

To install from source, download the package, extract and type: $ python setup.py install

The package is also available on conda-forge. Install via pip: $ pip install -U memory_profiler It is a pure python module which depends on the psutil module. 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.
