Skip to content

Commit 8fc5200

Browse files
author
Fabian Pedregosa
committed
Make a decent README
1 parent 8800fe9 commit 8fc5200

File tree

4 files changed

+68
-10
lines changed

4 files changed

+68
-10
lines changed

README.rst

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,60 @@
1-
Some utilities to monitor process memory usage
1+
Memory Profiler
2+
---------------
3+
This is a python module for monitoring memory consumption of a process
4+
as well as line-by-line analysis of memory consumption for python
5+
programs.
26

37

4-
Frequently Asked Questions
5-
--------------------------
8+
Installation
9+
------------
10+
To install through easy_install or pip::
11+
12+
$ easy_install -U line_profiler # pip install -U line_profiler
13+
14+
To install from source, download the package, extract and type::
15+
16+
$ python setup.py install
17+
18+
19+
20+
Usage
21+
-----
22+
The line-by-line profiler is used much in the same way of the
23+
line_profiler: you must first decorate the function you would like to
24+
profile with @profile::
25+
26+
@profile
27+
def my_func():
28+
a = np.zeros((100, 100))
29+
b = np.zeros((1000, 1000))
30+
c = np.zeros((10000, 1000))
31+
return a, b, c
632

7-
Q: I am a screech owl with trouble making sounds.
833

9-
A: Yes.
34+
then execute the code passing the option "-m memory_profiler" to the
35+
python interpreter. If the file name was example.py, this would result
36+
in::
1037

38+
$ python -m line_profiler example.py
39+
40+
Output will follow::
41+
42+
13.8 MB a = np.zeros((100, 100))
43+
13.9 MB b = np.zeros((1000, 1000))
44+
21.5 MB c = np.zeros((10000, 1000))
45+
97.8 MB return a, b, c
46+
47+
48+
Bugs & wishlist
49+
---------------
50+
It currently prints the memory at line *before* the line has been
51+
executed. It would be nice to print consumption after the line has
52+
been executed. Maybe also print the increment in memory consumption.
53+
54+
55+
Frequently Asked Questions
56+
--------------------------
57+
None
1158

1259
Author: Fabian Pedregosa <fabian@fseoane.net>
13-
License: Simplified BSD
60+
License: Simplified BSD

examples/example.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import numpy as np
2+
3+
@profile
4+
def my_func():
5+
a = np.zeros((100, 100))
6+
b = np.zeros((1000, 1000))
7+
c = np.zeros((10000, 1000))
8+
return a, b, c
9+
10+
if __name__ == '__main__':
11+
my_func()

memory_profiler.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
if os.name == 'posix':
1212
def _get_memory(pid):
13-
# ..
13+
# ..
1414
# .. memory usage in MB ..
1515
out = subprocess.check_output(['ps', '-p %s' % pid, '-v']).split('\n')
1616
try:
@@ -23,7 +23,7 @@ def _get_memory(pid):
2323
# .. better to be safe than sorry ..
2424
raise NotImplementedError
2525

26-
def memory_usage(proc= -1, num= -1, interval=.1, locals={}):
26+
def memory_usage(proc= -1, num= -1, interval=.1):
2727
"""
2828
Return the memory usage of a process or piece of code
2929
@@ -32,7 +32,7 @@ def memory_usage(proc= -1, num= -1, interval=.1, locals={}):
3232
proc : {int, string, tuple}
3333
The process to monitor. Can be given by a PID or by a string
3434
containing a filename. A tuple containing (f, args, kwargs) specifies
35-
to run the function f(*args, **kwargs). Set to -1 (default)for
35+
to run the function f(*args, **kwargs). Set to -1 (default)for
3636
current process.
3737
3838
interval : int, optional

test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
$ python minimon.py test.py
33
"""
44

5-
@monitor
5+
@profile
66
def sample():
77
a = 2
88
a + 3

0 commit comments

Comments
 (0)