Skip to content

Commit d56c6c6

Browse files
author
Fabian Pedregosa
committed
Print the memory of current line (move line events one line up)
1 parent 4214cfc commit d56c6c6

File tree

2 files changed

+5
-16
lines changed

2 files changed

+5
-16
lines changed

memory_profiler.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -110,17 +110,6 @@ def _find_script(script_name):
110110
print >> sys.stderr, 'Could not find script %s' % script_name
111111
raise SystemExit(1)
112112

113-
def label(code):
114-
# TODO: remove
115-
""" Return a (filename, first_lineno, func_name) tuple for a given code
116-
object.
117-
118-
This is the same labelling as used by the cProfile module in Python 2.5.
119-
"""
120-
if isinstance(code, str):
121-
return ('~', 0, code) # built-in functions ('~' sorts at the end)
122-
else:
123-
return (code.co_filename, code.co_firstlineno, code.co_name)
124113

125114
class LineProfiler:
126115
""" A profiler that records the amount of memory for each line """
@@ -185,8 +174,8 @@ def trace_memory_usage(self, frame, event, arg):
185174
if event in ('line', 'return'):
186175
if frame.f_code in self.code_map:
187176
lineno = frame.f_lineno
188-
if event == 'return':
189-
lineno += 1
177+
if event == 'line':
178+
lineno -= 1
190179
entry = self.code_map[frame.f_code].setdefault(lineno, [])
191180
entry.append(_get_memory(os.getpid()))
192181

@@ -222,8 +211,8 @@ def show_results(prof, stream=None):
222211
filename.endswith(".pyo")):
223212
filename = filename[:-1]
224213
all_lines = linecache.getlines(filename)
225-
sublines = inspect.getblock(all_lines[code.co_firstlineno-1:])
226-
linenos = range(code.co_firstlineno, code.co_firstlineno + len(sublines))
214+
sub_lines = inspect.getblock(all_lines[code.co_firstlineno-1:])
215+
linenos = range(code.co_firstlineno, code.co_firstlineno + len(sub_lines))
227216
for l in linenos:
228217
mem = ''
229218
if lines.has_key(l):

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
setup(
1818
name='memory_profiler',
19-
description='A module for getting memory usage of a python program',
19+
description='A module for monitoring memory usage of a python program',
2020
long_description=open('README.rst').read(),
2121
version=memory_profiler.__version__,
2222
author='Fabian Pedregosa',

0 commit comments

Comments
 (0)